Skip to content

Commit

Permalink
Generalize BWC logic (#28505)
Browse files Browse the repository at this point in the history
Generalizing BWC building so that there is less code to modify for a release. This ensures we do not
need to think about what major or minor version is in the gradle code. It follows the general rules of the
elastic release structure. For more information on the rules, see the VersionCollection's javadoc.

This also removes the additional bwc snapshots that will never be released, such as 6.0.2, which were
being built and tested against every time we ran bwc tests.

Additionally, it creates 4 new projects that correspond to the different types of snapshots that may exist
for a given version. Its possible to now run those individual tasks to work out bwc logic whereas
previously it was impossible and the entire suite of bwc tests had to be run to work out any logic
changes in the build tools' bwc project. Please note that if the project does not make sense for the 
version that is current, that an error will be thrown from that individual project if an attempt is made to 
run it.

This should allow for automating the version bumps as well, since it removes all the hardcoded version
logic from the configs.
  • Loading branch information
hub-cap authored Feb 9, 2018
1 parent 20c37ef commit e0bea70
Show file tree
Hide file tree
Showing 20 changed files with 635 additions and 245 deletions.
21 changes: 11 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ allprojects {
isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')

// for BWC testing
versionCollection = versions
bwcVersions = versions

buildMetadata = buildMetadataMap
}
Expand All @@ -122,13 +122,13 @@ task verifyVersions {
Set<Version> knownVersions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /\d\.\d\.\d/ }.collect { Version.fromString(it) })

// Limit the known versions to those that should be index compatible, and are not future versions
knownVersions = knownVersions.findAll { it.major >= versions.currentVersion.major - 1 && it.before(VersionProperties.elasticsearch) }
knownVersions = knownVersions.findAll { it.major >= bwcVersions.currentVersion.major - 1 && it.before(VersionProperties.elasticsearch) }

/* Limit the listed versions to those that have been marked as released.
* Versions not marked as released don't get the same testing and we want
* to make sure that we flip all unreleased versions to released as soon
* as possible after release. */
Set<Version> actualVersions = new TreeSet<>(versions.versionsIndexCompatibleWithCurrent.findAll { false == it.snapshot })
Set<Version> actualVersions = new TreeSet<>(bwcVersions.indexCompatible.findAll { false == it.snapshot })

// Finally, compare!
if (knownVersions.equals(actualVersions) == false) {
Expand Down Expand Up @@ -219,13 +219,14 @@ subprojects {
"org.elasticsearch.plugin:rank-eval-client:${version}": ':modules:rank-eval',
]

for (final Version version : versionCollection.versionsIndexCompatibleWithCurrent) {
if (version.branch != null) {
final String snapshotProject = ":distribution:bwc-snapshot-${version.branch}"
project(snapshotProject).ext.bwcVersion = version
ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${version}"] = snapshotProject
ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${version}"] = snapshotProject
ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${version}"] = snapshotProject
bwcVersions.snapshotProjectNames.each { snapshotName ->
Version snapshot = bwcVersions.getSnapshotForProject(snapshotName)
if (snapshot != null ) {
String snapshotProject = ":distribution:bwc:${snapshotName}"
project(snapshotProject).ext.bwcVersion = snapshot
ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${snapshot}"] = snapshotProject
ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${snapshot}"] = snapshotProject
ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${snapshot}"] = snapshotProject
}
}

Expand Down
23 changes: 14 additions & 9 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,29 @@ public class Version {
final int revision
final int id
final boolean snapshot
final String branch
/**
* Suffix on the version name. Unlike Version.java the build does not
* consider alphas and betas different versions, it just preserves the
* suffix that the version was declared with in Version.java.
* Suffix on the version name.
*/
final String suffix

public Version(int major, int minor, int revision,
String suffix, boolean snapshot, String branch) {
String suffix, boolean snapshot) {
this.major = major
this.minor = minor
this.revision = revision
this.snapshot = snapshot
this.suffix = suffix
this.branch = branch
this.id = major * 100000 + minor * 1000 + revision * 10 +
(snapshot ? 1 : 0)

int suffixOffset = 0
if (suffix.contains("alpha")) {
suffixOffset += Integer.parseInt(suffix.substring(6))
} else if (suffix.contains("beta")) {
suffixOffset += 25 + Integer.parseInt(suffix.substring(5))
} else if (suffix.contains("rc")) {
suffixOffset += 50 + Integer.parseInt(suffix.substring(3));
}

this.id = major * 1000000 + minor * 10000 + revision * 100 + suffixOffset
}

public static Version fromString(String s) {
Expand All @@ -60,7 +65,7 @@ public class Version {
throw new InvalidUserDataException("Invalid version [${s}]")
}
return new Version(m.group(1) as int, m.group(2) as int,
m.group(3) as int, m.group(4) ?: '', m.group(5) != null, null)
m.group(3) as int, m.group(4) ?: '', m.group(5) != null)
}

@Override
Expand Down
Loading

0 comments on commit e0bea70

Please sign in to comment.