mirror of
https://github.com/elastic/logstash.git
synced 2025-04-19 04:15:23 -04:00
gradle task migrate to the new artifacts-api (#17232)
This commit migrates gradle task to the new artifacts-api - remove dependency on staging artifacts - all builds use snapshot artifacts - resolve version from current branch, major.x, previous minor, with priority given in that order. Co-authored-by: Andrea Selva <selva.andre@gmail.com>
This commit is contained in:
parent
7d1458fad3
commit
0a745686f6
1 changed files with 30 additions and 65 deletions
95
build.gradle
95
build.gradle
|
@ -146,7 +146,6 @@ subprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
version = versionMap['logstash-core']
|
version = versionMap['logstash-core']
|
||||||
String artifactVersionsApi = "https://artifacts-api.elastic.co/v1/versions"
|
|
||||||
|
|
||||||
tasks.register("configureArchitecture") {
|
tasks.register("configureArchitecture") {
|
||||||
String arch = System.properties['os.arch']
|
String arch = System.properties['os.arch']
|
||||||
|
@ -172,33 +171,28 @@ tasks.register("configureArtifactInfo") {
|
||||||
description "Set the url to download stack artifacts for select stack version"
|
description "Set the url to download stack artifacts for select stack version"
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
def versionQualifier = System.getenv('VERSION_QUALIFIER')
|
def splitVersion = version.split('\\.')
|
||||||
if (versionQualifier) {
|
int major = splitVersion[0].toInteger()
|
||||||
version = "$version-$versionQualifier"
|
int minor = splitVersion[1].toInteger()
|
||||||
}
|
String branch = "${major}.${minor}"
|
||||||
|
String fallbackMajorX = "${major}.x"
|
||||||
|
boolean isFallBackPreviousMajor = minor - 1 < 0
|
||||||
|
String fallbackBranch = isFallBackPreviousMajor ? "${major-1}.x" : "${major}.${minor-1}"
|
||||||
|
def qualifiedVersion = ""
|
||||||
|
|
||||||
boolean isReleaseBuild = System.getenv('RELEASE') == "1" || versionQualifier
|
for (b in [branch, fallbackMajorX, fallbackBranch]) {
|
||||||
String apiResponse = artifactVersionsApi.toURL().text
|
def url = "https://storage.googleapis.com/artifacts-api/snapshots/${b}.json"
|
||||||
|
try {
|
||||||
def dlVersions = new JsonSlurper().parseText(apiResponse)
|
def snapshotInfo = new JsonSlurper().parseText(url.toURL().text)
|
||||||
String qualifiedVersion = dlVersions['versions'].grep(isReleaseBuild ? ~/^${version}$/ : ~/^${version}-SNAPSHOT/)[0]
|
qualifiedVersion = snapshotInfo.version
|
||||||
if (qualifiedVersion == null) {
|
println "ArtifactInfo version: ${qualifiedVersion}"
|
||||||
if (!isReleaseBuild) {
|
break
|
||||||
project.ext.set("useProjectSpecificArtifactSnapshotUrl", true)
|
} catch (Exception e) {
|
||||||
project.ext.set("stackArtifactSuffix", "${version}-SNAPSHOT")
|
println "Failed to fetch branch ${branch} from ${url}: ${e.message}"
|
||||||
return
|
|
||||||
}
|
}
|
||||||
throw new GradleException("could not find the current artifact from the artifact-api ${artifactVersionsApi} for ${version}")
|
|
||||||
}
|
}
|
||||||
// find latest reference to last build
|
|
||||||
String buildsListApi = "${artifactVersionsApi}/${qualifiedVersion}/builds/"
|
|
||||||
apiResponse = buildsListApi.toURL().text
|
|
||||||
def dlBuilds = new JsonSlurper().parseText(apiResponse)
|
|
||||||
def stackBuildVersion = dlBuilds["builds"][0]
|
|
||||||
|
|
||||||
project.ext.set("artifactApiVersionedBuildUrl", "${artifactVersionsApi}/${qualifiedVersion}/builds/${stackBuildVersion}")
|
project.ext.set("artifactApiVersion", qualifiedVersion)
|
||||||
project.ext.set("stackArtifactSuffix", qualifiedVersion)
|
|
||||||
project.ext.set("useProjectSpecificArtifactSnapshotUrl", false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,23 +431,13 @@ tasks.register("downloadFilebeat") {
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
download {
|
download {
|
||||||
String beatVersion = project.ext.get("stackArtifactSuffix")
|
String beatsVersion = project.ext.get("artifactApiVersion")
|
||||||
String downloadedFilebeatName = "filebeat-${beatVersion}-${project.ext.get("beatsArchitecture")}"
|
String downloadedFilebeatName = "filebeat-${beatsVersion}-${project.ext.get("beatsArchitecture")}"
|
||||||
project.ext.set("unpackedFilebeatName", downloadedFilebeatName)
|
project.ext.set("unpackedFilebeatName", downloadedFilebeatName)
|
||||||
|
|
||||||
if (project.ext.get("useProjectSpecificArtifactSnapshotUrl")) {
|
def res = SnapshotArtifactURLs.packageUrls("beats", beatsVersion, downloadedFilebeatName)
|
||||||
def res = SnapshotArtifactURLs.packageUrls("beats", beatVersion, downloadedFilebeatName)
|
project.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: res.packageUrl)
|
||||||
project.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: res.packageUrl)
|
project.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz")
|
||||||
project.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz")
|
|
||||||
} else {
|
|
||||||
// find url of build artifact
|
|
||||||
String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/beats/packages/${downloadedFilebeatName}.tar.gz"
|
|
||||||
String apiResponse = artifactApiUrl.toURL().text
|
|
||||||
def buildUrls = new JsonSlurper().parseText(apiResponse)
|
|
||||||
|
|
||||||
project.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: buildUrls["package"]["url"])
|
|
||||||
project.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz")
|
|
||||||
}
|
|
||||||
|
|
||||||
src project.ext.filebeatSnapshotUrl
|
src project.ext.filebeatSnapshotUrl
|
||||||
onlyIfNewer true
|
onlyIfNewer true
|
||||||
|
@ -489,20 +473,12 @@ tasks.register("checkEsSHA") {
|
||||||
description "Download ES version remote's fingerprint file"
|
description "Download ES version remote's fingerprint file"
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
String esVersion = project.ext.get("stackArtifactSuffix")
|
String esVersion = project.ext.get("artifactApiVersion")
|
||||||
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${project.ext.get("esArchitecture")}"
|
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${project.ext.get("esArchitecture")}"
|
||||||
String remoteSHA
|
String remoteSHA
|
||||||
|
|
||||||
if (project.ext.get("useProjectSpecificArtifactSnapshotUrl")) {
|
def res = SnapshotArtifactURLs.packageUrls("elasticsearch", esVersion, downloadedElasticsearchName)
|
||||||
def res = SnapshotArtifactURLs.packageUrls("elasticsearch", esVersion, downloadedElasticsearchName)
|
remoteSHA = res.packageShaUrl
|
||||||
remoteSHA = res.packageShaUrl
|
|
||||||
} else {
|
|
||||||
// find url of build artifact
|
|
||||||
String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/elasticsearch/packages/${downloadedElasticsearchName}.tar.gz"
|
|
||||||
String apiResponse = artifactApiUrl.toURL().text
|
|
||||||
def buildUrls = new JsonSlurper().parseText(apiResponse)
|
|
||||||
remoteSHA = buildUrls.package.sha_url.toURL().text
|
|
||||||
}
|
|
||||||
|
|
||||||
def localESArchive = new File("${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
|
def localESArchive = new File("${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
|
||||||
if (localESArchive.exists()) {
|
if (localESArchive.exists()) {
|
||||||
|
@ -536,25 +512,14 @@ tasks.register("downloadEs") {
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
download {
|
download {
|
||||||
String esVersion = project.ext.get("stackArtifactSuffix")
|
String esVersion = project.ext.get("artifactApiVersion")
|
||||||
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${project.ext.get("esArchitecture")}"
|
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${project.ext.get("esArchitecture")}"
|
||||||
|
|
||||||
project.ext.set("unpackedElasticsearchName", "elasticsearch-${esVersion}")
|
project.ext.set("unpackedElasticsearchName", "elasticsearch-${esVersion}")
|
||||||
|
|
||||||
if (project.ext.get("useProjectSpecificArtifactSnapshotUrl")) {
|
def res = SnapshotArtifactURLs.packageUrls("elasticsearch", esVersion, downloadedElasticsearchName)
|
||||||
def res = SnapshotArtifactURLs.packageUrls("elasticsearch", esVersion, downloadedElasticsearchName)
|
project.ext.set("elasticsearchSnapshotURL", System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: res.packageUrl)
|
||||||
project.ext.set("elasticsearchSnapshotURL", System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: res.packageUrl)
|
project.ext.set("elasticsearchDownloadLocation", "${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
|
||||||
project.ext.set("elasticsearchDownloadLocation", "${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
|
|
||||||
} else {
|
|
||||||
// find url of build artifact
|
|
||||||
String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/elasticsearch/packages/${downloadedElasticsearchName}.tar.gz"
|
|
||||||
String apiResponse = artifactApiUrl.toURL().text
|
|
||||||
|
|
||||||
def buildUrls = new JsonSlurper().parseText(apiResponse)
|
|
||||||
|
|
||||||
project.ext.set("elasticsearchSnapshotURL", System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: buildUrls["package"]["url"])
|
|
||||||
project.ext.set("elasticsearchDownloadLocation", "${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
|
|
||||||
}
|
|
||||||
|
|
||||||
src project.ext.elasticsearchSnapshotURL
|
src project.ext.elasticsearchSnapshotURL
|
||||||
onlyIfNewer true
|
onlyIfNewer true
|
||||||
|
|
Loading…
Add table
Reference in a new issue