Skip to content

Commit

Permalink
Be more explicit about API diffing source
Browse files Browse the repository at this point in the history
  • Loading branch information
emilypgoogle committed Jun 7, 2024
1 parent 35b2a9d commit 627ed6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ abstract class ChangelogPlugin : Plugin<Project> {
}

tasks.register<WarnVersionBumpTask>("warnVersionBump") {
if (export.isPresent) {
export.set(apiPlugin.exportFile)
}
changesFile.set(fileChanges)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
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.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskExecutionException

Expand All @@ -38,14 +36,20 @@ import org.gradle.api.tasks.TaskExecutionException
* @throws TaskExecutionException if changes cause an minor or major API bump
*/
abstract class WarnVersionBumpTask : DefaultTask() {
@get:[Optional InputFile] abstract val export: RegularFileProperty

@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. If this is intended, add a changelog entry. Otherwise, revert the changes."))
if (export.isPresent) {
throw TaskExecutionException(this, Exception("Based on exported API, changes are ${diff.bump}, higher than PATCH. If this is intended, add a changelog entry. Otherwise, revert the changes."))
} else {
throw TaskExecutionException(this, Exception("Based on last release API, changes are ${diff.bump}, higher than PATCH. If this is intended, add a changelog entry. Otherwise, revert the changes. To compare local changes, run exportApi on a commit first."))
}
}
}
}

0 comments on commit 627ed6e

Please sign in to comment.