Skip to content

Commit d4fff1e

Browse files
authored
output released version in github actions environement (#737)
* output released version in GitHub actions environment
1 parent 103e689 commit d4fff1e

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ dependencies {
7575
}
7676
testImplementation("org.testcontainers:spock:1.17.6")
7777
testImplementation("org.spockframework:spock-core:2.3-groovy-3.0")
78+
testImplementation("org.spockframework:spock-junit4:2.3-groovy-3.0")
7879
testImplementation("cglib:cglib-nodep:3.3.0")
7980
testImplementation("org.objenesis:objenesis:3.3")
8081
testImplementation("org.apache.sshd:sshd-core:2.12.1")
8182
testImplementation("org.apache.sshd:sshd-git:2.12.1")
83+
testImplementation("com.github.stefanbirkner:system-rules:1.19.0")
8284
testImplementation(gradleTestKit())
8385
}
8486

src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pl.allegro.tech.build.axion.release
22

33
import org.gradle.testkit.runner.TaskOutcome
4+
import org.junit.Rule
5+
import org.junit.contrib.java.lang.system.EnvironmentVariables
46

57
import java.nio.charset.StandardCharsets
68
import java.nio.file.Files
@@ -9,6 +11,9 @@ import static pl.allegro.tech.build.axion.release.TagPrefixConf.fullPrefix
911

1012
class SimpleIntegrationTest extends BaseIntegrationTest {
1113

14+
@Rule
15+
EnvironmentVariables environmentVariablesRule = new EnvironmentVariables();
16+
1217
def "should return default version on calling currentVersion task on vanilla repo"() {
1318
given:
1419
buildFile('')
@@ -34,6 +39,24 @@ class SimpleIntegrationTest extends BaseIntegrationTest {
3439
result.task(":currentVersion").outcome == TaskOutcome.SUCCESS
3540
}
3641

42+
def "should define a github output when running release task in github workflow context"() {
43+
given:
44+
def outputFile = File.createTempFile("github-outputs", ".tmp")
45+
environmentVariablesRule.set("GITHUB_ACTIONS", "true")
46+
environmentVariablesRule.set("GITHUB_OUTPUT", outputFile.getAbsolutePath())
47+
48+
buildFile('')
49+
50+
when:
51+
runGradle('release', '-Prelease.version=1.0.0', '-Prelease.localOnly', '-Prelease.disableChecks')
52+
53+
then:
54+
outputFile.getText().contains('released-version=1.0.0')
55+
56+
cleanup:
57+
environmentVariablesRule.clear("GITHUB_ACTIONS", "GITHUB_OUTPUT")
58+
}
59+
3760
def "should return released version on calling cV on repo with release commit"() {
3861
given:
3962
buildFile('')
@@ -95,7 +118,7 @@ class SimpleIntegrationTest extends BaseIntegrationTest {
95118
def result = gradle().withArguments('cV').buildAndFail()
96119

97120
then:
98-
result.output.contains(fullPrefix() +'blabla')
121+
result.output.contains(fullPrefix() + 'blabla')
99122
}
100123

101124
def "should use initial version setting"() {

src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class OutputCurrentVersionTask extends BaseAxionTask {
1717
@Inject
1818
OutputCurrentVersionTask() {
1919
this.outputs.upToDateWhen { false }
20-
getQuiet().convention(providers.gradleProperty("release.quiet").map({true})
20+
getQuiet().convention(providers.gradleProperty("release.quiet").map({ true })
2121
.orElse(false))
2222
}
2323

src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class ReleasePlugin implements Plugin<Project> {
2222

2323
def versionConfig = project.extensions.create(VERSION_EXTENSION, VersionConfig, project.rootProject.layout.projectDirectory)
2424

25-
project.tasks.withType(BaseAxionTask).configureEach( {
25+
project.tasks.withType(BaseAxionTask).configureEach({
2626
it.versionConfig = versionConfig
2727
})
2828

src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import pl.allegro.tech.build.axion.release.domain.Releaser
55
import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult
66
import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext
77

8+
import java.nio.file.Files
9+
import java.nio.file.Paths
10+
import java.nio.file.StandardOpenOption
11+
812
abstract class ReleaseTask extends BaseAxionTask {
913

1014
@TaskAction
@@ -13,12 +17,20 @@ abstract class ReleaseTask extends BaseAxionTask {
1317
Releaser releaser = context.releaser()
1418
ScmPushResult result = releaser.releaseAndPush(context.rules())
1519

16-
if(!result.success) {
20+
if (!result.success) {
1721
def status = result.failureStatus.orElse("Unknown status of push")
1822
def message = result.remoteMessage.orElse("Unknown error during push")
1923
logger.error("remote status: ${status}")
2024
logger.error("remote message: ${message}")
2125
throw new ReleaseFailedException("Status: ${status}\nMessage: ${message}")
2226
}
27+
28+
if (System.getenv().containsKey('GITHUB_ACTIONS')) {
29+
Files.write(
30+
Paths.get(System.getenv('GITHUB_OUTPUT')),
31+
"released-version=${versionConfig.version}\n".getBytes(),
32+
StandardOpenOption.APPEND
33+
)
34+
}
2335
}
2436
}

0 commit comments

Comments
 (0)