-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add changelog requirement action for major/minor bumps
- Loading branch information
1 parent
440e6b1
commit bf37123
Showing
4 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Check API Changes | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
check-format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout branch | ||
uses: actions/[email protected] | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: temurin | ||
cache: gradle | ||
- name: Run API versioning check | ||
run: | | ||
if test -d .changes && git diff --quiet HEAD^..HEAD .changes ; then ./gradlew warnVersionBump ; else exit 0 ; fi | ||
- name : Log errors | ||
if: failure() | ||
run: | | ||
echo "PR contains a Major or Minor API bump without an associated changelog entry. Either generate a changelog entry for the change or revert the API changes." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
plugins/src/main/java/com/google/gradle/tasks/WarnVersionBumpTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.gradle.tasks | ||
|
||
import com.google.gradle.types.LinesChanged | ||
import com.google.gradle.types.VersionType | ||
import com.google.gradle.types.VersionType.* | ||
import com.google.gradle.util.SkipTask | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.StopExecutionException | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.tasks.TaskExecutionException | ||
|
||
/** | ||
* A Gradle task to warn about API version bumps beyond what is expected | ||
* | ||
* The task uses the provided [changesFile] to infer if merging the changes currently present in the | ||
* repo will have an impact on the public api. | ||
* | ||
* @property changesFile a file containing a [LinesChanged]; representing the changes made in this | ||
* repo | ||
* @throws TaskExecutionException if changes cause an minor or major API bump | ||
*/ | ||
abstract class WarnVersionBumpTask : DefaultTask() { | ||
@get:InputFile abstract val changesFile: RegularFileProperty | ||
|
||
@TaskAction | ||
fun add() { | ||
val diff = LinesChanged.fromFile(changesFile.asFile.get()) | ||
|
||
if (diff.bump == MAJOR || diff.bump == MINOR) { | ||
throw TaskExecutionException(this, Exception("Changes are ${diff.bump}, higher than PATCH")) | ||
} | ||
} | ||
} |