jjb: lttng-modules: Add hwe-5.8 kernel to ubuntu focal
[lttng-ci.git] / scripts / lttng-modules / master.groovy
CommitLineData
f3d8604b 1/**
073dc82c 2 * Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
f3d8604b
MJ
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import hudson.model.*
19import hudson.AbortException
20import hudson.console.HyperlinkNote
21import java.util.concurrent.CancellationException
22import org.eclipse.jgit.api.Git
23import org.eclipse.jgit.lib.Ref
24
25
3a01c580
MJ
26class InvalidKVersionException extends Exception {
27 public InvalidKVersionException(String message) {
591756e5
MJ
28 super(message)
29 }
30}
31
3a01c580
MJ
32class EmptyKVersionException extends Exception {
33 public EmptyKVersionException(String message) {
591756e5
MJ
34 super(message)
35 }
36}
37
3a01c580 38class VanillaKVersion implements Comparable<VanillaKVersion> {
f3d8604b 39
3a01c580
MJ
40 Integer major = 0
41 Integer majorB = 0
42 Integer minor = 0
43 Integer patch = 0
44 Integer rc = Integer.MAX_VALUE
f3d8604b 45
3a01c580 46 VanillaKVersion() {}
f3d8604b 47
3a01c580 48 VanillaKVersion(version) {
f3d8604b
MJ
49 this.parse(version)
50 }
51
3a01c580
MJ
52 static VanillaKVersion minKVersion() {
53 return new VanillaKVersion("v0.0.0")
54 }
55
56 static VanillaKVersion maxKVersion() {
57 return new VanillaKVersion("v" + Integer.MAX_VALUE + ".0.0")
58 }
59
60 static VanillaKVersion factory(version) {
61 return new VanillaKVersion(version)
62 }
63
f3d8604b
MJ
64 def parse(version) {
65 this.major = 0
66 this.majorB = 0
67 this.minor = 0
68 this.patch = 0
69 this.rc = Integer.MAX_VALUE
70
591756e5 71 if (!version) {
3a01c580 72 throw new EmptyKVersionException("Empty kernel version")
591756e5
MJ
73 }
74
f3d8604b
MJ
75 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/
76 if (!match) {
3a01c580 77 throw new InvalidKVersionException("Invalid kernel version: ${version}")
f3d8604b
MJ
78 }
79
80 Integer offset = 0;
81
82 // Major
83 this.major = Integer.parseInt(match.group(1))
84 if (this.major <= 2) {
85 offset = 2
86 this.majorB = Integer.parseInt(match.group(2))
87 }
88
89 // Minor
90 if (match.group(2 + offset) != null) {
91 this.minor = Integer.parseInt(match.group(2 + offset))
92 }
93
94 // Patch level
95 if (match.group(4 + offset) != null) {
96 this.patch = Integer.parseInt(match.group(4 + offset))
97 }
98
99 // RC
100 if (match.group(8) != null) {
101 this.rc = Integer.parseInt(match.group(8))
102 }
103 }
104
105 // Return true if this version is a release candidate
106 Boolean isRC() {
107 return this.rc != Integer.MAX_VALUE
108 }
109
e9b44189 110 // Return true if both version are of the same stable branch
3a01c580 111 Boolean isSameStable(VanillaKVersion o) {
e9b44189
MJ
112 if (this.major != o.major) {
113 return false
114 }
115 if (this.majorB != o.majorB) {
116 return false
117 }
118 if (this.minor != o.minor) {
119 return false
120 }
121
122 return true
123 }
124
3a01c580 125 @Override int compareTo(VanillaKVersion o) {
f3d8604b 126 if (this.major != o.major) {
e9b44189 127 return Integer.compare(this.major, o.major)
f3d8604b
MJ
128 }
129 if (this.majorB != o.majorB) {
e9b44189 130 return Integer.compare(this.majorB, o.majorB)
f3d8604b
MJ
131 }
132 if (this.minor != o.minor) {
e9b44189 133 return Integer.compare(this.minor, o.minor)
f3d8604b
MJ
134 }
135 if (this.patch != o.patch) {
e9b44189 136 return Integer.compare(this.patch, o.patch)
f3d8604b
MJ
137 }
138 if (this.rc != o.rc) {
e9b44189 139 return Integer.compare(this.rc, o.rc)
f3d8604b
MJ
140 }
141
142 // Same version
143 return 0;
144 }
145
146 String toString() {
147 String vString = "v${this.major}"
148
149 if (this.majorB > 0) {
150 vString = vString.concat(".${this.majorB}")
151 }
152
153 vString = vString.concat(".${this.minor}")
154
155 if (this.patch > 0) {
156 vString = vString.concat(".${this.patch}")
157 }
158
159 if (this.rc > 0 && this.rc < Integer.MAX_VALUE) {
160 vString = vString.concat("-rc${this.rc}")
161 }
162 return vString
163 }
164}
165
3a01c580
MJ
166class UbuntuKVersion implements Comparable<UbuntuKVersion> {
167
168 Integer major = 0
169 Integer minor = 0
170 Integer patch = 0
171 Integer umajor = 0
172 Integer uminor = 0
173 String suffix = ""
cba2f848 174 String strLTS = ""
3a01c580
MJ
175 Boolean isLTS = false
176
177 UbuntuKVersion() {}
178
179 UbuntuKVersion(version) {
180 this.parse(version)
181 }
182
183 static UbuntuKVersion minKVersion() {
184 return new UbuntuKVersion("Ubuntu-lts-0.0.0-0.0")
185 }
186
187 static UbuntuKVersion maxKVersion() {
188 return new UbuntuKVersion("Ubuntu-" + Integer.MAX_VALUE + ".0.0-0.0")
189 }
190
191 static UbuntuKVersion factory(version) {
192 return new UbuntuKVersion(version)
193 }
194
195 def parse(version) {
196 this.major = 0
197 this.minor = 0
198 this.patch = 0
199 this.umajor = 0
200 this.uminor = 0
201 this.suffix = "";
202 this.isLTS = false
203
204 if (!version) {
205 throw new EmptyKVersionException("Empty kernel version")
206 }
207
073dc82c 208 //'Ubuntu-hwe-5.8-5.8.0-19.20_20.04.3',
3a01c580
MJ
209 //'Ubuntu-lts-4.8.0-27.29_16.04.1',
210 //'Ubuntu-4.4.0-70.91',
073dc82c 211 def match = version =~ /^Ubuntu-(lts-|hwe-)??(?:\d+\.\d+-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(.*)??$/
3a01c580
MJ
212 if (!match) {
213 throw new InvalidKVersionException("Invalid kernel version: ${version}")
214 }
215
cba2f848
MJ
216 if (match.group(1) != null) {
217 this.isLTS = true
218 this.strLTS = match.group(1)
219 }
3a01c580
MJ
220
221 // Major
222 this.major = Integer.parseInt(match.group(2))
223
224 // Minor
225 this.minor = Integer.parseInt(match.group(3))
226
227 // Patch level
228 this.patch = Integer.parseInt(match.group(4))
229
230 // Ubuntu major
231 this.umajor = Integer.parseInt(match.group(5))
232
233 // Ubuntu minor
234 this.uminor = Integer.parseInt(match.group(6))
235
236 if (match.group(7) != null) {
237 this.suffix = match.group(7)
238 }
239 }
240
241 // Return true if this version is a release candidate
242 Boolean isRC() {
243 return false
244 }
245
246 // Return true if both version are of the same stable branch
247 Boolean isSameStable(UbuntuKVersion o) {
248 if (this.isLTS != o.isLTS) {
249 return false
250 }
251 if (this.major != o.major) {
252 return false
253 }
254 if (this.minor != o.minor) {
255 return false
256 }
257 if (this.patch != o.patch) {
258 return false
259 }
260
261 return true
262 }
263
264 @Override int compareTo(UbuntuKVersion o) {
265 if (this.major != o.major) {
266 return Integer.compare(this.major, o.major)
267 }
268 if (this.minor != o.minor) {
269 return Integer.compare(this.minor, o.minor)
270 }
271 if (this.patch != o.patch) {
272 return Integer.compare(this.patch, o.patch)
273 }
274 if (this.umajor != o.umajor) {
275 return Integer.compare(this.umajor, o.umajor)
276 }
277 if (this.uminor != o.uminor) {
278 return Integer.compare(this.uminor, o.uminor)
279 }
280 if (this.isLTS != o.isLTS) {
281 if (o.isLTS) {
282 return 1
283 } else {
284 return -1
285 }
286 }
287
288 // Same version
289 return 0;
290 }
291
292 String toString() {
293 String vString = "Ubuntu-"
294
295 if (this.isLTS) {
cba2f848 296 vString = vString.concat("${this.strLTS}")
3a01c580
MJ
297 }
298
073dc82c
MJ
299 if (this.major >= 5 && this.minor >= 8) {
300 vString = vString.concat("${this.major}.${this.minor}-${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
301 } else {
302 vString = vString.concat("${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
303 }
3a01c580
MJ
304
305 return vString
306 }
307}
308
f3d8604b
MJ
309
310// Retrieve parameters of the current build
28b10e79 311def mbranch = build.getEnvironment(listener).get('GIT_BRANCH').minus('origin/')
f3d8604b
MJ
312def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
313def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
591756e5
MJ
314def kverfloor_raw = build.buildVariableResolver.resolve('kverfloor')
315def kverceil_raw = build.buildVariableResolver.resolve('kverceil')
e9b44189 316def kverfilter = build.buildVariableResolver.resolve('kverfilter')
28b10e79 317def kverrc = build.buildVariableResolver.resolve('kverrc')
3a01c580 318def uversion = build.buildVariableResolver.resolve('uversion')
f3d8604b 319def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
483859f3 320def currentJobName = build.project.getFullDisplayName()
5a196804 321def gitmodpath = build.getEnvironment(listener).get('WORKSPACE') + "/src/lttng-modules"
591756e5 322
f3d8604b
MJ
323// Get the out variable
324def config = new HashMap()
325def bindings = getBinding()
326config.putAll(bindings.getVariables())
327def out = config['out']
328
f3d8604b 329
5a196804
MJ
330// Get the lttng-modules git url
331def gitmodrepo = Git.open(new File(gitmodpath))
332def mgitrepo = gitmodrepo.getRepository().getConfig().getString("remote", "origin", "url")
333
f3d8604b 334// Get tags from git repository
5a196804 335def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call()
f3d8604b
MJ
336
337// Get kernel versions to build
338def kversions = []
339def kversionsRC = []
3a01c580
MJ
340def matchStrs = []
341def blacklist = []
342def kversionFactory = ""
343
344if (uversion != null) {
345 kversionFactory = new UbuntuKVersion()
346 switch (uversion) {
9e5757c6
MJ
347 case 'focal':
348 matchStrs = [
349 ~/^refs\/tags\/(Ubuntu-5\.4\.0-\d{1,3}?\.[\d]+)$/,
073dc82c 350 ~/^refs\/tags\/(Ubuntu-hwe-5\.8-.*_20\.04\.\d+)$/,
9e5757c6
MJ
351 ]
352 break
353
57bdee9e
MJ
354 case 'bionic':
355 matchStrs = [
356 ~/^refs\/tags\/(Ubuntu-4\.15\.0-\d{1,3}?\.[\d]+)$/,
9e5757c6 357 ~/^refs\/tags\/(Ubuntu-hwe-5\.0\.0-.*_18\.04\.\d+)$/,
73b8af4b 358 ~/^refs\/tags\/(Ubuntu-hwe-5\.3\.0-.*_18\.04\.\d+)$/,
57bdee9e
MJ
359 ]
360 break
361
3a01c580
MJ
362 case 'xenial':
363 matchStrs = [
364 ~/^refs\/tags\/(Ubuntu-4\.4\.0-\d{1,3}?\.[\d]+)$/,
cba2f848 365 ~/^refs\/tags\/(Ubuntu-hwe-4\.15\.0-.*_16\.04\.\d+)$/,
3a01c580
MJ
366 ]
367
368 blacklist = [
369 'Ubuntu-lts-4.10.0-7.9_16.04.1',
370 ]
371 break
372
373 case 'trusty':
374 matchStrs = [
375 ~/^refs\/tags\/(Ubuntu-3\.13\.0-[\d\.]+)$/,
376 ~/^refs\/tags\/(Ubuntu-lts-.*_14\.04\.\d+)$/,
377 ]
378 break
379
380 default:
57bdee9e 381 println "Unsupported Ubuntu version: ${uversion}"
3a01c580
MJ
382 throw new InterruptedException()
383 break
384 }
385} else {
386 // Vanilla
387 kversionFactory = new VanillaKVersion()
388 matchStrs = [
389 ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/,
390 ]
2cfd47ab
MJ
391 blacklist = [
392 'v3.2.3',
393 ]
3a01c580 394}
f3d8604b 395
3a01c580
MJ
396// Parse kernel versions
397def kverfloor = ""
398try {
399 kverfloor = kversionFactory.factory(kverfloor_raw)
400} catch (EmptyKVersionException e) {
401 kverfloor = kversionFactory.minKVersion()
402}
f3d8604b 403
3a01c580
MJ
404def kverceil = ""
405try {
406 kverceil = kversionFactory.factory(kverceil_raw)
407} catch (EmptyKVersionException e) {
408 kverceil = kversionFactory.maxKVersion()
409}
410
411// Build a sorted list of versions to build
412for (ref in refs) {
413 for (matchStr in matchStrs) {
414 def match = ref.getName() =~ matchStr
415 if (match && !blacklist.contains(match.group(1))) {
416 def v = kversionFactory.factory(match.group(1))
417
418 if ((v >= kverfloor) && (v < kverceil)) {
419 if (v.isRC()) {
420 kversionsRC.add(v)
421 } else {
422 kversions.add(v)
423 }
f3d8604b
MJ
424 }
425 }
426 }
427}
428
429kversions.sort()
430kversionsRC.sort()
431
e9b44189
MJ
432switch (kverfilter) {
433 case 'stable-head':
434 // Keep only the head of each stable branch
435 println('Filter kernel versions to keep only the latest point release of each stable branch.')
436
437 for (i = 0; i < kversions.size(); i++) {
438 def curr = kversions[i]
439 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
440
441 if (next != null) {
442 if (curr.isSameStable(next)) {
443 kversions.remove(i)
444 i--
445 }
446 }
447 }
448 break
449
450 default:
451 // No filtering of kernel versions
452 println('No kernel versions filtering selected.')
453 break
454}
455
28b10e79
MJ
456if (kverrc == "true") {
457 // If the last RC version is newer than the last stable, add it to the build list
458 if (kversionsRC.size() > 0 && kversionsRC.last() > kversions.last()) {
459 kversions.add(kversionsRC.last())
460 }
f3d8604b
MJ
461}
462
f3d8604b
MJ
463println "Building the following kernel versions:"
464for (k in kversions) {
465 println k
466}
467
468// Debug: Stop build here
469//throw new InterruptedException()
470
471def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
472
473def allBuilds = []
474def ongoingBuild = []
475def failedRuns = []
476def isFailed = false
483859f3 477def similarJobQueued = 0;
f3d8604b
MJ
478
479// Loop while we have kernel versions remaining or jobs running
480while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
481
482 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
483 def kversion = kversions.pop()
484 def job_params = [
28b10e79 485 new StringParameterValue('mversion', mbranch),
5a196804 486 new StringParameterValue('mgitrepo', mgitrepo),
a1ae361e 487 new StringParameterValue('ktag', kversion.toString()),
f3d8604b
MJ
488 new StringParameterValue('kgitrepo', kgitrepo),
489 ]
490
491 // Launch the parametrized build
492 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
28b10e79 493 println "triggering ${joburl} for the ${mbranch} branch on kernel ${kversion}"
f3d8604b
MJ
494
495 // Add it to the ongoing build queue
496 ongoingBuild.push(param_build)
497
498 } else {
499
500 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
501 try {
3a01c580 502 Thread.sleep(10000)
f3d8604b
MJ
503 } catch(e) {
504 if (e in InterruptedException) {
505 build.setResult(hudson.model.Result.ABORTED)
506 throw new InterruptedException()
507 } else {
508 throw(e)
509 }
510 }
511
3a01c580 512 // Abort job if a newer instance is queued
b7efa3aa
MJ
513 if (!currentJobName.contains("gerrit")) {
514 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
515 if (similarJobQueued > 0) {
516 println "Abort, a newer instance of the job was queued"
483859f3
JR
517 build.setResult(hudson.model.Result.ABORTED)
518 throw new InterruptedException()
b7efa3aa 519 }
483859f3
JR
520 }
521
f3d8604b
MJ
522 def i = ongoingBuild.iterator()
523 while ( i.hasNext() ) {
524 currentBuild = i.next()
525 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
526 // Remove from queue
527 i.remove()
528
529 // Print results
530 def matrixParent = currentBuild.get()
531 allBuilds.add(matrixParent)
a1ae361e 532 def kernelStr = matrixParent.buildVariableResolver.resolve("ktag")
f3d8604b
MJ
533 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
534
535 // Process child runs of matrixBuild
536 def childRuns = matrixParent.getRuns()
537 for ( childRun in childRuns ) {
538 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
539 if (childRun.result != Result.SUCCESS) {
540 failedRuns.add(childRun)
541 isFailed = true
542 }
543 }
544 }
545 }
546 }
547}
548
549// Get log of failed runs
550for (failedRun in failedRuns) {
551 println "---START---"
552 failedRun.writeWholeLogTo(out)
553 println "---END---"
554}
555
556println "---Build report---"
557for (b in allBuilds) {
a1ae361e 558 def kernelStr = b.buildVariableResolver.resolve("ktag")
f3d8604b 559 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
7e02032c 560 // Cleanup builds
7e942863
MJ
561 try {
562 b.delete()
563 } catch (all) {}
f3d8604b
MJ
564}
565
566// Mark this build failed if any child build has failed
567if (isFailed) {
c5c05f73 568 build.setResult(hudson.model.Result.FAILURE)
f3d8604b
MJ
569}
570
571// EOF
This page took 0.05078 seconds and 4 git commands to generate.