diff --git a/.project-keeper.yml b/.project-keeper.yml index a57ed378..9297b1ea 100644 --- a/.project-keeper.yml +++ b/.project-keeper.yml @@ -11,6 +11,9 @@ sources: version: "${revision}" relativePath: "../parent-pom/pom.xml" advertise: false + artifacts: + # [itest->dsn~customize-release-artifacts-custom~0] + - target/project-keeper-shared-model-classes-${version}.jar - type: maven path: project-keeper/pom.xml modules: diff --git a/doc/requirements/design.md b/doc/requirements/design.md index 09d753cf..beda8d4c 100644 --- a/doc/requirements/design.md +++ b/doc/requirements/design.md @@ -407,7 +407,7 @@ This allows adding project-specific release artifacts like `.js` extensions. Covers: * [`dsn~customize-release-artifacts~0`](#customize-release-artifacts) --Needs: impl, utest, itest +Needs: impl, utest ### Customize Build Process `dsn~customize-build-process~0` diff --git a/project-keeper/src/main/java/com/exasol/projectkeeper/github/GitHubWorkflowOutput.java b/project-keeper/src/main/java/com/exasol/projectkeeper/github/GitHubWorkflowOutput.java index 08ff51d1..53d900e2 100644 --- a/project-keeper/src/main/java/com/exasol/projectkeeper/github/GitHubWorkflowOutput.java +++ b/project-keeper/src/main/java/com/exasol/projectkeeper/github/GitHubWorkflowOutput.java @@ -102,7 +102,7 @@ private String getAdditionalReleaseTags() { } private String getReleaseArtifacts() { - return Stream.of(sourceReleaseArtifacts(), errorCodeReports()) // + return Stream.of(sourceReleaseArtifacts(), errorCodeReports(), customArtifacts()) // .flatMap(Function.identity()) // .map(Path::toString).collect(joining("\n")); } @@ -125,6 +125,22 @@ private Stream errorCodeReports() { .map(source -> this.projectDir.resolve("target/error_code_report.json")); } + // [impl->dsn~customize-release-artifacts-custom~0] + private Stream customArtifacts() { + return config.getSources().stream().flatMap(this::customArtifacts); + } + + private Stream customArtifacts(final Source source) { + final Path sourcePath = projectDir.resolve(source.getPath()).getParent(); + return source.getReleaseArtifacts().stream() // + .map(this::replaceVersionPlaceholder) // + .map(sourcePath::resolve); + } + + private Path replaceVersionPlaceholder(final Path path) { + return Path.of(path.toString().replace("${version}", this.projectVersion)); + } + private String extractReleaseNotes(final ChangesFile changesFile) { final List lines = new ArrayList<>(); lines.addAll( diff --git a/project-keeper/src/test/java/com/exasol/projectkeeper/github/GitHubWorkflowOutputTest.java b/project-keeper/src/test/java/com/exasol/projectkeeper/github/GitHubWorkflowOutputTest.java index 2a2e7246..93ededbf 100644 --- a/project-keeper/src/test/java/com/exasol/projectkeeper/github/GitHubWorkflowOutputTest.java +++ b/project-keeper/src/test/java/com/exasol/projectkeeper/github/GitHubWorkflowOutputTest.java @@ -1,6 +1,7 @@ package com.exasol.projectkeeper.github; import static java.util.Arrays.asList; +import static java.util.stream.Collectors.joining; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -8,11 +9,15 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; import org.apache.commons.lang3.exception.UncheckedException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -75,13 +80,13 @@ void releaseNotes() { @Test void releaseArtifactsNoMavenSource() { publish(ProjectKeeperConfig.builder(), ChangesFile.builder()); - verify(this.publisherMock).publish("release-artifacts", ""); + verifyReleaseArtifacts(); } @Test void releaseArtifactsMavenSourceWithoutArtifact() { publish(ProjectKeeperConfig.builder(), ChangesFile.builder(), AnalyzedMavenSource.builder().build()); - verify(this.publisherMock).publish("release-artifacts", ""); + verifyReleaseArtifacts(); } // [utest->dsn~customize-release-artifacts-hard-coded~0] @@ -89,29 +94,56 @@ void releaseArtifactsMavenSourceWithoutArtifact() { void releaseArtifactsErrorCodeReport() { publish(ProjectKeeperConfig.builder(), ChangesFile.builder(), AnalyzedMavenSource.builder().isRootProject(true).build()); - verify(this.publisherMock).publish("release-artifacts", - this.projectDir.resolve("target/error_code_report.json").toString()); + verifyReleaseArtifacts("target/error_code_report.json"); } @Test void releaseArtifactsMavenSourceWithArtifact() { publish(ProjectKeeperConfig.builder(), ChangesFile.builder(), AnalyzedMavenSource.builder() .path(this.projectDir.resolve("project-dir/pom.xml")).releaseArtifactName("my-project.jar").build()); - verify(this.publisherMock).publish("release-artifacts", - this.projectDir.resolve("project-dir/target/my-project.jar").toString()); + verifyReleaseArtifacts("project-dir/target/my-project.jar"); + } + + // [utest->dsn~customize-release-artifacts-custom~0] + @ParameterizedTest + @CsvSource({ "pom.xml, target/custom.jar, target/custom.jar", // + "go.mod, build/executable, build/executable", // + "package.json, build/ext.js, build/ext.js", // + "subModule/go.mod, build/executable, subModule/build/executable", // + "pom.xml, target/custom-$version.jar, target/custom-$version.jar", + "pom.xml, target/custom-${version}.jar, target/custom-1.2.3.jar", + "subModule/pom.xml, target/custom-${version}.jar, subModule/target/custom-1.2.3.jar" }) + void releaseArtifactCustom(final String sourcePath, final String artifactPath, final String expectedPath) { + publish(ProjectKeeperConfig.builder().sources(List.of( + Source.builder().path(Path.of(sourcePath)).releaseArtifacts(List.of(Path.of(artifactPath))).build())), + ChangesFile.builder()); + verifyReleaseArtifacts(expectedPath); } @Test void releaseArtifactsMultipleArtifact() { - publish(ProjectKeeperConfig.builder(), ChangesFile.builder(), + publish(ProjectKeeperConfig.builder() + .sources(List.of( + Source.builder().path(Path.of("pom.xml")) + .releaseArtifacts(List.of(Path.of("target/custom-${version}.jar"))).build(), + Source.builder().path(Path.of("subModule/package.json")) + .releaseArtifacts(List.of(Path.of("build/custom-extension.js"))).build())), + ChangesFile.builder(), AnalyzedMavenSource.builder().path(this.projectDir.resolve("pom.xml")) .releaseArtifactName("my-project1.jar").isRootProject(true).build(), AnalyzedMavenSource.builder().path(this.projectDir.resolve("module1/pom.xml")) .releaseArtifactName("my-project2.jar").build()); - verify(this.publisherMock).publish("release-artifacts", - this.projectDir.resolve("target/my-project1.jar").toString() + "\n" - + this.projectDir.resolve("module1/target/my-project2.jar").toString() + "\n" - + this.projectDir.resolve("target/error_code_report.json").toString()); + verifyReleaseArtifacts("target/my-project1.jar", "module1/target/my-project2.jar", + "target/error_code_report.json", "target/custom-" + PROJECT_VERSION + ".jar", + "subModule/build/custom-extension.js"); + } + + private void verifyReleaseArtifacts(final String... expectedPaths) { + final String expected = Arrays.stream(expectedPaths) // + .map(path -> this.projectDir.resolve(path)) // + .map(Path::toString) // + .collect(joining("\n")); + verify(this.publisherMock).publish("release-artifacts", expected); } @Test