-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathtrigger_beta_build.groovy
280 lines (241 loc) · 12 KB
/
trigger_beta_build.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package common
/*
Licensed 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
https://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.
*/
import java.nio.file.NoSuchFileException
import groovy.json.JsonOutput
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.Month
import java.time.DayOfWeek
import java.time.temporal.ChronoUnit
import java.time.temporal.TemporalAdjusters
/*
Detect new upstream OpenJDK source build tag, and trigger a "beta" pipeline build
if the given build has not already been published, and the given version is
not GA yet (existance of -ga tag).
The "Force" option can be used to re-build and re-publish the existing latest build.
*/
def variant="${params.VARIANT}"
def mirrorRepo="${params.MIRROR_REPO}"
def version="${params.JDK_VERSION}".toInteger()
def binariesRepo="${params.BINARIES_REPO}"
def triggerMainBuild = false
def triggerEvaluationBuild = false
def enableTesting = true
def overrideMainTargetConfigurations = params.OVERRIDE_MAIN_TARGET_CONFIGURATIONS
def overrideEvaluationTargetConfigurations = params.OVERRIDE_EVALUATION_TARGET_CONFIGURATIONS
def ignore_platforms = "${params.IGNORE_PLATFORMS}" // platforms not to build
def mainTargetConfigurations = overrideMainTargetConfigurations
def evaluationTargetConfigurations = overrideEvaluationTargetConfigurations
def latestAdoptTag
def publishJobTag
// Is the current day within the release period of from the previous Saturday to the following Sunday
// from the release Tuesday ?
def isDuringReleasePeriod() {
def releasePeriod = false
def now = ZonedDateTime.now(ZoneId.of('UTC'))
def month = now.getMonth()
// Is it a release month? CPU updates in Jan, Apr, Jul, Oct
// New major versions are released in Mar and Sept
if (month == Month.JANUARY || month == Month.MARCH || month == Month.APRIL || month == Month.JULY || month == Month.SEPTEMBER || month == Month.OCTOBER) {
// Yes, calculate release Tuesday, which is the closest Tuesday to the 17th
def day17th = now.withDayOfMonth(17)
def dayOfWeek17th = day17th.getDayOfWeek()
def releaseTuesday
if (dayOfWeek17th == DayOfWeek.SATURDAY || dayOfWeek17th == DayOfWeek.SUNDAY || dayOfWeek17th == DayOfWeek.MONDAY || dayOfWeek17th == DayOfWeek.TUESDAY) {
releaseTuesday = day17th.with(TemporalAdjusters.nextOrSame(DayOfWeek.TUESDAY))
} else {
releaseTuesday = day17th.with(TemporalAdjusters.previous(DayOfWeek.TUESDAY))
}
// Release period no trigger from prior week previous Saturday to following Sunday
def days = ChronoUnit.DAYS.between(releaseTuesday, now)
if (days >= -10 && days <= 5) {
releasePeriod = true
}
}
return releasePeriod
}
// Load the given targetConfigurations from the pipeline config
def loadTargetConfigurations(String javaVersion, String variant, String configSet, String ignore_platforms) {
def targetConfigPath = "${params.BUILD_CONFIG_URL}"
def to_be_ignored = ignore_platforms.split("[, ]+")
targetConfigurations = null
configFile = "jdk${javaVersion}${configSet}.groovy"
def rc = sh(script: "curl --fail -LO ${targetConfigPath}/${configFile}", returnStatus: true)
if (rc != 0) {
echo "Error loading ${targetConfigPath}/${configFile}, trying ${targetConfigPath}/jdk${javaVersion}u${configSet}.groovy"
configFile = "jdk${javaVersion}u${configSet}.groovy"
rc = sh(script: "curl --fail -LO ${targetConfigPath}/${configFile}", returnStatus: true)
if (rc != 0) {
echo "Error loading ${targetConfigPath}/${configFile}"
}
}
if (rc == 0) {
// We successfully downloaded the pipeline config file, now load it into groovy to set targetConfigurations..
load configFile
echo "Successfully loaded ${targetConfigPath}/${configFile}"
}
def targetConfigurationsForVariant = [:]
if (targetConfigurations != null) {
targetConfigurations.each { platform ->
if (platform.value.contains(variant) && !to_be_ignored.contains(platform.key)) {
targetConfigurationsForVariant[platform.key] = [variant]
}
}
}
return targetConfigurationsForVariant
}
node('worker') {
def adopt_tag_search
if (version == 8) {
// eg. jdk8u422-b03_adopt
adopt_tag_search = 'grep "jdk8u.*_adopt"'
if (mirrorRepo.contains("aarch32-jdk8u")) {
adopt_tag_search = adopt_tag_search + ' | grep "\\-aarch32\\-"'
}
} else {
// eg. jdk-11.0.24+6_adopt or jdk-23+26_adopt
adopt_tag_search = 'grep "jdk-'+version+'[\\.\\+].*_adopt"'
}
// Find latest _adopt tag for this version?
latestAdoptTag = sh(script:'git ls-remote --sort=-v:refname --tags "'+mirrorRepo+'" | grep -v "\\^{}" | grep -v "\\+0\\$" | grep -v "\\-ga\\$" | '+adopt_tag_search+' | tr -s "\\t " " " | cut -d" " -f2 | sed "s,refs/tags/,," | sort -V -r | head -1 | tr -d "\\n"', returnStdout:true)
if (latestAdoptTag.indexOf("_adopt") < 0) {
def error = "Error finding latest _adopt tag for ${mirrorRepo}"
echo "${error}"
throw new Exception("${error}")
}
echo "Latest Adoptium tag from ${mirrorRepo} = ${latestAdoptTag}"
// publishJobTag is TAG that gets passed to the Adoptium "publish job"
if (mirrorRepo.contains("aarch32-jdk8u")) {
publishJobTag = latestAdoptTag.substring(0, latestAdoptTag.indexOf("-aarch32"))+"-ea"
} else {
publishJobTag = latestAdoptTag.replaceAll("_adopt","-ea")
}
echo "publishJobTag = ${publishJobTag}"
// binariesRepoTag is the resulting published github binaries release tag created by the Adoptium "publish job"
def binariesRepoTag = publishJobTag + "-beta"
if (isDuringReleasePeriod()) {
echo "We are within a release period (previous Saturday to the following Sunday around the release Tuesday), so testing is disabled."
enableTesting = false
}
if (!params.FORCE_MAIN && !params.FORCE_EVALUATION) {
// Determine this versions potential GA tag, so as to not build and publish a GA version
def gaTag
def versionStr
if (version > 8) {
versionStr = latestAdoptTag.substring(0, latestAdoptTag.indexOf("+"))
} else {
versionStr = latestAdoptTag.substring(0, latestAdoptTag.indexOf("-"))
}
gaTag=versionStr+"-ga"
echo "Expected GA tag to check for = ${gaTag}"
// If "-ga" tag exists, then we don't want to trigger a MAIN build
def gaTagCheck=sh(script:'git ls-remote --sort=-v:refname --tags "'+mirrorRepo+'" | grep -v "\\^{}" | grep "'+gaTag+'"', returnStatus:true)
if (gaTagCheck == 0) {
echo "Version "+versionStr+" already has a GA tag so not triggering a MAIN build"
}
// Check binaries repo for existance of the given release?
echo "Checking if ${binariesRepoTag} is already published?"
def desiredRepoTagURL="${binariesRepo}/releases/tag/${binariesRepoTag}"
def httpCode=sh(script:"curl -s -o /dev/null -w '%{http_code}' "+desiredRepoTagURL, returnStdout:true)
if (httpCode == "200") {
echo "Build tag ${binariesRepoTag} is already published - nothing to do"
} else if (httpCode == "404") {
echo "New unpublished build tag ${binariesRepoTag} - triggering builds"
if (gaTagCheck == 0) {
echo "Version "+versionStr+" already has a GA tag so not triggering a MAIN build"
} else {
triggerMainBuild = true
}
triggerEvaluationBuild = true
} else {
def error = "Unexpected HTTP code ${httpCode} when querying for existing build tag at $desiredRepoTagURL"
echo "${error}"
throw new Exception("${error}")
}
} else {
echo "FORCE triggering specified builds.."
triggerMainBuild = params.FORCE_MAIN
triggerEvaluationBuild = params.FORCE_EVALUATION
}
// If we are going to trigger, then load the targetConfigurations
if (triggerMainBuild || triggerEvaluationBuild) {
// Load the targetConfigurations
if (triggerMainBuild && mainTargetConfigurations == "") {
// Load "main" targetConfigurations from pipeline config
def config = loadTargetConfigurations((String)version, variant, "", ignore_platforms)
if (!config) {
def error = "Empty mainTargetConfigurations"
echo "${error}"
throw new Exception("${error}")
}
mainTargetConfigurations = JsonOutput.toJson(config)
}
if (triggerEvaluationBuild && evaluationTargetConfigurations == "") {
// Load "evaluation" targetConfigurations from pipeline config
def config = loadTargetConfigurations((String)version, variant, "_evaluation", ignore_platforms)
if (!config) {
def error = "Empty evaluationTargetConfigurations"
echo "${error}"
// Evaluation config can be empty if none for this version
triggerEvaluationBuild = false
} else {
evaluationTargetConfigurations = JsonOutput.toJson(config)
}
}
}
} // End: node('worker')
if (triggerMainBuild || triggerEvaluationBuild) {
// Set version suffix, jdk8 has different mechanism to jdk11+
def additionalConfigureArgs = (version > 8) ? "--with-version-opt=ea" : ""
// Trigger pipeline builds for main & evaluation of the new build tag and publish with the "ea" tag
def jobs = [:]
def pipelines = [:]
if (triggerMainBuild) {
pipelines["main"] = "build-scripts/openjdk${version}-pipeline"
echo "main build targetConfigurations:"
echo JsonOutput.prettyPrint(mainTargetConfigurations)
}
if (triggerEvaluationBuild) {
pipelines["evaluation"] = "build-scripts/evaluation-openjdk${version}-pipeline"
echo "evaluation build targetConfigurations:"
echo JsonOutput.prettyPrint(evaluationTargetConfigurations)
}
pipelines.keySet().each { pipeline_type ->
def pipeline = pipelines[pipeline_type]
jobs[pipeline] = {
catchError {
stage("Trigger build pipeline - ${pipeline}") {
echo "Triggering ${pipeline} for $latestAdoptTag"
def jobParams = [
string(name: 'releaseType', value: "Weekly"),
string(name: 'scmReference', value: "$latestAdoptTag"),
string(name: 'overridePublishName', value: "$publishJobTag"),
booleanParam(name: 'aqaAutoGen', value: true),
booleanParam(name: 'enableTests', value: enableTesting),
string(name: 'additionalConfigureArgs', value: "$additionalConfigureArgs")
]
// Specify the required targetConfigurations
if (pipeline_type == "main") {
jobParams.add(text(name: 'targetConfigurations', value: JsonOutput.prettyPrint(mainTargetConfigurations)))
}
if (pipeline_type == "evaluation") {
jobParams.add(text(name: 'targetConfigurations', value: JsonOutput.prettyPrint(evaluationTargetConfigurations)))
}
def job = build job: "${pipeline}", propagate: true, parameters: jobParams
echo "Triggered ${pipeline} build result = "+ job.getResult()
}
}
}
}
parallel jobs
}