ansible: Add mirror Ubuntu noble kernel sources to git-mirror
[lttng-ci.git] / scripts / lttng-modules / master.groovy
... / ...
CommitLineData
1/**
2 * Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
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
26class InvalidKVersionException extends Exception {
27 public InvalidKVersionException(String message) {
28 super(message)
29 }
30}
31
32class EmptyKVersionException extends Exception {
33 public EmptyKVersionException(String message) {
34 super(message)
35 }
36}
37
38class VanillaKVersion implements Comparable<VanillaKVersion> {
39
40 Integer major = 0
41 Integer majorB = 0
42 Integer minor = 0
43 Integer patch = 0
44 Integer rc = Integer.MAX_VALUE
45
46 VanillaKVersion() {}
47
48 VanillaKVersion(version) {
49 this.parse(version)
50 }
51
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
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
71 if (!version) {
72 throw new EmptyKVersionException("Empty kernel version")
73 }
74
75 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/
76 if (!match) {
77 throw new InvalidKVersionException("Invalid kernel version: ${version}")
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
110 // Return true if both version are of the same stable branch
111 Boolean isSameStable(VanillaKVersion o) {
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
125 @Override int compareTo(VanillaKVersion o) {
126 if (this.major != o.major) {
127 return Integer.compare(this.major, o.major)
128 }
129 if (this.majorB != o.majorB) {
130 return Integer.compare(this.majorB, o.majorB)
131 }
132 if (this.minor != o.minor) {
133 return Integer.compare(this.minor, o.minor)
134 }
135 if (this.patch != o.patch) {
136 return Integer.compare(this.patch, o.patch)
137 }
138 if (this.rc != o.rc) {
139 return Integer.compare(this.rc, o.rc)
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
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 = ""
174 String strLTS = ""
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
208 //'Ubuntu-hwe-5.8-5.8.0-19.20_20.04.3',
209 //'Ubuntu-lts-4.8.0-27.29_16.04.1',
210 //'Ubuntu-4.4.0-70.91',
211 def match = version =~ /^Ubuntu-(lts-|hwe-)??(?:\d+\.\d+-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(.*)??$/
212 if (!match) {
213 throw new InvalidKVersionException("Invalid kernel version: ${version}")
214 }
215
216 if (match.group(1) != null) {
217 this.isLTS = true
218 this.strLTS = match.group(1)
219 }
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) {
296 vString = vString.concat("${this.strLTS}")
297 }
298
299 // The tag pattern changed for HWE kernels >= 5.0
300 if (this.isLTS && this.major >= 5) {
301 vString = vString.concat("${this.major}.${this.minor}-${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
302 } else {
303 vString = vString.concat("${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
304 }
305
306 return vString
307 }
308}
309
310
311// Retrieve parameters of the current build
312def mbranch = build.getEnvironment(listener).get('GIT_BRANCH').minus('origin/')
313def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
314def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
315def kverfloor_raw = build.buildVariableResolver.resolve('kverfloor')
316def kverceil_raw = build.buildVariableResolver.resolve('kverceil')
317def kverfilter = build.buildVariableResolver.resolve('kverfilter')
318def kverrc = build.buildVariableResolver.resolve('kverrc')
319def uversion = build.buildVariableResolver.resolve('uversion')
320def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
321def currentJobName = build.project.getFullDisplayName()
322def gitmodpath = build.getEnvironment(listener).get('WORKSPACE') + "/src/lttng-modules"
323
324// Get the out variable
325def config = new HashMap()
326def bindings = getBinding()
327config.putAll(bindings.getVariables())
328def out = config['out']
329
330
331// Get the lttng-modules git url
332def gitmodrepo = Git.open(new File(gitmodpath))
333def mgitrepo = gitmodrepo.getRepository().getConfig().getString("remote", "origin", "url")
334
335// Get tags from git repository
336def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call()
337
338// Get kernel versions to build
339def kversions = []
340def kversionsRC = []
341def matchStrs = []
342def blacklist = []
343def kversionFactory = ""
344
345if (uversion != null) {
346 kversionFactory = new UbuntuKVersion()
347 switch (uversion) {
348 case 'jammy':
349 matchStrs = [
350 ~/^refs\/tags\/(Ubuntu-5\.15\.0-\d{1,3}?\.[\d]+)$/,
351 ~/^refs\/tags\/(Ubuntu-hwe-6\.2-6\.2\.0-.*_22\.04\.\d+)$/,
352 ~/^refs\/tags\/(Ubuntu-hwe-6\.5-6\.5\.0-.*_22\.04\.\d+)$/,
353 ]
354 break
355
356 case 'focal':
357 matchStrs = [
358 ~/^refs\/tags\/(Ubuntu-5\.4\.0-\d{1,3}?\.[\d]+)$/,
359 ~/^refs\/tags\/(Ubuntu-hwe-5\.13-5\.13\.0-.*_20\.04\.\d+)$/,
360 ]
361 break
362
363 default:
364 println "Unsupported Ubuntu version: ${uversion}"
365 throw new InterruptedException()
366 break
367 }
368} else {
369 // Vanilla
370 kversionFactory = new VanillaKVersion()
371 matchStrs = [
372 ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/,
373 ]
374 blacklist = [
375 'v3.2.3',
376 ]
377}
378
379// Parse kernel versions
380def kverfloor = ""
381try {
382 kverfloor = kversionFactory.factory(kverfloor_raw)
383} catch (EmptyKVersionException e) {
384 kverfloor = kversionFactory.minKVersion()
385}
386
387def kverceil = ""
388try {
389 kverceil = kversionFactory.factory(kverceil_raw)
390} catch (EmptyKVersionException e) {
391 kverceil = kversionFactory.maxKVersion()
392}
393
394// Build a sorted list of versions to build
395for (ref in refs) {
396 for (matchStr in matchStrs) {
397 def match = ref.getName() =~ matchStr
398 if (match && !blacklist.contains(match.group(1))) {
399 def v = kversionFactory.factory(match.group(1))
400
401 if ((v >= kverfloor) && (v < kverceil)) {
402 if (v.isRC()) {
403 kversionsRC.add(v)
404 } else {
405 kversions.add(v)
406 }
407 }
408 }
409 }
410}
411
412// The filtering step assumes the version lists are sorted
413kversions.sort()
414kversionsRC.sort()
415
416switch (kverfilter) {
417 case 'stable-head':
418 // Keep only the head of each stable branch
419 println('Filter kernel versions to keep only the latest point release of each stable branch.')
420
421 for (i = 0; i < kversions.size(); i++) {
422 def curr = kversions[i]
423 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
424
425 if (next != null) {
426 if (curr.isSameStable(next)) {
427 kversions.remove(i)
428 i--
429 }
430 }
431 }
432 break
433
434 case 'lts-head':
435 // Keep only the head of each LTS branch and the latest non-RC tag
436 println('Filter kernel versions to keep only the latest point release of each lts branch and the current stable.')
437
438 def lts_kversions = []
439 // Old LTS entries are kept so that "lts-head" is still meaningful in kernel
440 // version ranges that are supported by lttng-modules but no longer supported
441 // upstream, eg. lttng-modules stable-2.13 supports >= 3.0
442 lts_kversions.add(kversionFactory.factory("v3.0")) // LTS until October 2013
443 lts_kversions.add(kversionFactory.factory("v3.2")) // LTS until May 2018
444 lts_kversions.add(kversionFactory.factory("v3.4")) // LTS until October 2016
445 lts_kversions.add(kversionFactory.factory("v3.10")) // LTS until November 2017
446 lts_kversions.add(kversionFactory.factory("v3.12")) // LTS until May 2017
447 lts_kversions.add(kversionFactory.factory("v3.14")) // LTS until August 2016
448 lts_kversions.add(kversionFactory.factory("v3.16")) // LTS until October 2014
449 lts_kversions.add(kversionFactory.factory("v3.18")) // LTS until January 2017
450 lts_kversions.add(kversionFactory.factory("v4.1")) // LTS until May 2018
451 lts_kversions.add(kversionFactory.factory("v4.4")) // SLTS until 2026
452 lts_kversions.add(kversionFactory.factory("v4.9")) // LTS until January 2023
453 lts_kversions.add(kversionFactory.factory("v4.14")) // LTS until January 2024
454 lts_kversions.add(kversionFactory.factory("v4.19")) // LTS until December 2024
455 lts_kversions.add(kversionFactory.factory("v5.4")) // LTS until December 2025
456 lts_kversions.add(kversionFactory.factory("v5.10")) // LTS until December 2026
457 lts_kversions.add(kversionFactory.factory("v5.15")) // LTS until December 2026
458 lts_kversions.add(kversionFactory.factory("v6.1")) // LTS until December 2026
459 lts_kversions.add(kversionFactory.factory("v6.6")) // LTS until December 2026
460
461 // First filter the head of each branch
462 for (i = 0; i < kversions.size(); i++) {
463 def curr = kversions[i]
464 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
465
466 if (next != null) {
467 if (curr.isSameStable(next)) {
468 kversions.remove(i)
469 i--
470 }
471 }
472 }
473
474 for (i = 0; i < kversions.size(); i++) {
475 def curr = kversions[i]
476
477 // Keep the newest tag
478 if (i == kversions.size() - 1) {
479 break
480 }
481
482 // Prune non-LTS versions
483 def keep = false
484 for (j = 0; j < lts_kversions.size(); j++) {
485 if (curr.isSameStable(lts_kversions[j])) {
486 keep = true
487 break
488 }
489 }
490
491 if (!keep) {
492 kversions.remove(i)
493 i--
494 }
495 }
496 break
497
498 default:
499 // No filtering of kernel versions
500 println('No kernel versions filtering selected.')
501 break
502}
503
504if (kverrc == "true") {
505 // If the last RC version is newer than the last stable, add it to the build list
506 if (kversionsRC.size() > 0 && kversionsRC.last() > kversions.last()) {
507 kversions.add(kversionsRC.last())
508 }
509}
510
511println "Building the following kernel versions:"
512for (k in kversions) {
513 println k
514}
515
516// Debug: Stop build here
517//throw new InterruptedException()
518
519def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
520
521def allBuilds = []
522def ongoingBuild = []
523def failedRuns = []
524def isFailed = false
525def similarJobQueued = 0;
526
527// Loop while we have kernel versions remaining or jobs running
528while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
529
530 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
531 def kversion = kversions.pop()
532 def job_params = [
533 new StringParameterValue('mversion', mbranch),
534 new StringParameterValue('mgitrepo', mgitrepo),
535 new StringParameterValue('ktag', kversion.toString()),
536 new StringParameterValue('kgitrepo', kgitrepo),
537 ]
538
539 // Launch the parametrized build
540 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
541 println "triggering ${joburl} for the ${mbranch} branch on kernel ${kversion}"
542
543 // Add it to the ongoing build queue
544 ongoingBuild.push(param_build)
545
546 } else {
547
548 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
549 try {
550 Thread.sleep(10000)
551 } catch(e) {
552 if (e in InterruptedException) {
553 build.setResult(hudson.model.Result.ABORTED)
554 throw new InterruptedException()
555 } else {
556 throw(e)
557 }
558 }
559
560 // Abort job if a newer instance is queued
561 if (!currentJobName.contains("gerrit")) {
562 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
563 if (similarJobQueued > 0) {
564 println "Abort, a newer instance of the job was queued"
565 build.setResult(hudson.model.Result.ABORTED)
566 throw new InterruptedException()
567 }
568 }
569
570 def i = ongoingBuild.iterator()
571 while ( i.hasNext() ) {
572 currentBuild = i.next()
573 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
574 // Remove from queue
575 i.remove()
576
577 // Print results
578 def matrixParent = currentBuild.get()
579 allBuilds.add(matrixParent)
580 def kernelStr = matrixParent.buildVariableResolver.resolve("ktag")
581 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
582
583 // Process child runs of matrixBuild
584 def childRuns = matrixParent.getRuns()
585 for ( childRun in childRuns ) {
586 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
587 if (childRun.result != Result.SUCCESS) {
588 failedRuns.add(childRun)
589 isFailed = true
590 }
591 }
592 }
593 }
594 }
595}
596
597// Get log of failed runs
598for (failedRun in failedRuns) {
599 println "---START---"
600 failedRun.writeWholeLogTo(out)
601 println "---END---"
602}
603
604println "---Build report---"
605for (b in allBuilds) {
606 def kernelStr = b.buildVariableResolver.resolve("ktag")
607 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
608 // Cleanup builds
609 try {
610 b.delete()
611 } catch (all) {}
612}
613
614// Mark this build failed if any child build has failed
615if (isFailed) {
616 build.setResult(hudson.model.Result.FAILURE)
617}
618
619// EOF
This page took 0.025243 seconds and 4 git commands to generate.