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 6446e468..995b4d4e 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 @@ -43,7 +43,7 @@ class SimpleIntegrationTest extends BaseIntegrationTest { def "should set released-version github output after release task"(String task, String rootProjectVersion, String subprojectVersion, - String output) { + List output) { given: def outputFile = File.createTempFile("github-outputs", ".tmp") environmentVariablesRule.set("GITHUB_ACTIONS", "true") @@ -91,23 +91,23 @@ class SimpleIntegrationTest extends BaseIntegrationTest { then: def definedEnvVariables = outputFile.getText().lines().collect(toList()) - definedEnvVariables.contains(output) + definedEnvVariables == output cleanup: environmentVariablesRule.clear("GITHUB_ACTIONS", "GITHUB_OUTPUT") where: task | rootProjectVersion | subprojectVersion || output - 'release' | "1.0.0" | "1.0.0" || 'released-version=1.0.1' - 'release' | "1.0.0" | "2.0.0" || 'released-version={"root-project":"1.0.1","sub-project":"2.0.1"}' - ':release' | "1.0.0" | "2.0.0" || 'released-version=1.0.1' - ':sub-project:release' | "1.0.0" | "2.0.0" || 'released-version=2.0.1' + 'release' | "1.0.0" | "1.0.0" || ['released-version=1.0.1'] + 'release' | "1.0.0" | "2.0.0" || ['released-version={"root-project":"1.0.1","sub-project":"2.0.1"}'] + ':release' | "1.0.0" | "2.0.0" || ['released-version=1.0.1'] + ':sub-project:release' | "1.0.0" | "2.0.0" || ['released-version=2.0.1'] } def "should set published-version github output after publish task"(String task, String rootProjectVersion, String subprojectVersion, - String output) { + List output) { given: def outputFile = File.createTempFile("github-outputs", ".tmp") environmentVariablesRule.set("GITHUB_ACTIONS", "true") @@ -145,17 +145,59 @@ class SimpleIntegrationTest extends BaseIntegrationTest { then: def definedEnvVariables = outputFile.getText().lines().collect(toList()) - definedEnvVariables.contains(output) + definedEnvVariables == output cleanup: environmentVariablesRule.clear("GITHUB_ACTIONS", "GITHUB_OUTPUT") where: task | rootProjectVersion | subprojectVersion || output - 'publish' | "1.0.0" | "1.0.0" || 'published-version=1.0.0' - 'publish' | "1.0.0" | "2.0.0" || 'published-version={"root-project":"1.0.0","sub-project":"2.0.0"}' - ':publish' | "1.0.0" | "2.0.0" || 'published-version=1.0.0' - ':sub-project:publish' | "1.0.0" | "2.0.0" || 'published-version=2.0.0' + 'publish' | "1.0.0" | "1.0.0" || ['published-version=1.0.0'] + 'publish' | "1.0.0" | "2.0.0" || ['published-version={"root-project":"1.0.0","sub-project":"2.0.0"}'] + ':publish' | "1.0.0" | "2.0.0" || ['published-version=1.0.0'] + ':sub-project:publish' | "1.0.0" | "2.0.0" || ['published-version=2.0.0'] + } + + def "should set published-version github output even if root project does not apply maven-publish"() { + given: + def outputFile = File.createTempFile("github-outputs", ".tmp") + environmentVariablesRule.set("GITHUB_ACTIONS", "true") + environmentVariablesRule.set("GITHUB_OUTPUT", outputFile.getAbsolutePath()) + + vanillaSettingsFile(""" + rootProject.name = 'root-project' + + include 'sub-project' + """ + ) + + vanillaBuildFile(""" + plugins { + id 'pl.allegro.tech.build.axion-release' + } + + allprojects { + version = '1.0.0' + } + """ + ) + + vanillaSubprojectBuildFile("sub-project", """ + plugins { + id 'maven-publish' + } + """ + ) + + when: + runGradle('publish') + + then: + def definedEnvVariables = outputFile.getText().lines().collect(toList()) + definedEnvVariables == ['published-version=1.0.0'] + + cleanup: + environmentVariablesRule.clear("GITHUB_ACTIONS", "GITHUB_OUTPUT") } def "should return released version on calling cV on repo with release commit"() { 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 a43ec627..f600320e 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 @@ -78,14 +78,16 @@ abstract class ReleasePlugin implements Plugin { } private static setGithubOutputsAfterPublishTask(Project project, Provider githubService) { - String projectName = project.name - Provider projectVersion = project.provider { project.version.toString() } - - project.plugins.withId('maven-publish') { - project.tasks.named('publish') { task -> - task.usesService(githubService) - task.doLast { - githubService.get().setOutput('published-version', projectName, projectVersion.get()) + project.allprojects { Project p -> + String projectName = p.name + Provider projectVersion = p.provider { p.version.toString() } + + p.plugins.withId('maven-publish') { + p.tasks.named('publish') { task -> + task.usesService(githubService) + task.doLast { + githubService.get().setOutput('published-version', projectName, projectVersion.get()) + } } } } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/github/GithubService.java b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/github/GithubService.java index 986e78cd..d703d140 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/github/GithubService.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/github/GithubService.java @@ -44,7 +44,7 @@ public void close() { writeOutput(name, singleValue); } else { String jsonValue = new JsonBuilder(valuePerProject).toString(); - logger.warn("Multiple values provided for the '{}' GitHub output, it will be formatted as JSON: {}", name, jsonValue); + logger.warn("Multiple values provided for the '{}' GitHub output, it will be formatted as JSON", name); writeOutput(name, jsonValue); } }); @@ -58,6 +58,7 @@ private static void writeOutput(String name, String value) { String.format("%s=%s\n", name, value).getBytes(), StandardOpenOption.APPEND ); + logger.lifecycle("Written GitHub output: {}={}", name, value); } catch (IOException e) { logger.warn("Unable to the set '{}' GitHub output, cause: {}", name, e.getMessage()); }