2017-03-24 01:32:13 -04:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2017-05-24 11:55:32 -04:00
|
|
|
|
2017-03-24 01:32:13 -04:00
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
|
|
|
|
|
|
|
/**
|
2017-05-17 15:58:37 -04:00
|
|
|
* This is a dummy project which does a local checkout of the previous
|
|
|
|
* wire compat version's branch, and builds a snapshot. This allows backcompat
|
|
|
|
* tests to test against the next unreleased version, closest to this version,
|
|
|
|
* without relying on snapshots.
|
2017-03-24 01:32:13 -04:00
|
|
|
*/
|
2017-05-29 10:22:32 -04:00
|
|
|
String bwcVersion
|
|
|
|
boolean enabled = true
|
|
|
|
if (project.name == 'bwc-stable-snapshot') {
|
|
|
|
/* bwc-stable is only used if the last version is on a stable branch instead
|
|
|
|
* of a bugfix branch */
|
|
|
|
enabled = indexCompatVersions[-1].bugfix == 0
|
|
|
|
bwcVersion = indexCompatVersions[-1]
|
|
|
|
} else if (project.name == 'bwc-release-snapshot') {
|
|
|
|
if (indexCompatVersions[-1].bugfix == 0) {
|
|
|
|
/* The last version is on a stable branch so it is handled by the bwc-stable
|
|
|
|
* project. This project will instead handle the version before that which
|
|
|
|
* *should* be on a stable branch. */
|
|
|
|
bwcVersion = indexCompatVersions[-2]
|
|
|
|
} else {
|
|
|
|
// The last version is on a release branch so it is handled by this project
|
|
|
|
bwcVersion = indexCompatVersions[-1]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new InvalidUserDataException("Unsupport project name ${project.name}")
|
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-05-29 10:22:32 -04:00
|
|
|
if (enabled) {
|
2017-05-17 15:58:37 -04:00
|
|
|
apply plugin: 'distribution'
|
2017-06-16 17:16:03 -04:00
|
|
|
// Not published so no need to assemble
|
|
|
|
tasks.remove(assemble)
|
|
|
|
build.dependsOn.remove('assemble')
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
def (String major, String minor, String bugfix) = bwcVersion.split('\\.')
|
2017-06-08 12:56:47 -04:00
|
|
|
def (String currentMajor, String currentMinor, String currentBugfix) = version.split('\\.')
|
|
|
|
String bwcBranch
|
2017-11-01 15:21:18 -04:00
|
|
|
if (project.name == 'bwc-stable-snapshot' && major != currentMajor) {
|
2017-06-08 12:56:47 -04:00
|
|
|
bwcBranch = "${major}.x"
|
|
|
|
} else {
|
|
|
|
bwcBranch = "${major}.${minor}"
|
|
|
|
}
|
2017-05-17 15:58:37 -04:00
|
|
|
File checkoutDir = file("${buildDir}/bwc/checkout-${bwcBranch}")
|
2017-05-29 10:22:32 -04:00
|
|
|
|
2017-10-07 13:40:18 -04:00
|
|
|
final String remote = System.getProperty("tests.bwc.remote", "elastic")
|
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
task createClone(type: LoggedExec) {
|
|
|
|
onlyIf { checkoutDir.exists() == false }
|
|
|
|
commandLine = ['git', 'clone', rootDir, checkoutDir]
|
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-10-07 13:40:18 -04:00
|
|
|
task findRemote(type: LoggedExec) {
|
2017-05-17 15:58:37 -04:00
|
|
|
dependsOn createClone
|
|
|
|
workingDir = checkoutDir
|
|
|
|
commandLine = ['git', 'remote', '-v']
|
2017-11-08 15:27:15 -05:00
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
|
|
standardOutput = output
|
2017-05-17 15:58:37 -04:00
|
|
|
doLast {
|
2017-10-07 13:40:18 -04:00
|
|
|
project.ext.remoteExists = false
|
2017-05-17 15:58:37 -04:00
|
|
|
output.toString('UTF-8').eachLine {
|
2017-10-07 13:40:18 -04:00
|
|
|
if (it.contains("${remote}\thttps://github.com/${remote}/elasticsearch.git")) {
|
|
|
|
project.ext.remoteExists = true
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 13:40:18 -04:00
|
|
|
task addRemote(type: LoggedExec) {
|
|
|
|
dependsOn findRemote
|
|
|
|
onlyIf { project.ext.remoteExists == false }
|
2017-05-17 15:58:37 -04:00
|
|
|
workingDir = checkoutDir
|
2017-10-07 13:40:18 -04:00
|
|
|
commandLine = ['git', 'remote', 'add', "${remote}", "https://github.com/${remote}/elasticsearch.git"]
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
task fetchLatest(type: LoggedExec) {
|
|
|
|
onlyIf { project.gradle.startParameter.isOffline() == false }
|
2017-10-07 13:40:18 -04:00
|
|
|
dependsOn addRemote
|
2017-05-17 15:58:37 -04:00
|
|
|
workingDir = checkoutDir
|
2017-07-07 07:39:24 -04:00
|
|
|
commandLine = ['git', 'fetch', '--all']
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-08-28 17:10:06 -04:00
|
|
|
String buildMetadataKey = "bwc_refspec_${project.path.substring(1)}"
|
2017-08-30 14:01:17 -04:00
|
|
|
task checkoutBwcBranch(type: LoggedExec) {
|
2017-10-07 13:40:18 -04:00
|
|
|
String refspec = System.getProperty("tests.bwc.refspec", buildMetadata.get(buildMetadataKey, "${remote}/${bwcBranch}"))
|
2017-05-17 15:58:37 -04:00
|
|
|
dependsOn fetchLatest
|
|
|
|
workingDir = checkoutDir
|
2017-07-07 05:18:03 -04:00
|
|
|
commandLine = ['git', 'checkout', refspec]
|
2017-08-30 14:01:17 -04:00
|
|
|
doFirst {
|
|
|
|
println "Checking out elasticsearch ${refspec} for branch ${bwcBranch}"
|
|
|
|
}
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-08-28 17:10:06 -04:00
|
|
|
File buildMetadataFile = project.file("build/${project.name}/build_metadata")
|
|
|
|
task writeBuildMetadata(type: LoggedExec) {
|
|
|
|
dependsOn checkoutBwcBranch
|
|
|
|
workingDir = checkoutDir
|
|
|
|
commandLine = ['git', 'rev-parse', 'HEAD']
|
|
|
|
ignoreExitValue = true
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
|
|
standardOutput = output
|
|
|
|
doLast {
|
|
|
|
if (execResult.exitValue != 0) {
|
|
|
|
output.toString('UTF-8').eachLine { line -> logger.error(line) }
|
|
|
|
execResult.assertNormalExitValue()
|
|
|
|
}
|
|
|
|
project.mkdir(buildMetadataFile.parent)
|
2017-08-30 14:01:17 -04:00
|
|
|
String commit = output.toString('UTF-8')
|
|
|
|
buildMetadataFile.setText("${buildMetadataKey}=${commit}", 'UTF-8')
|
|
|
|
println "Checked out elasticsearch commit ${commit}"
|
2017-08-28 17:10:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 13:55:32 -04:00
|
|
|
File bwcDeb = file("${checkoutDir}/distribution/deb/build/distributions/elasticsearch-${bwcVersion}.deb")
|
|
|
|
File bwcRpm = file("${checkoutDir}/distribution/rpm/build/distributions/elasticsearch-${bwcVersion}.rpm")
|
2017-05-17 15:58:37 -04:00
|
|
|
File bwcZip = file("${checkoutDir}/distribution/zip/build/distributions/elasticsearch-${bwcVersion}.zip")
|
|
|
|
task buildBwcVersion(type: GradleBuild) {
|
2017-08-28 17:10:06 -04:00
|
|
|
dependsOn checkoutBwcBranch, writeBuildMetadata
|
2017-05-17 15:58:37 -04:00
|
|
|
dir = checkoutDir
|
2017-05-24 11:55:32 -04:00
|
|
|
tasks = [':distribution:deb:assemble', ':distribution:rpm:assemble', ':distribution:zip:assemble']
|
2017-09-19 20:41:51 -04:00
|
|
|
startParameter.systemPropertiesArgs = ['build.snapshot': 'true']
|
2017-08-10 14:30:00 -04:00
|
|
|
doLast {
|
|
|
|
List missing = [bwcDeb, bwcRpm, bwcZip].grep { file ->
|
|
|
|
false == file.exists() }
|
|
|
|
if (false == missing.empty) {
|
|
|
|
throw new InvalidUserDataException(
|
|
|
|
"Building bwc version didn't generate expected files ${missing}")
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
artifacts {
|
2017-05-24 11:55:32 -04:00
|
|
|
'default' file: bwcDeb, name: 'elasticsearch', type: 'deb', builtBy: buildBwcVersion
|
|
|
|
'default' file: bwcRpm, name: 'elasticsearch', type: 'rpm', builtBy: buildBwcVersion
|
2017-05-17 15:58:37 -04:00
|
|
|
'default' file: bwcZip, name: 'elasticsearch', type: 'zip', builtBy: buildBwcVersion
|
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
}
|