X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=scripts%2Flttng-modules%2Fmaster-rt.groovy;h=dd24317940a5d18ab45ad74e9aad7646a533f9ee;hb=f185acd0096a94f9a094c7123ee56d5c803aff25;hp=3b84c1ae7dd7aa9814e6ddd697a3e80a1f278f36;hpb=7e02032ce920ba456327f163dade2aa616b09234;p=lttng-ci.git diff --git a/scripts/lttng-modules/master-rt.groovy b/scripts/lttng-modules/master-rt.groovy index 3b84c1a..dd24317 100644 --- a/scripts/lttng-modules/master-rt.groovy +++ b/scripts/lttng-modules/master-rt.groovy @@ -1,5 +1,5 @@ /** - * Copyright (C) 2016 - Michael Jeanson + * Copyright (C) 2016-2018 - Michael Jeanson * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,20 +23,44 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.lib.Ref -class kVersion implements Comparable { +class InvalidKVersionException extends Exception { + public InvalidKVersionException(String message) { + super(message) + } +} - Integer major = 0; - Integer majorB = 0; - Integer minor = 0; - Integer patch = 0; - Integer rt = 0; +class EmptyKVersionException extends Exception { + public EmptyKVersionException(String message) { + super(message) + } +} - kVersion() {} +class RTKVersion implements Comparable { - kVersion(version) { + Integer major = 0 + Integer majorB = 0 + Integer minor = 0 + Integer patch = 0 + Integer rt = 0 + + RTKVersion() {} + + RTKVersion(version) { this.parse(version) } + static RTKVersion minKVersion() { + return new RTKVersion("v0.0.0-rt0-rebase") + } + + static RTKVersion maxKVersion() { + return new RTKVersion("v" + Integer.MAX_VALUE + ".0.0-rt0-rebase") + } + + static RTKVersion factory(version) { + return new RTKVersion(version) + } + def parse(version) { this.major = 0 this.majorB = 0 @@ -44,9 +68,13 @@ class kVersion implements Comparable { this.patch = 0 this.rt = 0 + if (!version) { + throw new EmptyKVersionException("Empty kernel version") + } + def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rt(\d+)-rebase)$/ if (!match) { - throw new Exception("Invalid kernel version: ${version}") + throw new InvalidKVersionException("Invalid kernel version: ${version}") } Integer offset = 0; @@ -72,21 +100,36 @@ class kVersion implements Comparable { this.rt = Integer.parseInt(match.group(8)) } - @Override int compareTo(kVersion o) { + // Return true if both version are of the same stable branch + Boolean isSameStable(RTKVersion o) { + if (this.major != o.major) { + return false + } + if (this.majorB != o.majorB) { + return false + } + if (this.minor != o.minor) { + return false + } + + return true + } + + @Override int compareTo(RTKVersion o) { if (this.major != o.major) { - return Integer.compare(this.major, o.major); + return Integer.compare(this.major, o.major) } if (this.majorB != o.majorB) { - return Integer.compare(this.majorB, o.majorB); + return Integer.compare(this.majorB, o.majorB) } if (this.minor != o.minor) { - return Integer.compare(this.minor, o.minor); + return Integer.compare(this.minor, o.minor) } if (this.patch != o.patch) { - return Integer.compare(this.patch, o.patch); + return Integer.compare(this.patch, o.patch) } - if (this.rt != o.rc) { - return Integer.compare(this.rt, o.rt); + if (this.rt != o.rt) { + return Integer.compare(this.rt, o.rt) } // Same version @@ -115,11 +158,15 @@ class kVersion implements Comparable { // Retrieve parameters of the current build -def mversion = build.buildVariableResolver.resolve('mversion') +def mbranch = build.getEnvironment(listener).get('GIT_BRANCH').minus('origin/') def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild') def kgitrepo = build.buildVariableResolver.resolve('kgitrepo') -def kverfloor = new kVersion(build.buildVariableResolver.resolve('kverfloor')) +def kverfloor_raw = build.buildVariableResolver.resolve('kverfloor') +def kverceil_raw = build.buildVariableResolver.resolve('kverceil') +def kverfilter = build.buildVariableResolver.resolve('kverfilter') def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob')) +def currentJobName = build.project.getFullDisplayName() +def gitmodpath = build.getEnvironment(listener).get('WORKSPACE') + "/src/lttng-modules" // Get the out variable def config = new HashMap() @@ -127,29 +174,113 @@ def bindings = getBinding() config.putAll(bindings.getVariables()) def out = config['out'] -def jlc = new jenkins.model.JenkinsLocationConfiguration() -def jenkinsUrl = jlc.url + +// Get the lttng-modules git url +def gitmodrepo = Git.open(new File(gitmodpath)) +def mgitrepo = gitmodrepo.getRepository().getConfig().getString("remote", "origin", "url") // Get tags from git repository -def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call(); +def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call() // Get kernel versions to build def kversions = [] +def tagMatchStrs = [ + ~/^refs\/tags\/(v[\d\.]+(-rt(\d+)-rebase))$/, +] +def blacklist = [ + ~/v4\.11\.8-rt5-rebase/, + ~/v4\.11\.9-rt6-rebase/, + ~/v4\.11\.9-rt7-rebase/, + ~/v4\.11\.12-rt8-rebase/, + ~/v4\.11\.12-rt9-rebase/, + ~/v4\.11\.12-rt10-rebase/, + ~/v4\.11\.12-rt11-rebase/, + ~/v4\.11\.12-rt12-rebase/, + ~/v4\.11\.12-rt13-rebase/, + ~/v4\.19.*-rebase/, + ~/v3\.6.*-rebase/, + ~/v3\.8.*-rebase/, +] + +def kversionFactory = new RTKVersion() + +// Parse kernel versions +def kverfloor = "" +try { + kverfloor = kversionFactory.factory(kverfloor_raw) +} catch (EmptyKVersionException e) { + kverfloor = kversionFactory.minKVersion() +} + +def kverceil = "" +try { + kverceil = kversionFactory.factory(kverceil_raw) +} catch (EmptyKVersionException e) { + kverceil = kversionFactory.maxKVersion() +} + +// Build a sorted list of versions to build for (ref in refs) { - def match = ref.getName() =~ /^refs\/tags\/(v[\d\.]+(-rt(\d+)-rebase))$/ + for (tagMatchStr in tagMatchStrs) { + def tagMatch = ref.getName() =~ tagMatchStr + + if (tagMatch) { + def kversion_raw = tagMatch.group(1) + def blacklisted = false + + // Check if the kversion is blacklisted + for (blackMatchStr in blacklist) { + def blackMatch = kversion_raw =~ blackMatchStr + + if (blackMatch) { + blacklisted = true + break; + } + } - if (match) { - def v = new kVersion(match.group(1)) + if (!blacklisted) { + def v = kversionFactory.factory(kversion_raw) - if (v >= kverfloor) { - kversions.add(v) + if ((v >= kverfloor) && (v < kverceil)) { + kversions.add(v) + } + } } } } kversions.sort() -// Debug +//println "Pre filtering kernel versions:" +//for (k in kversions) { +// println k +//} + +switch (kverfilter) { + case 'stable-head': + // Keep only the head of each stable branch + println('Filter kernel versions to keep only the latest point release of each stable branch.') + + for (i = 0; i < kversions.size(); i++) { + def curr = kversions[i] + def next = i < kversions.size() - 1 ? kversions[i + 1] : null + + if (next != null) { + if (curr.isSameStable(next)) { + kversions.remove(i) + i-- + } + } + } + break + + default: + // No filtering of kernel versions + println('No kernel versions filtering selected.') + break +} + + println "Building the following kernel versions:" for (k in kversions) { println k @@ -164,6 +295,7 @@ def allBuilds = [] def ongoingBuild = [] def failedRuns = [] def isFailed = false +def similarJobQueued = 0; // Loop while we have kernel versions remaining or jobs running while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { @@ -171,14 +303,15 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) { def kversion = kversions.pop() def job_params = [ - new StringParameterValue('mversion', mversion), - new StringParameterValue('kversion', kversion.toString()), + new StringParameterValue('mversion', mbranch), + new StringParameterValue('mgitrepo', mgitrepo), + new StringParameterValue('ktag', kversion.toString()), new StringParameterValue('kgitrepo', kgitrepo), ] // Launch the parametrized build def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params)) - println "triggering ${joburl} for the ${mversion} branch on kernel ${kversion}" + println "triggering ${joburl} for the ${mbranch} branch on kernel ${kversion}" // Add it to the ongoing build queue ongoingBuild.push(param_build) @@ -187,7 +320,7 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size() try { - Thread.sleep(5000) + Thread.sleep(10000) } catch(e) { if (e in InterruptedException) { build.setResult(hudson.model.Result.ABORTED) @@ -197,6 +330,13 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { } } + // Abort job if a newer instance is queued + similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName} + if ( similarJobQueued > 0 ) { + build.setResult(hudson.model.Result.ABORTED) + throw new InterruptedException() + } + def i = ongoingBuild.iterator() while ( i.hasNext() ) { currentBuild = i.next() @@ -207,7 +347,7 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { // Print results def matrixParent = currentBuild.get() allBuilds.add(matrixParent) - def kernelStr = matrixParent.buildVariableResolver.resolve("kversion") + def kernelStr = matrixParent.buildVariableResolver.resolve("ktag") println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}" // Process child runs of matrixBuild @@ -233,15 +373,17 @@ for (failedRun in failedRuns) { println "---Build report---" for (b in allBuilds) { - def kernelStr = b.buildVariableResolver.resolve("kversion") + def kernelStr = b.buildVariableResolver.resolve("ktag") println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}" // Cleanup builds - b.delete() + try { + b.delete() + } catch (all) {} } // Mark this build failed if any child build has failed if (isFailed) { - build.getExecutor().interrupt(Result.FAILURE) + build.setResult(hudson.model.Result.FAILURE) } // EOF