Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -37,6 +38,7 @@
import releaser.internal.project.Projects;
import releaser.internal.sagan.SaganClient;
import releaser.internal.sagan.SaganUpdater;
import releaser.internal.spring.ArgsBuilder;
import releaser.internal.spring.Arguments;
import releaser.internal.spring.SpringReleaser;
import releaser.internal.tasks.ReleaseReleaserTask;
Expand Down Expand Up @@ -86,6 +88,64 @@ public class SpringMetaReleaseAcceptanceTests extends AbstractSpringCloudMetaAcc
@TempDir
File tempDirAllTestSample;

private void should_perform_a_meta_release_of_sc_release_and_consul(File tempDirSpringCloudConsulOrigin,
File tempDirSpringCloudConsulProject, boolean dryRun,
Consumer<NonAssertingTestProjectGitHandler> stepAsserter, ArgsBuilder argsBuilder) throws Exception {
checkoutReleaseTrainBranch("/projects/spring-cloud-release/", "2022.0.x");

run(defaultRunner(),
properties("debugx=true")
.properties("test.metarelease=true", "releaser.git.create-release-notes-for-milestone=false")
.properties(argsBuilder.build()),
context -> {
SpringReleaser releaser = context.getBean(SpringReleaser.class);
NonAssertingTestProjectGitHandler nonAssertingTestProjectGitHandler = context
.getBean(NonAssertingTestProjectGitHandler.class);
SaganUpdater saganUpdater = context.getBean(SaganUpdater.class);
PostReleaseActions postReleaseActions = context.getBean(PostReleaseActions.class);
TestExecutionResultHandler testExecutionResultHandler = context
.getBean(TestExecutionResultHandler.class);
ReleaseBundleCreator creator = context.getBean(ReleaseBundleCreator.class);

ExecutionResult result = releaser
.release(new OptionsBuilder().metaRelease(true).dryRun(dryRun).options());

// print results
testExecutionResultHandler.accept(result);
then(testExecutionResultHandler.exitedSuccessOrUnstable).isTrue();

then(result.isFailureOrUnstable()).isFalse();
// consul, release
then(nonAssertingTestProjectGitHandler.clonedProjects).hasSize(2);
// don't want to verify the docs
stepAsserter.accept(nonAssertingTestProjectGitHandler);
ProjectVersion projectVersion = new ProjectVersion(tempDirSpringCloudConsulOrigin);
if (!dryRun && !projectVersion.isSnapshot()) {
thenSaganWasCalled(saganUpdater);
then(clonedProject(nonAssertingTestProjectGitHandler, "spring-cloud-consul-commercial")
.tagList().call()).extracting("name").contains("refs/tags/v4.0.2");
thenRunUpdatedTestsWereCalled(postReleaseActions);
thenUpdateReleaseTrainDocsWasCalled(postReleaseActions);
BDDMockito.then(creator).should(times(1))
.createReleaseTrainSourceBundle(
List.of(new ProjectVersion("spring-cloud-consul", "4.0.2"),
new ProjectVersion("spring-cloud-starter-build", "2022.0.4")),
"2022.0.4");
BDDMockito.then(creator).should(times(1)).createReleaseBundle(
List.of("org/springframework/cloud/spring-cloud-consul*",
"org/springframework/cloud/spring-cloud-starter-consul*"),
"4.0.2", "TNZ-spring-cloud-consul-commercial");
BDDMockito.then(creator).should(times(1)).distributeReleaseTrainSourceBundle("2022.0.4");
// This should never be called when releasing a release train
// since
// distributing a release train source bundle
// will distribute individual project release bundles
verify(creator, never()).distributeReleaseBundle(anyString(), anyString(), anyString());
}

});
}

@Test
public void should_perform_a_meta_release_of_sc_release_and_consul(@TempDir File tempDirSpringCloudConsulOrigin,
@TempDir File tempDirSpringCloudConsulProject) throws Exception {
Expand Down Expand Up @@ -144,6 +204,63 @@ public void should_perform_a_meta_release_of_sc_release_and_consul(@TempDir File
});
}

@Test
public void should_perform_a_meta_release_of_sc_release_and_consul_ga(@TempDir File tempDirSpringCloudConsulOrigin,
@TempDir File tempDirSpringCloudConsulProject) throws Exception {
File origin = cloneToTemporaryDirectory(tempDirSpringCloudConsulOrigin,
this.springCloudConsulCommercialProject);
assertThatClonedConsulProjectIsInSnapshots(origin);
File project = cloneToTemporaryDirectory(tempDirSpringCloudConsulProject, tmpFile("spring-cloud-consul"));
GitTestUtils.setOriginOnProjectToTmp(origin, project);
should_perform_a_meta_release_of_sc_release_and_consul(tempDirSpringCloudConsulOrigin,
tempDirSpringCloudConsulProject, false, this::thenAllStepsWereExecutedForEachProjectDuringGaRelease,
metaReleaseArgs(project, tempDirTestSamplesProject, tempDirReleaseTrainDocs, tempDirSpringCloud,
tempDirReleaseTrainWiki, tempDirAllTestSample).bomBranch("v2022.0.2")
.addFixedVersions(v2022_0_4()).distributeReleaseTrainSourceReleaseBundle(true)
.releaseTrainSourceReleaseBundle(true).projectReleaseBundle(true).commercial(true)
.mavenGaReleaseBuildCommand("echo '{{profiles}}' > /tmp/executed_ga_build"));
}

@Test
public void should_perform_a_snapshot_meta_release_of_sc_release_and_consul_ga(
@TempDir File tempDirSpringCloudConsulOrigin, @TempDir File tempDirSpringCloudConsulProject)
throws Exception {
File origin = cloneToTemporaryDirectory(tempDirSpringCloudConsulOrigin,
this.springCloudConsulCommercialProject);
assertThatClonedConsulProjectIsInSnapshots(origin);
File project = cloneToTemporaryDirectory(tempDirSpringCloudConsulProject, tmpFile("spring-cloud-consul"));
GitTestUtils.setOriginOnProjectToTmp(origin, project);
should_perform_a_meta_release_of_sc_release_and_consul(tempDirSpringCloudConsulOrigin,
tempDirSpringCloudConsulProject, false, this::thenAllStepsWereExecutedForEachProject,
metaReleaseArgs(project, tempDirTestSamplesProject, tempDirReleaseTrainDocs, tempDirSpringCloud,
tempDirReleaseTrainWiki, tempDirAllTestSample).bomBranch("v2022.0.2")
.addFixedVersions(v2022_0_4_SNAPSHOT()).distributeReleaseTrainSourceReleaseBundle(true)
.releaseTrainSourceReleaseBundle(true).projectReleaseBundle(true).commercial(true)
.mavenGaReleaseBuildCommand("echo '{{profiles}}' > /tmp/executed_ga_build"));
}

@Test
public void should_perform_a_dry_run_meta_release_of_sc_release_and_consul_ga(
@TempDir File tempDirSpringCloudConsulOrigin, @TempDir File tempDirSpringCloudConsulProject)
throws Exception {
File origin = cloneToTemporaryDirectory(tempDirSpringCloudConsulOrigin,
this.springCloudConsulCommercialProject);
assertThatClonedConsulProjectIsInSnapshots(origin);
File project = cloneToTemporaryDirectory(tempDirSpringCloudConsulProject, tmpFile("spring-cloud-consul"));
GitTestUtils.setOriginOnProjectToTmp(origin, project);
should_perform_a_meta_release_of_sc_release_and_consul(tempDirSpringCloudConsulOrigin,
tempDirSpringCloudConsulProject, true, this::thenAllDryRunStepsWereExecutedForEachProject,
metaReleaseArgs(project, tempDirTestSamplesProject, tempDirReleaseTrainDocs, tempDirSpringCloud,
tempDirReleaseTrainWiki, tempDirAllTestSample).bomBranch("v2022.0.2")
.addFixedVersions(v2022_0_4()).distributeReleaseTrainSourceReleaseBundle(true)
.releaseTrainSourceReleaseBundle(true).projectReleaseBundle(true).commercial(true)
// Because this is a dry run we should not run the GA
// release build command,
// thenAllDryRunStepsWereExecutedForEachProject verifies
// just the build command was run
.mavenGaReleaseBuildCommand("echo '{{profiles}}' > /tmp/executed_ga_build"));
}

@Test
public void should_perform_a_meta_release_of_sc_release_and_consul_in_parallel(
@TempDir File tempDirSpringCloudConsulOrigin, @TempDir File tempDirSpringCloudConsulProject)
Expand Down
4 changes: 2 additions & 2 deletions releaser-core/src/main/java/releaser/internal/Releaser.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ private ExecutionResult updateProjectFromBom(File project, Projects versions, Pr
}

public ExecutionResult buildProject(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion versionFromBom) {
this.projectCommandExecutor.build(properties, originalVersion, versionFromBom);
ProjectVersion versionFromBom, boolean dryRun) {
this.projectCommandExecutor.build(properties, originalVersion, versionFromBom, dryRun);
log.info("\nProject was successfully built");
return ExecutionResult.success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ public ReleaserProperties copy() {
*/
public interface Command {

/**
* @return build command
*/
String getGaReleaseBuildCommand();

/**
* @param buildCommand to set
*/
void setGaReleaseBuildCommand(String buildCommand);

/**
* @return build command
*/
Expand Down Expand Up @@ -1037,6 +1047,14 @@ public static class Maven implements Serializable, Command {
**/
private String buildCommand = "./mvnw clean install -B -Pdocs {{systemProps}}";

/**
* Command to be executed during a dry run build. If present "{{version}}" will be
* replaced by the provided version. "{{nextVersion}}" with the bumped snapshot
* version and "{{oldVersion}}" with the version before version updating. By
* default the value is the same as null.
**/
private String gaReleaseBuildCommand = null;

/**
* Command to be executed to deploy a built project. If present "{{version}}" will
* be replaced by the provided version. "{{nextVersion}}" with the bumped snapshot
Expand Down Expand Up @@ -1076,6 +1094,19 @@ public static class Maven implements Serializable, Command {
*/
private long waitTimeInMinutes = 20;

@Override
public String getGaReleaseBuildCommand() {
if (this.gaReleaseBuildCommand == null) {
return this.getBuildCommand();
}
return this.gaReleaseBuildCommand;
}

@Override
public void setGaReleaseBuildCommand(String buildCommand) {
this.gaReleaseBuildCommand = buildCommand;
}

@Override
public String getBuildCommand() {
return this.buildCommand;
Expand Down Expand Up @@ -1146,8 +1177,9 @@ public void setSystemProperties(String systemProperties) {

@Override
public String toString() {
return "Maven{" + "buildCommand='" + this.buildCommand + '\'' + ", deployCommand='" + this.deployCommand
+ '\'' + ", publishDocsCommand=" + this.publishDocsCommand + "generateReleaseTrainDocsCommand='"
return "Maven{" + "buildCommand='" + this.buildCommand + '\'' + ", dryRunBuildCommand='"
+ this.gaReleaseBuildCommand + '\'' + ", deployCommand='" + this.deployCommand + '\''
+ ", publishDocsCommand=" + this.publishDocsCommand + "generateReleaseTrainDocsCommand='"
+ this.generateReleaseTrainDocsCommand + '\'' + ", waitTimeInMinutes=" + this.waitTimeInMinutes
+ '}';
}
Expand All @@ -1168,6 +1200,14 @@ public static class Bash implements Serializable, Command {
*/
private String buildCommand = "echo \"{{systemProps}}\"";

/**
* Command to be executed to build the project during a GA release. If present
* "{{version}}" will be replaced by the provided version. "{{nextVersion}}" with
* the bumped snapshot version and "{{oldVersion}}" with the version before
* version updating. By default the value is null.
*/
private String gaReleaseBuildCommand = null;

/**
* Command to be executed to deploy a built project. If present "{{version}}" will
* be replaced by the provided version. "{{nextVersion}}" with the bumped snapshot
Expand Down Expand Up @@ -1207,6 +1247,19 @@ public static class Bash implements Serializable, Command {
*/
private long waitTimeInMinutes = 20;

@Override
public String getGaReleaseBuildCommand() {
if (this.gaReleaseBuildCommand == null) {
return this.getBuildCommand();
}
return this.gaReleaseBuildCommand;
}

@Override
public void setGaReleaseBuildCommand(String buildCommand) {
this.gaReleaseBuildCommand = buildCommand;
}

@Override
public String getBuildCommand() {
return this.buildCommand;
Expand Down Expand Up @@ -1277,8 +1330,9 @@ public void setSystemProperties(String systemProperties) {

@Override
public String toString() {
return "Bash{" + "buildCommand='" + this.buildCommand + '\'' + ", deployCommand='" + this.deployCommand
+ '\'' + ", publishDocsCommand=" + this.publishDocsCommand + "generateReleaseTrainDocsCommand='"
return "Bash{" + "buildCommand='" + this.buildCommand + '\'' + ", dryRunBuildCommand='"
+ this.gaReleaseBuildCommand + '\'' + ", deployCommand='" + this.deployCommand + '\''
+ ", publishDocsCommand=" + this.publishDocsCommand + "generateReleaseTrainDocsCommand='"
+ this.generateReleaseTrainDocsCommand + '\'' + ", waitTimeInMinutes=" + this.waitTimeInMinutes
+ '}';
}
Expand Down Expand Up @@ -1320,12 +1374,20 @@ public static class Gradle implements Serializable, Command {
private List<String> ignoredGradleRegex = new ArrayList<>();

/**
* Command to be executed to build the project If present "{{version}}" will be
* Command to be executed to build the project. If present "{{version}}" will be
* replaced by the provided version. "{{nextVersion}}" with the bumped snapshot
* version and "{{oldVersion}}" with the version before version updating.
**/
private String buildCommand = "./gradlew clean build publishToMavenLocal --console=plain -PnextVersion={{nextVersion}} -PoldVersion={{oldVersion}} -PcurrentVersion={{version}} {{systemProps}}";

/**
* Command to be executed to build the project during a dry run. If present
* "{{version}}" will be replaced by the provided version. "{{nextVersion}}" with
* the bumped snapshot version and "{{oldVersion}}" with the version before
* version updating. By default the value is null.
*/
private String gaReleaseBuildCommand = null;

/**
* Command to be executed to deploy a built project.
*/
Expand Down Expand Up @@ -1359,6 +1421,19 @@ public static class Gradle implements Serializable, Command {
*/
private long waitTimeInMinutes = 20;

@Override
public String getGaReleaseBuildCommand() {
if (this.gaReleaseBuildCommand == null) {
return this.getBuildCommand();
}
return this.gaReleaseBuildCommand;
}

@Override
public void setGaReleaseBuildCommand(String buildCommand) {
this.gaReleaseBuildCommand = buildCommand;
}

@Override
public String getBuildCommand() {
return this.buildCommand;
Expand Down Expand Up @@ -1448,7 +1523,8 @@ public String toString() {
return new StringJoiner(", ", Gradle.class.getSimpleName() + "[", "]")
.add("gradlePropsSubstitution=" + gradlePropsSubstitution)
.add("ignoredGradleRegex=" + ignoredGradleRegex).add("buildCommand='" + buildCommand + "'")
.add("deployCommand='" + deployCommand + "'")
.add("dryRunBuildCommand='" + gaReleaseBuildCommand + "'")
.add("buildCommand='" + buildCommand + "'").add("deployCommand='" + deployCommand + "'")
.add("deployGuidesCommand='" + deployGuidesCommand + "'")
.add("publishDocsCommand=" + publishDocsCommand)
.add("generateReleaseTrainDocsCommand='" + generateReleaseTrainDocsCommand + "'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public ExecutionResult runUpdatedTests(Projects projects) {
String releaseTrainVersion = projects.releaseTrain(projectProps).version;
Projects newProjects = addVersionForTestsProject(projects, projectVersion, releaseTrainVersion);
updateWithVersions(file, newProjects);
this.projectCommandExecutor.build(projectProps, projectVersion, projectVersion, file.getAbsolutePath());
this.projectCommandExecutor.build(projectProps, projectVersion, projectVersion, file.getAbsolutePath(), false);
return ExecutionResult.success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ public class ProjectCommandExecutor {

public void build(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion versionFromReleaseTrain) {
build(properties, originalVersion, versionFromReleaseTrain, properties.getWorkingDir());
build(properties, originalVersion, versionFromReleaseTrain, properties.getWorkingDir(), false);
}

public void build(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion versionFromReleaseTrain, boolean dryRyn) {
build(properties, originalVersion, versionFromReleaseTrain, properties.getWorkingDir(), dryRyn);
}

public String version(ReleaserProperties properties) {
Expand Down Expand Up @@ -82,9 +87,19 @@ private String executeCommandWithOutput(ReleaserProperties properties, String co
}

public void build(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion versionFromReleaseTrain, String projectRoot) {
ProjectVersion versionFromReleaseTrain, String projectRoot, boolean dryRun) {
try {
String command = new CommandPicker(properties, projectRoot).buildCommand(versionFromReleaseTrain);
CommandPicker commandPicker = new CommandPicker(properties, projectRoot);
boolean useGaReleaseBuildCommand = !dryRun && !versionFromReleaseTrain.isSnapshot();
String command;
if (useGaReleaseBuildCommand) {
log.info(
"We are not doing a dry run and not releasing a snapshot so will use GA release build command");
command = commandPicker.gaReleaseBuildCommand(versionFromReleaseTrain);
}
else {
command = commandPicker.buildCommand(versionFromReleaseTrain);
}
String[] commands = replaceAllPlaceHolders(originalVersion, versionFromReleaseTrain, command).split(" ");
runCommand(properties, projectRoot, commands);
assertNoHtmlFilesInDocsContainUnresolvedTags(projectRoot);
Expand Down Expand Up @@ -307,6 +322,17 @@ else if (projectType == ProjectType.MAVEN) {
return bashCommandWithSystemProps(releaserProperties.getBash().getBuildCommand());
}

String gaReleaseBuildCommand(ProjectVersion version) {
log.info("Running GA release build command.");
if (projectType == ProjectType.GRADLE) {
return gradleCommandWithSystemProps(releaserProperties.getGradle().getGaReleaseBuildCommand());
}
else if (projectType == ProjectType.MAVEN) {
return mavenCommandWithSystemProps(releaserProperties.getMaven().getGaReleaseBuildCommand(), version);
}
return bashCommandWithSystemProps(releaserProperties.getBash().getGaReleaseBuildCommand());
}

String version() {
// makes more sense to use PomReader
if (projectType == ProjectType.GRADLE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void should_successfully_execute_a_command_when_path_is_provided_explicit
ProjectCommandExecutor builder = projectBuilder(properties);

builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
tmpFile("/builder/resolved").getPath());
tmpFile("/builder/resolved").getPath(), false);

then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("resolved.log");
}
Expand Down
Loading