Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version logic when bumping major version #38593

Merged
merged 2 commits into from
Feb 8, 2019
Merged
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 @@ -218,7 +218,14 @@ private String getGradleProjectNameFor(Version version) {
private String getBranchFor(Version version) {
switch (getGradleProjectNameFor(version)) {
case "minor":
return version.getMajor() + ".x";
// The .x branch will always point to the latest minor (for that major), so a "minor" project will be on the .x branch
// unless there is more recent (higher) minor.
final Version latestInMajor = getLatestVersionByKey(groupByMajor, version.getMajor());
if (latestInMajor.getMinor() == version.getMinor()) {
return version.getMajor() + ".x";
} else {
return version.getMajor() + "." + version.getMinor();
}
case "staged":
case "maintenance":
case "bugfix":
Expand All @@ -234,7 +241,15 @@ public List<Version> getUnreleased() {
unreleased.add(currentVersion);

// the tip of the previous major is unreleased for sure, be it a minor or a bugfix
unreleased.add(getLatestVersionByKey(this.groupByMajor, currentVersion.getMajor() - 1));
final Version latestOfPreviousMajor = getLatestVersionByKey(this.groupByMajor, currentVersion.getMajor() - 1);
unreleased.add(latestOfPreviousMajor);
if (latestOfPreviousMajor.getRevision() == 0) {
// if the previous major is a x.y.0 release, then the tip of the minor before that (y-1) is also unreleased
final Version previousMinor = getLatestInMinor(latestOfPreviousMajor.getMajor(), latestOfPreviousMajor.getMinor() - 1);
if (previousMinor != null) {
unreleased.add(previousMinor);
}
}

final Map<Integer, List<Version>> groupByMinor = getReleasedMajorGroupedByMinor();
int greatestMinor = groupByMinor.keySet().stream().max(Integer::compareTo).orElse(0);
Expand Down Expand Up @@ -262,6 +277,13 @@ public List<Version> getUnreleased() {
);
}

private Version getLatestInMinor(int major, int minor) {
return groupByMajor.get(major).stream()
.filter(v -> v.getMinor() == minor)
.max(Version::compareTo)
.orElse(null);
}

private Version getLatestVersionByKey(Map<Integer, List<Version>> groupByMajor, int key) {
return groupByMajor.getOrDefault(key, emptyList()).stream()
.max(Version::compareTo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ public void testGetUnreleased() {
asList("7.1.1", "7.2.0", "7.3.0", "8.0.0"),
getVersionCollection("8.0.0").getUnreleased()
);
assertVersionsEquals(
asList("6.6.1", "6.7.0", "7.0.0", "7.1.0"),
getVersionCollection("7.1.0").getUnreleased()
);
}

public void testGetBranch() {
Expand All @@ -298,13 +302,17 @@ public void testGetBranch() {
getVersionCollection("6.4.2")
);
assertUnreleasedBranchNames(
asList("5.6", "6.4", "6.x"),
asList("5.6", "6.4", "6.5"),
getVersionCollection("6.6.0")
);
assertUnreleasedBranchNames(
asList("7.1", "7.2", "7.x"),
getVersionCollection("8.0.0")
);
assertUnreleasedBranchNames(
asList("6.6", "6.7", "7.0"),
getVersionCollection("7.1.0")
);
}

public void testGetGradleProjectName() {
Expand All @@ -329,7 +337,7 @@ public void testGetGradleProjectName() {
getVersionCollection("8.0.0")
);
assertUnreleasedGradleProjectNames(
asList("staged", "minor"),
asList("maintenance", "staged", "minor"),
getVersionCollection("7.1.0")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class VersionUtils {
* rules here match up with the rules in gradle then this should
* produce sensible results.
* @return a tuple containing versions with backwards compatibility
* guarantees in v1 and versions without the guranteees in v2
* guarantees in v1 and versions without the guarantees in v2
*/
static Tuple<List<Version>, List<Version>> resolveReleasedVersions(Version current, Class<?> versionClass) {
// group versions into major version
Expand All @@ -67,7 +67,11 @@ static Tuple<List<Version>, List<Version>> resolveReleasedVersions(Version curre
// on a stable or release branch, ie N.x
stableVersions = currentMajor;
// remove the next maintenance bugfix
moveLastToUnreleased(previousMajor, unreleasedVersions);
final Version prevMajorLastMinor = moveLastToUnreleased(previousMajor, unreleasedVersions);
if (prevMajorLastMinor.revision == 0 && previousMajor.isEmpty() == false) {
// The latest minor in the previous major is a ".0" release, so there must be an unreleased bugfix for the minor before that
moveLastToUnreleased(previousMajor, unreleasedVersions);
}
}

// remove next minor
Expand Down