diff --git a/build.gradle.kts b/build.gradle.kts index 4107d6e0..40af4d09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -75,10 +75,12 @@ dependencies { } testImplementation("org.testcontainers:spock:1.17.6") testImplementation("org.spockframework:spock-core:2.3-groovy-3.0") + testImplementation("org.spockframework:spock-junit4:2.3-groovy-3.0") testImplementation("cglib:cglib-nodep:3.3.0") testImplementation("org.objenesis:objenesis:3.3") testImplementation("org.apache.sshd:sshd-core:2.12.1") testImplementation("org.apache.sshd:sshd-git:2.12.1") + testImplementation("com.github.stefanbirkner:system-rules:1.19.0") testImplementation(gradleTestKit()) } 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 361e946d..8b4de9cb 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 @@ -1,6 +1,8 @@ package pl.allegro.tech.build.axion.release import org.gradle.testkit.runner.TaskOutcome +import org.junit.Rule +import org.junit.contrib.java.lang.system.EnvironmentVariables import java.nio.charset.StandardCharsets import java.nio.file.Files @@ -9,6 +11,9 @@ import static pl.allegro.tech.build.axion.release.TagPrefixConf.fullPrefix class SimpleIntegrationTest extends BaseIntegrationTest { + @Rule + EnvironmentVariables environmentVariablesRule = new EnvironmentVariables(); + def "should return default version on calling currentVersion task on vanilla repo"() { given: buildFile('') @@ -34,6 +39,24 @@ class SimpleIntegrationTest extends BaseIntegrationTest { result.task(":currentVersion").outcome == TaskOutcome.SUCCESS } + def "should define a github output when running release task in github workflow context"() { + given: + def outputFile = File.createTempFile("github-outputs", ".tmp") + environmentVariablesRule.set("GITHUB_ACTIONS", "true") + environmentVariablesRule.set("GITHUB_OUTPUT", outputFile.getAbsolutePath()) + + buildFile('') + + when: + runGradle('release', '-Prelease.version=1.0.0', '-Prelease.localOnly', '-Prelease.disableChecks') + + then: + outputFile.getText().contains('released-version=1.0.0') + + cleanup: + environmentVariablesRule.clear("GITHUB_ACTIONS", "GITHUB_OUTPUT") + } + def "should return released version on calling cV on repo with release commit"() { given: buildFile('') @@ -95,7 +118,7 @@ class SimpleIntegrationTest extends BaseIntegrationTest { def result = gradle().withArguments('cV').buildAndFail() then: - result.output.contains(fullPrefix() +'blabla') + result.output.contains(fullPrefix() + 'blabla') } def "should use initial version setting"() { diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy index dbc80565..633d8e34 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy @@ -17,7 +17,7 @@ abstract class OutputCurrentVersionTask extends BaseAxionTask { @Inject OutputCurrentVersionTask() { this.outputs.upToDateWhen { false } - getQuiet().convention(providers.gradleProperty("release.quiet").map({true}) + getQuiet().convention(providers.gradleProperty("release.quiet").map({ true }) .orElse(false)) } 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 2891bc58..91f28c1d 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 @@ -22,7 +22,7 @@ abstract class ReleasePlugin implements Plugin { def versionConfig = project.extensions.create(VERSION_EXTENSION, VersionConfig, project.rootProject.layout.projectDirectory) - project.tasks.withType(BaseAxionTask).configureEach( { + project.tasks.withType(BaseAxionTask).configureEach({ it.versionConfig = versionConfig }) 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 b00f20d4..8ae9e304 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 @@ -5,6 +5,10 @@ import pl.allegro.tech.build.axion.release.domain.Releaser import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext +import java.nio.file.Files +import java.nio.file.Paths +import java.nio.file.StandardOpenOption + abstract class ReleaseTask extends BaseAxionTask { @TaskAction @@ -13,12 +17,20 @@ abstract class ReleaseTask extends BaseAxionTask { Releaser releaser = context.releaser() ScmPushResult result = releaser.releaseAndPush(context.rules()) - if(!result.success) { + if (!result.success) { def status = result.failureStatus.orElse("Unknown status of push") def message = result.remoteMessage.orElse("Unknown error during push") logger.error("remote status: ${status}") logger.error("remote message: ${message}") throw new ReleaseFailedException("Status: ${status}\nMessage: ${message}") } + + if (System.getenv().containsKey('GITHUB_ACTIONS')) { + Files.write( + Paths.get(System.getenv('GITHUB_OUTPUT')), + "released-version=${versionConfig.version}\n".getBytes(), + StandardOpenOption.APPEND + ) + } } }