From 305b0c122b68b93b8f8092e9c8c0603db1f9b3cc Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Wed, 16 Oct 2024 16:38:48 +0200 Subject: [PATCH 1/9] Add verbose information to version generation logic --- docs/configuration/version.md | 5 +++ .../axion/release/domain/VersionConfig.groovy | 5 +++ .../config/ScmPropertiesFactory.groovy | 3 +- .../di/VersionResolutionContext.groovy | 3 +- .../axion/release/domain/VersionResolver.java | 4 +- .../axion/release/domain/VersionSorter.java | 40 +++++++++++++++---- .../release/domain/scm/ScmProperties.java | 9 ++++- .../domain/VersionResolverMonoRepoTest.groovy | 2 +- .../VersionResolverSubfolderTest.groovy | 2 +- .../release/domain/VersionResolverTest.groovy | 2 +- .../release/domain/VersionSorterTest.groovy | 2 +- .../domain/scm/ScmPropertiesBuilder.groovy | 3 +- 12 files changed, 63 insertions(+), 17 deletions(-) diff --git a/docs/configuration/version.md b/docs/configuration/version.md index 9f524b90..3af59dac 100644 --- a/docs/configuration/version.md +++ b/docs/configuration/version.md @@ -425,3 +425,8 @@ property: scmVersion { sanitizeVersion.set(false) } + +## Troubleshooting +In case of problems use can try to use verbose mode: + + #./gradlew release -Prelease.verbose diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy index cf1d1282..9ff40f89 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy @@ -36,10 +36,12 @@ abstract class VersionConfig extends BaseExtension { private static final String VERSION_CREATOR_PROPERTY = 'release.versionCreator' private static final String RELEASE_ONLY_ON_RELEASE_BRANCHES_PROPERTY = 'release.releaseOnlyOnReleaseBranches' private static final String RELEASE_BRANCH_NAMES_PROPERTY = 'release.releaseBranchNames' + private static final String RELEASE_VERBOSE = 'release.verbose' @Inject VersionConfig(Directory repositoryDirectory) { getDryRun().convention(gradlePropertyPresent(DRY_RUN_FLAG).orElse(false)) + getVerbose().convention(gradlePropertyPresent(RELEASE_VERBOSE).orElse(false)) getLocalOnly().convention(false) getIgnoreUncommittedChanges().convention(true) getUseHighestVersion().convention(false) @@ -81,6 +83,9 @@ abstract class VersionConfig extends BaseExtension { @Internal abstract Property getDryRun() + @Internal + abstract Property getVerbose() + @Internal abstract Property getIgnoreUncommittedChanges() diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy index 8900f4cb..fde6c8e1 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy @@ -20,7 +20,8 @@ class ScmPropertiesFactory { config.getUnshallowRepoOnCI().get(), config.getReleaseBranchNames().get(), config.getReleaseOnlyOnReleaseBranches().get(), - config.getIgnoreGlobalGitConfig().get() + config.getIgnoreGlobalGitConfig().get(), + config.verbose.get() ) } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy index a35c4506..9a33659e 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy @@ -35,7 +35,8 @@ class VersionResolutionContext { this.scmProperties = scmProperties this.localOnlyResolver = localOnlyResolver this.versionService = new VersionService(new VersionResolver(scmRepository, - scmProperties.directory.toPath().relativize(projectRoot.toPath()).toString())) + scmProperties.directory.toPath().relativize(projectRoot.toPath()).toString(), + scmProperties.isVerbose())) } static VersionResolutionContext create(VersionConfig versionConfig, Directory projectDirectory) { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java index 742ae1b3..b975f98c 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java @@ -33,10 +33,10 @@ public class VersionResolver { */ private final String projectRootRelativePath; - public VersionResolver(ScmRepository repository, String projectRootRelativePath) { + public VersionResolver(ScmRepository repository, String projectRootRelativePath, boolean verbose) { this.repository = repository; this.projectRootRelativePath = projectRootRelativePath; - this.sorter = new VersionSorter(); + this.sorter = new VersionSorter(verbose); } public VersionContext resolveVersion(VersionProperties versionProperties, TagProperties tagProperties, NextVersionProperties nextVersionProperties) { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java index d62b3947..b05eb6fa 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java @@ -1,6 +1,8 @@ package pl.allegro.tech.build.axion.release.domain; import com.github.zafarkhaja.semver.Version; +import org.gradle.api.logging.Logger; +import org.gradle.api.logging.Logging; import pl.allegro.tech.build.axion.release.domain.scm.TaggedCommits; import pl.allegro.tech.build.axion.release.domain.scm.TagsOnCommit; @@ -21,6 +23,12 @@ * * any highest (stable or alpha) */ class VersionSorter { + private static final Logger logger = Logging.getLogger(VersionSorter.class); + private final boolean verbose; + + public VersionSorter(boolean verbose) { + this.verbose = verbose; + } Result pickTaggedCommit( TaggedCommits taggedCommits, @@ -32,9 +40,11 @@ Result pickTaggedCommit( Set versions = new LinkedHashSet<>(); LinkedHashMap isVersionNextVersion = new LinkedHashMap<>(); LinkedHashMap versionToCommit = new LinkedHashMap<>(); + boolean tagsFound = false; for (TagsOnCommit tagsEntry : taggedCommits.getCommits()) { List tags = tagsEntry.getTags(); + tagsFound = tagsFound || !tags.isEmpty(); // next version should be ignored when tag is on head // and there are other, normal tags on it @@ -47,10 +57,16 @@ Result pickTaggedCommit( for (String tag : tags) { boolean isNextVersion = nextVersionTagPattern.matcher(tag).matches(); if (isNextVersion && (ignoreNextVersionTags || ignoreNextVersionOnHead)) { + if (verbose) { + logger.info("Ignoring tag: {}, because it's a next version tag and it's not forced", tag); + } continue; } Version version = versionFactory.versionFromTag(tag); + if (verbose) { + logger.info("Detected version: {} from tag: {}", version, tag); + } boolean versionDidNotExist = versions.add(version); boolean isNormalVersion = !isNextVersion; // normal tags have precedence over nextVersion tags with same version @@ -68,14 +84,13 @@ Result pickTaggedCommit( } } + if (!tagsFound) { + logger.info("No tags were found in git history"); + } - - List versionList = new ArrayList<>(versions); - Collections.sort(versionList, Collections.reverseOrder()); - - Version version = (versionList.isEmpty() ? versionFactory.initialVersion() : versionList.get(0)); - if (version == null) { - version = versionFactory.initialVersion(); + Version version = findBestVersion(versionFactory, versions); + if (verbose) { + logger.info("Version: {}, was selected from versions: {}", version, versions); } TagsOnCommit versionCommit = versionToCommit.get(version); @@ -88,6 +103,17 @@ Result pickTaggedCommit( ); } + private static Version findBestVersion(VersionFactory versionFactory, Set versions) { + List versionList = new ArrayList<>(versions); + versionList.sort(Collections.reverseOrder()); + + if (versionList.isEmpty()) { + return versionFactory.initialVersion(); + } + Version version = versionList.get(0); + return version != null ? version : versionFactory.initialVersion(); + } + static class Result { final Version version; final boolean isNextVersion; diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java index a264aa65..7eedf530 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java @@ -20,6 +20,7 @@ public class ScmProperties { private final Set releaseBranchNames; private final boolean releaseOnlyOnReleaseBranches; private final boolean ignoreGlobalGitConfig; + private final boolean verbose; public ScmProperties( String type, @@ -35,7 +36,8 @@ public ScmProperties( Boolean unshallowRepoOnCI, Set releaseBranchNames, boolean releaseOnlyOnReleaseBranches, - boolean ignoreGlobalGitConfig + boolean ignoreGlobalGitConfig, + boolean verbose ) { this.type = type; this.directory = directory; @@ -51,6 +53,7 @@ public ScmProperties( this.releaseBranchNames = releaseBranchNames; this.releaseOnlyOnReleaseBranches = releaseOnlyOnReleaseBranches; this.ignoreGlobalGitConfig = ignoreGlobalGitConfig; + this.verbose = verbose; } public ScmPushOptions pushOptions() { @@ -112,4 +115,8 @@ public boolean isReleaseOnlyOnReleaseBranches() { public boolean isIgnoreGlobalGitConfig() { return ignoreGlobalGitConfig; } + + public boolean isVerbose() { + return verbose; + } } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy index 1652e9b0..5601151c 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy @@ -26,7 +26,7 @@ class VersionResolverMonoRepoTest extends RepositoryBasedTest { String secondaryDir = "subProjectSecondary" def setup() { - resolver = new VersionResolver(repository, subDir) + resolver = new VersionResolver(repository, subDir, false) commitPrimaryDir("init_file") } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy index e846f90e..38ed2ba0 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy @@ -30,7 +30,7 @@ class VersionResolverSubfolderTest extends RepositoryBasedTest { def setup() { this.projectRootSubfolder = "gradleProjectRoot" - resolver = new VersionResolver(repository, projectRootSubfolder) + resolver = new VersionResolver(repository, projectRootSubfolder, false) } def "should return default previous and current version when no tag in repository"() { diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy index b197e950..a663443d 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy @@ -21,7 +21,7 @@ class VersionResolverTest extends RepositoryBasedTest { VersionProperties defaultVersionRules = versionProperties().build() def setup() { - resolver = new VersionResolver(repository, "") + resolver = new VersionResolver(repository, "", false) } def "should return default previous and current version when no tag in repository"() { diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy index 7c97e555..7f4dc62d 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy @@ -21,7 +21,7 @@ import static pl.allegro.tech.build.axion.release.TagPrefixConf.fullPrefix */ class VersionSorterTest extends Specification { - private final VersionSorter sorter = new VersionSorter() + private final VersionSorter sorter = new VersionSorter(false) private final VersionFactory factory = new VersionFactory( VersionPropertiesBuilder.versionProperties().build(), diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy index 3e496d6b..8348b353 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy @@ -41,7 +41,8 @@ class ScmPropertiesBuilder { true, ['main', 'master'] as Set, false, - true + true, + false ) } From bfa18e2a8be3832e1e6186eac6df154c1fa3dbf1 Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Wed, 16 Oct 2024 16:55:34 +0200 Subject: [PATCH 2/9] fix doc --- docs/configuration/version.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/version.md b/docs/configuration/version.md index 3af59dac..fc97569a 100644 --- a/docs/configuration/version.md +++ b/docs/configuration/version.md @@ -427,6 +427,6 @@ property: } ## Troubleshooting -In case of problems use can try to use verbose mode: +In case of problems you can try to use verbose mode: #./gradlew release -Prelease.verbose From 0afbae0fd5f8edc507debf99f4a4c54d9637a2b0 Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Wed, 16 Oct 2024 17:05:47 +0200 Subject: [PATCH 3/9] change info level to quiet --- .../tech/build/axion/release/domain/VersionSorter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java index b05eb6fa..360870d6 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java @@ -58,14 +58,14 @@ Result pickTaggedCommit( boolean isNextVersion = nextVersionTagPattern.matcher(tag).matches(); if (isNextVersion && (ignoreNextVersionTags || ignoreNextVersionOnHead)) { if (verbose) { - logger.info("Ignoring tag: {}, because it's a next version tag and it's not forced", tag); + logger.quiet("Ignoring tag: {}, because it's a next version tag and it's not forced", tag); } continue; } Version version = versionFactory.versionFromTag(tag); if (verbose) { - logger.info("Detected version: {} from tag: {}", version, tag); + logger.quiet("Detected version: {} from tag: {}", version, tag); } boolean versionDidNotExist = versions.add(version); boolean isNormalVersion = !isNextVersion; @@ -85,12 +85,12 @@ Result pickTaggedCommit( } } if (!tagsFound) { - logger.info("No tags were found in git history"); + logger.quiet("No tags were found in git history"); } Version version = findBestVersion(versionFactory, versions); if (verbose) { - logger.info("Version: {}, was selected from versions: {}", version, versions); + logger.quiet("Version: {}, was selected from versions: {}", version, versions); } TagsOnCommit versionCommit = versionToCommit.get(version); From a3a084720b7559b4fca52dac96bfee4bb5cf65c0 Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Fri, 18 Oct 2024 08:12:49 +0200 Subject: [PATCH 4/9] use debug logging level instead of verbose flag --- docs/configuration/version.md | 5 ----- .../axion/release/domain/VersionConfig.groovy | 5 ----- .../config/ScmPropertiesFactory.groovy | 1 - .../di/VersionResolutionContext.groovy | 3 +-- .../axion/release/domain/VersionResolver.java | 4 ++-- .../axion/release/domain/VersionSorter.java | 18 ++++-------------- .../release/domain/scm/ScmProperties.java | 8 +------- .../domain/VersionResolverMonoRepoTest.groovy | 2 +- .../domain/VersionResolverSubfolderTest.groovy | 2 +- .../release/domain/VersionResolverTest.groovy | 2 +- .../release/domain/VersionSorterTest.groovy | 2 +- .../domain/scm/ScmPropertiesBuilder.groovy | 1 - 12 files changed, 12 insertions(+), 41 deletions(-) diff --git a/docs/configuration/version.md b/docs/configuration/version.md index fc97569a..9f524b90 100644 --- a/docs/configuration/version.md +++ b/docs/configuration/version.md @@ -425,8 +425,3 @@ property: scmVersion { sanitizeVersion.set(false) } - -## Troubleshooting -In case of problems you can try to use verbose mode: - - #./gradlew release -Prelease.verbose diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy index 9ff40f89..cf1d1282 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy @@ -36,12 +36,10 @@ abstract class VersionConfig extends BaseExtension { private static final String VERSION_CREATOR_PROPERTY = 'release.versionCreator' private static final String RELEASE_ONLY_ON_RELEASE_BRANCHES_PROPERTY = 'release.releaseOnlyOnReleaseBranches' private static final String RELEASE_BRANCH_NAMES_PROPERTY = 'release.releaseBranchNames' - private static final String RELEASE_VERBOSE = 'release.verbose' @Inject VersionConfig(Directory repositoryDirectory) { getDryRun().convention(gradlePropertyPresent(DRY_RUN_FLAG).orElse(false)) - getVerbose().convention(gradlePropertyPresent(RELEASE_VERBOSE).orElse(false)) getLocalOnly().convention(false) getIgnoreUncommittedChanges().convention(true) getUseHighestVersion().convention(false) @@ -83,9 +81,6 @@ abstract class VersionConfig extends BaseExtension { @Internal abstract Property getDryRun() - @Internal - abstract Property getVerbose() - @Internal abstract Property getIgnoreUncommittedChanges() diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy index fde6c8e1..4633da4e 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy @@ -21,7 +21,6 @@ class ScmPropertiesFactory { config.getReleaseBranchNames().get(), config.getReleaseOnlyOnReleaseBranches().get(), config.getIgnoreGlobalGitConfig().get(), - config.verbose.get() ) } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy index 9a33659e..a35c4506 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy @@ -35,8 +35,7 @@ class VersionResolutionContext { this.scmProperties = scmProperties this.localOnlyResolver = localOnlyResolver this.versionService = new VersionService(new VersionResolver(scmRepository, - scmProperties.directory.toPath().relativize(projectRoot.toPath()).toString(), - scmProperties.isVerbose())) + scmProperties.directory.toPath().relativize(projectRoot.toPath()).toString())) } static VersionResolutionContext create(VersionConfig versionConfig, Directory projectDirectory) { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java index b975f98c..742ae1b3 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java @@ -33,10 +33,10 @@ public class VersionResolver { */ private final String projectRootRelativePath; - public VersionResolver(ScmRepository repository, String projectRootRelativePath, boolean verbose) { + public VersionResolver(ScmRepository repository, String projectRootRelativePath) { this.repository = repository; this.projectRootRelativePath = projectRootRelativePath; - this.sorter = new VersionSorter(verbose); + this.sorter = new VersionSorter(); } public VersionContext resolveVersion(VersionProperties versionProperties, TagProperties tagProperties, NextVersionProperties nextVersionProperties) { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java index 360870d6..9308f4ef 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java @@ -24,11 +24,6 @@ */ class VersionSorter { private static final Logger logger = Logging.getLogger(VersionSorter.class); - private final boolean verbose; - - public VersionSorter(boolean verbose) { - this.verbose = verbose; - } Result pickTaggedCommit( TaggedCommits taggedCommits, @@ -57,16 +52,13 @@ Result pickTaggedCommit( for (String tag : tags) { boolean isNextVersion = nextVersionTagPattern.matcher(tag).matches(); if (isNextVersion && (ignoreNextVersionTags || ignoreNextVersionOnHead)) { - if (verbose) { - logger.quiet("Ignoring tag: {}, because it's a next version tag and it's not forced", tag); - } + logger.debug("Ignoring tag: {}, because it's a next version tag and it's not forced", tag); continue; } Version version = versionFactory.versionFromTag(tag); - if (verbose) { - logger.quiet("Detected version: {} from tag: {}", version, tag); - } + logger.debug("Detected version: {} from tag: {}", version, tag); + boolean versionDidNotExist = versions.add(version); boolean isNormalVersion = !isNextVersion; // normal tags have precedence over nextVersion tags with same version @@ -89,9 +81,7 @@ Result pickTaggedCommit( } Version version = findBestVersion(versionFactory, versions); - if (verbose) { - logger.quiet("Version: {}, was selected from versions: {}", version, versions); - } + logger.debug("Version: {}, was selected from versions: {}", version, versions); TagsOnCommit versionCommit = versionToCommit.get(version); diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java index 7eedf530..0d1cd801 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java @@ -20,7 +20,6 @@ public class ScmProperties { private final Set releaseBranchNames; private final boolean releaseOnlyOnReleaseBranches; private final boolean ignoreGlobalGitConfig; - private final boolean verbose; public ScmProperties( String type, @@ -36,8 +35,7 @@ public ScmProperties( Boolean unshallowRepoOnCI, Set releaseBranchNames, boolean releaseOnlyOnReleaseBranches, - boolean ignoreGlobalGitConfig, - boolean verbose + boolean ignoreGlobalGitConfig ) { this.type = type; this.directory = directory; @@ -53,7 +51,6 @@ public ScmProperties( this.releaseBranchNames = releaseBranchNames; this.releaseOnlyOnReleaseBranches = releaseOnlyOnReleaseBranches; this.ignoreGlobalGitConfig = ignoreGlobalGitConfig; - this.verbose = verbose; } public ScmPushOptions pushOptions() { @@ -116,7 +113,4 @@ public boolean isIgnoreGlobalGitConfig() { return ignoreGlobalGitConfig; } - public boolean isVerbose() { - return verbose; - } } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy index 5601151c..1652e9b0 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverMonoRepoTest.groovy @@ -26,7 +26,7 @@ class VersionResolverMonoRepoTest extends RepositoryBasedTest { String secondaryDir = "subProjectSecondary" def setup() { - resolver = new VersionResolver(repository, subDir, false) + resolver = new VersionResolver(repository, subDir) commitPrimaryDir("init_file") } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy index 38ed2ba0..e846f90e 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy @@ -30,7 +30,7 @@ class VersionResolverSubfolderTest extends RepositoryBasedTest { def setup() { this.projectRootSubfolder = "gradleProjectRoot" - resolver = new VersionResolver(repository, projectRootSubfolder, false) + resolver = new VersionResolver(repository, projectRootSubfolder) } def "should return default previous and current version when no tag in repository"() { diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy index a663443d..b197e950 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy @@ -21,7 +21,7 @@ class VersionResolverTest extends RepositoryBasedTest { VersionProperties defaultVersionRules = versionProperties().build() def setup() { - resolver = new VersionResolver(repository, "", false) + resolver = new VersionResolver(repository, "") } def "should return default previous and current version when no tag in repository"() { diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy index 7f4dc62d..7c97e555 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy @@ -21,7 +21,7 @@ import static pl.allegro.tech.build.axion.release.TagPrefixConf.fullPrefix */ class VersionSorterTest extends Specification { - private final VersionSorter sorter = new VersionSorter(false) + private final VersionSorter sorter = new VersionSorter() private final VersionFactory factory = new VersionFactory( VersionPropertiesBuilder.versionProperties().build(), diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy index 8348b353..a68d0798 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy @@ -42,7 +42,6 @@ class ScmPropertiesBuilder { ['main', 'master'] as Set, false, true, - false ) } From 9fb26669aac8d5b9b8d58e0d0c296176e4e6bb2e Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Fri, 18 Oct 2024 08:15:40 +0200 Subject: [PATCH 5/9] clean up unimportant changes --- .../release/infrastructure/config/ScmPropertiesFactory.groovy | 2 +- .../tech/build/axion/release/domain/scm/ScmProperties.java | 1 - .../build/axion/release/domain/scm/ScmPropertiesBuilder.groovy | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy index 4633da4e..8900f4cb 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy @@ -20,7 +20,7 @@ class ScmPropertiesFactory { config.getUnshallowRepoOnCI().get(), config.getReleaseBranchNames().get(), config.getReleaseOnlyOnReleaseBranches().get(), - config.getIgnoreGlobalGitConfig().get(), + config.getIgnoreGlobalGitConfig().get() ) } } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java index 0d1cd801..a264aa65 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmProperties.java @@ -112,5 +112,4 @@ public boolean isReleaseOnlyOnReleaseBranches() { public boolean isIgnoreGlobalGitConfig() { return ignoreGlobalGitConfig; } - } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy index a68d0798..4572bbf5 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPropertiesBuilder.groovy @@ -41,7 +41,7 @@ class ScmPropertiesBuilder { true, ['main', 'master'] as Set, false, - true, + true ) } From 5071c5cbc0d511dda14ccf166ebbd2d7d472495b Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Fri, 18 Oct 2024 08:52:54 +0200 Subject: [PATCH 6/9] clean up unimportant changes --- .../axion/release/domain/VersionSorter.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java index 9308f4ef..25005744 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java @@ -80,7 +80,14 @@ Result pickTaggedCommit( logger.quiet("No tags were found in git history"); } - Version version = findBestVersion(versionFactory, versions); + List versionList = new ArrayList<>(versions); + Collections.sort(versionList, Collections.reverseOrder()); + + Version version = (versionList.isEmpty() ? versionFactory.initialVersion() : versionList.get(0)); + if (version == null) { + version = versionFactory.initialVersion(); + } + logger.debug("Version: {}, was selected from versions: {}", version, versions); TagsOnCommit versionCommit = versionToCommit.get(version); @@ -93,17 +100,6 @@ Result pickTaggedCommit( ); } - private static Version findBestVersion(VersionFactory versionFactory, Set versions) { - List versionList = new ArrayList<>(versions); - versionList.sort(Collections.reverseOrder()); - - if (versionList.isEmpty()) { - return versionFactory.initialVersion(); - } - Version version = versionList.get(0); - return version != null ? version : versionFactory.initialVersion(); - } - static class Result { final Version version; final boolean isNextVersion; From 2d8726d6de6c73e2d77927e7ce3b6b4a42bfb045 Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Fri, 18 Oct 2024 09:04:21 +0200 Subject: [PATCH 7/9] refactor finding latest version --- .../axion/release/domain/VersionSorter.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java index 25005744..7e01c96d 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java @@ -80,14 +80,7 @@ Result pickTaggedCommit( logger.quiet("No tags were found in git history"); } - List versionList = new ArrayList<>(versions); - Collections.sort(versionList, Collections.reverseOrder()); - - Version version = (versionList.isEmpty() ? versionFactory.initialVersion() : versionList.get(0)); - if (version == null) { - version = versionFactory.initialVersion(); - } - + Version version = getLatestVersion(versionFactory, versions); logger.debug("Version: {}, was selected from versions: {}", version, versions); TagsOnCommit versionCommit = versionToCommit.get(version); @@ -100,6 +93,13 @@ Result pickTaggedCommit( ); } + private static Version getLatestVersion(VersionFactory versionFactory, Set versions) { + return versions.stream() + .filter(Objects::nonNull) // filter out nulls + .max(Comparator.naturalOrder()) // find latest version + .orElseGet(versionFactory::initialVersion); // if no versions found, return initial version + } + static class Result { final Version version; final boolean isNextVersion; From c4ba1481d0404801e1e5f7f2e3bb5ad55ea5dc4a Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Fri, 18 Oct 2024 12:52:45 +0200 Subject: [PATCH 8/9] after refactor inline logic of finding version number --- .../build/axion/release/domain/VersionSorter.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java index 7e01c96d..7f25773f 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java @@ -80,7 +80,10 @@ Result pickTaggedCommit( logger.quiet("No tags were found in git history"); } - Version version = getLatestVersion(versionFactory, versions); + Version version = versions.stream() + .filter(Objects::nonNull) + .max(Comparator.naturalOrder()) // find latest (max) version + .orElseGet(versionFactory::initialVersion); // if no versions found, use initial version logger.debug("Version: {}, was selected from versions: {}", version, versions); TagsOnCommit versionCommit = versionToCommit.get(version); @@ -93,13 +96,6 @@ Result pickTaggedCommit( ); } - private static Version getLatestVersion(VersionFactory versionFactory, Set versions) { - return versions.stream() - .filter(Objects::nonNull) // filter out nulls - .max(Comparator.naturalOrder()) // find latest version - .orElseGet(versionFactory::initialVersion); // if no versions found, return initial version - } - static class Result { final Version version; final boolean isNextVersion; From 621bb854918758853c030e3d087079b5114987a4 Mon Sep 17 00:00:00 2001 From: "tomasz.pankowski" Date: Wed, 6 Nov 2024 16:38:28 +0100 Subject: [PATCH 9/9] lifecycle is the default logging level, use it instead of debug --- .../tech/build/axion/release/domain/VersionSorter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java index 7f25773f..1513082c 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionSorter.java @@ -52,12 +52,12 @@ Result pickTaggedCommit( for (String tag : tags) { boolean isNextVersion = nextVersionTagPattern.matcher(tag).matches(); if (isNextVersion && (ignoreNextVersionTags || ignoreNextVersionOnHead)) { - logger.debug("Ignoring tag: {}, because it's a next version tag and it's not forced", tag); + logger.lifecycle("Ignoring tag: {}, because it's a next version tag and it's not forced", tag); continue; } Version version = versionFactory.versionFromTag(tag); - logger.debug("Detected version: {} from tag: {}", version, tag); + logger.lifecycle("Detected version: {} from tag: {}", version, tag); boolean versionDidNotExist = versions.add(version); boolean isNormalVersion = !isNextVersion; @@ -77,14 +77,14 @@ Result pickTaggedCommit( } } if (!tagsFound) { - logger.quiet("No tags were found in git history"); + logger.lifecycle("No tags were found in git history"); } Version version = versions.stream() .filter(Objects::nonNull) .max(Comparator.naturalOrder()) // find latest (max) version .orElseGet(versionFactory::initialVersion); // if no versions found, use initial version - logger.debug("Version: {}, was selected from versions: {}", version, versions); + logger.lifecycle("Version: {}, was selected from versions: {}", version, versions); TagsOnCommit versionCommit = versionToCommit.get(version);