From 58ea50e722853549a25a79e3a5adf8cab8adeb0e Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 14 Feb 2024 14:37:57 +0100 Subject: [PATCH] Polishing. Provide GPG signature arguments to release profile. Determine default branch from ModuleIteration and avoid branch defaulting to main. --- .../data/release/build/MavenBuildSystem.java | 8 +++- .../data/release/git/Branch.java | 18 +++++++++ .../data/release/git/GitOperations.java | 37 +++++++++++-------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java b/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java index 62b9b21..756d27f 100644 --- a/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java +++ b/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java @@ -235,8 +235,12 @@ class MavenBuildSystem implements BuildSystem { @Override public M triggerBuild(M module) { - CommandLine arguments = CommandLine.of(Goal.CLEAN, Goal.INSTALL)// - .and(profile("ci,release")).andIf(module.getSupportedProject().getProject().skipTests(), SKIP_TESTS) + CommandLine arguments = CommandLine.of(Goal.CLEAN, Goal.INSTALL, // + profile("ci,release"), // + arg("gpg.executable").withValue(gpg.getExecutable()), // + arg("gpg.keyname").withValue(gpg.getKeyname()), // + arg("gpg.passphrase").withValue(gpg.getPassphrase()))// + .andIf(module.getSupportedProject().getProject().skipTests(), SKIP_TESTS) .andIf(!ObjectUtils.isEmpty(properties.getSettingsXml()), settingsXml(properties.getSettingsXml())); mvn.execute(module.getSupportedProject(), arguments); diff --git a/src/main/java/org/springframework/data/release/git/Branch.java b/src/main/java/org/springframework/data/release/git/Branch.java index 6b0fc0e..e1eb473 100644 --- a/src/main/java/org/springframework/data/release/git/Branch.java +++ b/src/main/java/org/springframework/data/release/git/Branch.java @@ -20,6 +20,7 @@ import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; import org.springframework.data.release.model.IterationVersion; +import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.Tracker; import org.springframework.data.release.model.Version; import org.springframework.data.release.model.VersionAware; @@ -39,6 +40,23 @@ public class Branch implements Comparable { private final String name; + /** + * Creates a new {@link Branch} from the given {@link IterationVersion}. + * + * @param iterationVersion must not be {@literal null}. + * @return + */ + public static Branch from(ModuleIteration iterationVersion) { + + Assert.notNull(iterationVersion, "Iteration version must not be null!"); + + if (iterationVersion.isBranchVersion() || iterationVersion.isCommercial()) { + return from((VersionAware) iterationVersion); + } + + return MAIN; + } + /** * Creates a new {@link Branch} from the given {@link IterationVersion}. * diff --git a/src/main/java/org/springframework/data/release/git/GitOperations.java b/src/main/java/org/springframework/data/release/git/GitOperations.java index 3cbba1b..bc24447 100644 --- a/src/main/java/org/springframework/data/release/git/GitOperations.java +++ b/src/main/java/org/springframework/data/release/git/GitOperations.java @@ -61,17 +61,18 @@ import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.TagOpt; import org.eclipse.jgit.transport.URIish; + import org.springframework.data.release.io.Workspace; import org.springframework.data.release.issues.IssueTracker; import org.springframework.data.release.issues.Ticket; import org.springframework.data.release.issues.TicketReference; import org.springframework.data.release.issues.TicketStatus; import org.springframework.data.release.model.*; -import org.springframework.data.release.model.Module; import org.springframework.data.release.utils.ExecutionUtils; import org.springframework.data.release.utils.Logger; import org.springframework.data.util.Pair; import org.springframework.data.util.Streamable; +import org.springframework.lang.Nullable; import org.springframework.plugin.core.PluginRegistry; import org.springframework.stereotype.Component; import org.springframework.util.Assert; @@ -224,7 +225,7 @@ public class GitOperations { SupportedProject project = module.getSupportedProject(); Branch branch = Branch.from(module); - update(project); + update(project, branch); checkout(project, branch); logger.log(project, "Pulling latest updates for branch %s…", branch); @@ -297,6 +298,17 @@ public class GitOperations { * @param project must not be {@literal null}. */ public void update(SupportedProject project) { + update(project, null); + } + + /** + * Updates the given {@link Project}. Will either pull the latest changes or clone the project's repository if not + * already available. + * + * @param project must not be {@literal null}. + * @param branch + */ + public void update(SupportedProject project, @Nullable Branch branch) { Assert.notNull(project, "Project must not be null!"); @@ -311,7 +323,7 @@ public class GitOperations { logger.log(project, "Found existing repository %s. Obtaining latest changes…", repositoryName); - checkout(project, Branch.MAIN); + checkout(project, branch == null ? Branch.from(git.getRepository().getBranch()) : branch); logger.log(project, "git fetch --tags"); @@ -694,8 +706,7 @@ public class GitOperations { * @param summary must not be {@literal null} or empty. * @param details can be {@literal null} or empty. */ - public void commit(ProjectAware module, Ticket ticket, String summary, Optional details, - boolean all) { + public void commit(ProjectAware module, Ticket ticket, String summary, Optional details, boolean all) { Assert.notNull(module, "ProjectAware must not be null!"); @@ -965,9 +976,9 @@ public class GitOperations { Predicate trigger = calculateFilter(module, summary); - return findCommit(module, summary).orElseThrow(() -> new IllegalStateException(String - .format("Did not find a commit with summary starting with '%s' for project %s", module.getSupportedProject(), - trigger))); + return findCommit(module, summary).orElseThrow(() -> new IllegalStateException( + String.format("Did not find a commit with summary starting with '%s' for project %s", + module.getSupportedProject(), trigger))); } private Optional findCommit(ModuleIteration module, String summary) { @@ -1038,14 +1049,10 @@ public class GitOperations { logger.log(project, "No repository found! Cloning from %s…", gitProject.getProjectUri()); - Git git = call(Git.cloneRepository() // + call(Git.cloneRepository() // .setURI(gitProject.getProjectUri()) // .setDirectory(workspace.getProjectDirectory(project))); - git.checkout() // - .setName(Branch.MAIN.toString()) // - .call(); - logger.log(project, "Cloning done!", project); } @@ -1122,9 +1129,7 @@ public class GitOperations { private > T call(TransportCommand command) throws GitAPIException { - return command - .setCredentialsProvider(gitProperties.getCredentials()) - .call(); + return command.setCredentialsProvider(gitProperties.getCredentials()).call(); } /**