Skip to content

Commit a71a15a

Browse files
committed
Build: Move verifyVersions to new branchConsistency task (#25009)
This commit adds a new `branchConsistency` task which will run in CI once a day, instead of on every commit. This allows `verifyVersions` to not break immediately once a new version is released in maven.
1 parent b7af19f commit a71a15a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

build.gradle

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ for (String line : versionLines) {
7676
int minor = Integer.parseInt(match.group(2))
7777
int bugfix = Integer.parseInt(match.group(3))
7878
boolean unreleased = match.group(4) != null
79-
Version foundVersion = new Version(major, minor, bugfix, false, unreleased)
79+
Version foundVersion = new Version(major, minor, bugfix, unreleased, unreleased)
8080
if (currentVersion != foundVersion) {
8181
versions.add(foundVersion)
8282
}
@@ -112,6 +112,41 @@ allprojects {
112112
}
113113
}
114114

115+
task verifyVersions {
116+
doLast {
117+
if (gradle.startParameter.isOffline()) {
118+
throw new GradleException("Must run in online mode to verify versions")
119+
}
120+
// Read the list from maven central
121+
Node xml
122+
new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s ->
123+
xml = new XmlParser().parse(s)
124+
}
125+
Set<Version> knownVersions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /\d\.\d\.\d/ }.collect { Version.fromString(it) })
126+
127+
// Limit the known versions to those that should be index compatible, and are not future versions
128+
knownVersions = knownVersions.findAll { it.major >= 2 && it.before(VersionProperties.elasticsearch) }
129+
130+
/* Limit the listed versions to those that have been marked as released.
131+
* Versions not marked as released don't get the same testing and we want
132+
* to make sure that we flip all unreleased versions to released as soon
133+
* as possible after release. */
134+
Set<Version> actualVersions = new TreeSet<>(indexCompatVersions.findAll { false == it.snapshot })
135+
136+
// Finally, compare!
137+
if (knownVersions.equals(actualVersions) == false) {
138+
throw new GradleException("out-of-date released versions\nActual :" + actualVersions + "\nExpected:" + knownVersions +
139+
"\nUpdate Version.java. Note that Version.CURRENT doesn't count because it is not released.")
140+
}
141+
}
142+
}
143+
144+
task branchConsistency {
145+
description 'Ensures this branch is internally consistent. For example, that versions constants match released versions.'
146+
group 'Verification'
147+
dependsOn verifyVersions
148+
}
149+
115150
subprojects {
116151
project.afterEvaluate {
117152
// include license and notice in jars

buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
package org.elasticsearch.gradle
2121

22+
import groovy.transform.Sortable
23+
2224
/**
2325
* Encapsulates comparison and printing logic for an x.y.z version.
2426
*/
27+
@Sortable
2528
public class Version {
2629

2730
final int major

0 commit comments

Comments
 (0)