Skip to content

Commit

Permalink
output released version in github actions environement (#737)
Browse files Browse the repository at this point in the history
* output released version in GitHub actions environment
  • Loading branch information
bgalek authored Apr 30, 2024
1 parent 103e689 commit d4fff1e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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('')
Expand All @@ -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('')
Expand Down Expand Up @@ -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"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class ReleasePlugin implements Plugin<Project> {

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
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
}
}
}

0 comments on commit d4fff1e

Please sign in to comment.