diff --git a/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy b/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy index 24ce14aa..79336f2b 100644 --- a/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy +++ b/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy @@ -203,4 +203,53 @@ class SimpleIntegrationTest extends BaseIntegrationTest { cleanup: environmentVariablesRule.clear("GITHUB_ACTIONS", "GITHUB_OUTPUT") } + + def "should not update project.version after release when updateProjectVersionAfterRelease option is not set"() { + given: + buildFile(""" + task assemble { + inputs.property("version", project.version) + doLast { + println("Assembling project: " + version) + } + } + """) + + def result = runGradle('currentVersion', 'release', 'assemble', '-Prelease.localOnly', '-Prelease.disableChecks') + + expect: + result.output.contains('Project version: 0.1.0-SNAPSHOT') + result.output.contains('Creating tag: v0.1.0') + result.output.contains('Assembling project: 0.1.0-SNAPSHOT') + result.task(":currentVersion").outcome == TaskOutcome.SUCCESS + result.task(":release").outcome == TaskOutcome.SUCCESS + result.task(":assemble").outcome == TaskOutcome.SUCCESS + } + + def "should update project.version after release when updateProjectVersionAfterRelease option is set"() { + given: + buildFile(""" + scmVersion { + updateProjectVersionAfterRelease = true + } + + task assemble { + inputs.property("version", project.version) + doLast { + println("Assembling project: " + version) + } + } + """) + + def result = runGradle('currentVersion', 'release', 'assemble', '-Prelease.localOnly', '-Prelease.disableChecks') + + expect: + result.output.contains('Project version: 0.1.0-SNAPSHOT') + result.output.contains('Creating tag: v0.1.0') + result.output.contains('Project version will be updated after release.') + result.output.contains('Assembling project: 0.1.0') + result.task(":currentVersion").outcome == TaskOutcome.SUCCESS + result.task(":release").outcome == TaskOutcome.SUCCESS + result.task(":assemble").outcome == TaskOutcome.SUCCESS + } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy index 91f28c1d..93a48690 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy @@ -41,12 +41,20 @@ abstract class ReleasePlugin implements Plugin { group = 'Release' description = 'Performs release - creates tag and pushes it to remote.' dependsOn(VERIFY_RELEASE_TASK) + if (versionConfig.updateProjectVersionAfterRelease.get() && project.tasks.matching { it.name == "assemble" }.size() > 0) { + project.logger.quiet("Project version will be updated after release.") + finalizedBy(project.tasks.named("assemble")) + } } project.tasks.register(CREATE_RELEASE_TASK, CreateReleaseTask) { group = 'Release' description = 'Performs first stage of release - creates tag.' dependsOn(VERIFY_RELEASE_TASK) + if (versionConfig.updateProjectVersionAfterRelease.get() && project.tasks.matching { it.name == "assemble" }.size() > 0) { + project.logger.quiet("Project version will be updated after release.") + finalizedBy(project.tasks.named("assemble")) + } } project.tasks.register(PUSH_RELEASE_TASK, PushReleaseTask) { diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy index 702e27fc..2cca922e 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy @@ -1,5 +1,7 @@ package pl.allegro.tech.build.axion.release + +import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction import pl.allegro.tech.build.axion.release.domain.Releaser import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult @@ -12,6 +14,9 @@ import java.nio.file.StandardOpenOption abstract class ReleaseTask extends BaseAxionTask { + @Input + String projectVersion = project.version + @TaskAction void release() { VersionResolutionContext context = resolutionContext() @@ -32,6 +37,10 @@ abstract class ReleaseTask extends BaseAxionTask { throw new ReleaseFailedException("Status: ${status}\nMessage: ${message}") } + if (versionConfig.updateProjectVersionAfterRelease().get()) { + projectVersion = versionConfig.uncached.decoratedVersion + } + if (result.outcome === ScmPushResultOutcome.SUCCESS) { if (System.getenv().containsKey('GITHUB_ACTIONS')) { Files.write( diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy index cf1d1282..8a215201 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy @@ -29,6 +29,7 @@ abstract class VersionConfig extends BaseExtension { private static final String IGNORE_UNCOMMITTED_CHANGES_PROPERTY = 'release.ignoreUncommittedChanges' private static final String FORCE_SNAPSHOT_PROPERTY = 'release.forceSnapshot' private static final String USE_HIGHEST_VERSION_PROPERTY = 'release.useHighestVersion' + private static final String UPDATE_PROJECT_VERSION_AFTER_RELEASE_PROPERTY = 'release.updateProjectVersionAfterRelease' private static final String LOCAL_ONLY = "release.localOnly" private static final String FORCE_VERSION_PROPERTY = 'release.version' private static final String DEPRECATED_FORCE_VERSION_PROPERTY = 'release.forceVersion' @@ -43,6 +44,7 @@ abstract class VersionConfig extends BaseExtension { getLocalOnly().convention(false) getIgnoreUncommittedChanges().convention(true) getUseHighestVersion().convention(false) + getUpdateProjectVersionAfterRelease().convention(false) getUnshallowRepoOnCI().convention(false) getIgnoreGlobalGitConfig().convention(false) getReleaseBranchNames().convention(gradlePropertyAsSet(RELEASE_BRANCH_NAMES_PROPERTY).orElse(['master', 'main'] as Set)) @@ -127,6 +129,9 @@ abstract class VersionConfig extends BaseExtension { @Internal abstract Property getUseHighestVersion(); + @Internal + abstract Property getUpdateProjectVersionAfterRelease(); + Provider ignoreUncommittedChanges() { gradlePropertyPresent(IGNORE_UNCOMMITTED_CHANGES_PROPERTY) .orElse(ignoreUncommittedChanges) @@ -140,6 +145,10 @@ abstract class VersionConfig extends BaseExtension { gradlePropertyPresent(USE_HIGHEST_VERSION_PROPERTY).orElse(useHighestVersion) } + Provider updateProjectVersionAfterRelease() { + gradlePropertyPresent(UPDATE_PROJECT_VERSION_AFTER_RELEASE_PROPERTY).orElse(updateProjectVersionAfterRelease) + } + Provider localOnly() { gradlePropertyPresent(LOCAL_ONLY).orElse(localOnly) }