Skip to content

Commit d6d830f

Browse files
authored
Fix logic detecting unreleased versions
When partitioning version constants into released and unreleased versions, today we have a bug in finding the last unreleased version. Namely, consider the following version constants on the 6.x branch: ..., 5.6.3, 5.6.4, 6.0.0-alpha1, ..., 6.0.0-rc1, 6.0.0-rc2, 6.0.0, 6.1.0. In this case, our convention dictates that: 5.6.4, 6.0.0, and 6.1.0 are unreleased. Today we correctly detect that 6.0.0 and 6.1.0 are unreleased, and then we say the previous patch version is unreleased too. The problem is the logic to remove that previous patch version is broken, it does not skip alphas/betas/RCs which have been released. This commit fixes this by skipping backwards over pre-release versions when finding the previous patch version to remove. Relates elastic#27206
1 parent 99aca9c commit d6d830f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

test/framework/src/main/java/org/elasticsearch/test/VersionUtils.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,17 @@ static Tuple<List<Version>, List<Version>> resolveReleasedVersions(Version curre
100100

101101
Version unreleased = versions.remove(unreleasedIndex);
102102
if (unreleased.revision == 0) {
103-
/* If the last unreleased version is itself a patch release then gradle enforces
104-
* that there is yet another unreleased version before that. */
105-
unreleasedIndex--;
103+
/*
104+
* If the last unreleased version is itself a patch release then Gradle enforces that there is yet another unreleased version
105+
* before that. However, we have to skip alpha/betas/RCs too (e.g., consider when the version constants are ..., 5.6.3, 5.6.4,
106+
* 6.0.0-alpha1, ..., 6.0.0-rc1, 6.0.0-rc2, 6.0.0, 6.1.0 on the 6.x branch. In this case, we will have pruned 6.0.0 and 6.1.0 as
107+
* unreleased versions, but we also need to prune 5.6.4. At this point though, unreleasedIndex will be pointing to 6.0.0-rc2, so
108+
* we have to skip backwards until we find a non-alpha/beta/RC again. Then we can prune that version as an unreleased version
109+
* too.
110+
*/
111+
do {
112+
unreleasedIndex--;
113+
} while (versions.get(unreleasedIndex).isRelease() == false);
106114
Version earlierUnreleased = versions.remove(unreleasedIndex);
107115
return new Tuple<>(unmodifiableList(versions), unmodifiableList(Arrays.asList(earlierUnreleased, unreleased, current)));
108116
}

0 commit comments

Comments
 (0)