Skip to content

Commit

Permalink
Merge pull request #393 from allegro/incrementMinorIfNotOnRelease_fix
Browse files Browse the repository at this point in the history
legacy tag prefiex preserved in incrementMinorIfNotOnRelease #391
  • Loading branch information
bgalek authored Mar 31, 2021
2 parents d234427 + 8631ef1 commit b02d6ba
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NextVersionMarker {
nextVersion = nextVersionRules.nextVersion
} else {
Version currentVersion = Version.valueOf(versionConfig.undecoratedVersion)
VersionIncrementerContext context = new VersionIncrementerContext(currentVersion, repositoryService.position())
VersionIncrementerContext context = new VersionIncrementerContext(currentVersion, repositoryService.position(), repositoryService.isLegacyDefTagnameRepo())
nextVersion = nextVersionRules.versionIncrementer ?
PredefinedVersionIncrementer.versionIncrementerFor(nextVersionRules.versionIncrementer)(context) :
versionConfig.versionIncrementer(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.zafarkhaja.semver.Version
import pl.allegro.tech.build.axion.release.TagPrefixConf

import java.util.regex.Matcher

import static java.lang.String.format

enum PredefinedVersionIncrementer {
Expand All @@ -21,10 +22,10 @@ enum PredefinedVersionIncrementer {
}),

INCREMENT_MINOR_IF_NOT_ON_RELEASE_BRANCH('incrementMinorIfNotOnRelease', { VersionIncrementerContext context, Map config ->
if(!config.releaseBranchPattern) {
config.releaseBranchPattern = TagPrefixConf.prefix()+ '/.+'
if (!config.releaseBranchPattern) {
config.releaseBranchPattern = context.isLegacyDefTagnameRepo() ? TagPrefixConf.DEFAULT_LEGACY_PREFIX + '/.+' : TagPrefixConf.prefix() + '/.+'
}
if(context.scmPosition.branch ==~ config.releaseBranchPattern) {
if (context.scmPosition.branch ==~ config.releaseBranchPattern) {
return context.currentVersion.incrementPatchVersion()
}
return context.currentVersion.incrementMinorVersion()
Expand All @@ -45,7 +46,7 @@ enum PredefinedVersionIncrementer {
}
}

if (config.initialPreReleaseIfNotOnPrerelease != null) {
if (config.initialPreReleaseIfNotOnPrerelease != null) {
return context.currentVersion.incrementPatchVersion(String.valueOf(config.initialPreReleaseIfNotOnPrerelease))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@ public class VersionFactory {
private final TagProperties tagProperties;
private final NextVersionProperties nextVersionProperties;
private final ScmPosition position;
private final boolean isLegacyDefTagnameRepo;

public VersionFactory(
VersionProperties versionProperties,
TagProperties tagProperties,
NextVersionProperties nextVersionProperties,
ScmPosition position
ScmPosition position,
boolean isLegacyDefTagnameRepo
) {
this.tagProperties = tagProperties;
this.nextVersionProperties = nextVersionProperties;
this.versionProperties = versionProperties;
this.position = position;
this.isLegacyDefTagnameRepo = isLegacyDefTagnameRepo;
}

public VersionFactory(
VersionProperties versionProperties,
TagProperties tagProperties,
NextVersionProperties nextVersionProperties,
ScmPosition position
) {
this(versionProperties, tagProperties, nextVersionProperties, position, false);
}

public Version versionFromTag(String tag) {
Expand Down Expand Up @@ -65,9 +77,7 @@ public FinalVersion createFinalVersion(ScmState scmState, Version version) {
if (StringGroovyMethods.asBoolean(versionProperties.getForcedVersion())) {
finalVersion = Version.valueOf(versionProperties.getForcedVersion());
} else if (incrementVersion) {
finalVersion = versionProperties.getVersionIncrementer().call(new VersionIncrementerContext(
version, position
));
finalVersion = versionProperties.getVersionIncrementer().call(new VersionIncrementerContext(version, position, isLegacyDefTagnameRepo));
}

return new FinalVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ public class VersionIncrementerContext {

private final Version currentVersion;
private final ScmPosition scmPosition;
private final boolean isLegacyDefTagnameRepo;

public VersionIncrementerContext(Version currentVersion, ScmPosition scmPosition) {
public VersionIncrementerContext(Version currentVersion, ScmPosition scmPosition, boolean isLegacyDefTagnameRepo) {
this.currentVersion = currentVersion;
this.scmPosition = scmPosition;
this.isLegacyDefTagnameRepo = isLegacyDefTagnameRepo;
}

public VersionIncrementerContext(Version currentVersion, ScmPosition scmPosition) {
this(currentVersion, scmPosition, false);
}

public Version getCurrentVersion() {
Expand All @@ -20,4 +26,8 @@ public Version getCurrentVersion() {
public ScmPosition getScmPosition() {
return scmPosition;
}

public boolean isLegacyDefTagnameRepo() {
return isLegacyDefTagnameRepo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public VersionContext resolveVersion(VersionProperties versionProperties, TagPro
projectRootRelativePath, versionProperties.getMonorepoProperties().getDirsToExclude()
);

VersionFactory versionFactory = new VersionFactory(versionProperties, tagProperties, nextVersionProperties, latestChangePosition);
VersionFactory versionFactory = new VersionFactory(versionProperties, tagProperties, nextVersionProperties, latestChangePosition, repository.isLegacyDefTagnameRepo());

VersionInfo versions;
if (versionProperties.isUseHighestVersion()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public boolean remoteAttached() {
public List<String> lastLogMessages(int messageCount) {
return repository.lastLogMessages(messageCount);
}

public boolean isLegacyDefTagnameRepo() {
return repository.isLegacyDefTagnameRepo();
}
}

0 comments on commit b02d6ba

Please sign in to comment.