Rename KernelVersion To basicVersion
[lttng-ci.git] / dsl / kernel-lttng-modules.seed.groovy
1 enum KernelVersioning {
2 MAJOR,MINOR,REVISION,BUILD
3 }
4
5 class BasicVersion implements Comparable<BasicVersion> {
6 int major = -1
7 int minor = -1
8 int revision = -1
9 int build = -1
10 int rc = -1
11 String gitRefs
12
13 // Default Constructor
14 BasicVersion() {}
15
16 // Parse a version string of format X.Y.Z.W-A
17 BasicVersion(String version, String ref) {
18 gitRefs = ref
19 def tokenVersion
20 def token
21 if (version.contains('-')) {
22 // Release canditate
23 token = version.tokenize('-')
24 tokenVersion = token[0]
25 if (token[1]?.isInteger()) {
26 rc = token[1].toInteger()
27 }
28 } else {
29 tokenVersion = version
30 }
31
32 tokenVersion = tokenVersion.tokenize('.')
33
34 def tagEnum = KernelVersioning.MAJOR
35 tokenVersion.each {
36 if (it?.isInteger()) {
37 switch (tagEnum) {
38 case KernelVersioning.MAJOR:
39 major = it.toInteger()
40 tagEnum = KernelVersioning.MINOR
41 break
42 case KernelVersioning.MINOR:
43 minor = it.toInteger()
44 tagEnum = KernelVersioning.REVISION
45 break
46 case KernelVersioning.REVISION:
47 revision = it.toInteger()
48 tagEnum = KernelVersioning.BUILD
49 break
50 case KernelVersioning.BUILD:
51 build = it.toInteger()
52 tagEnum = -1
53 break
54 default:
55 println("Unsupported version extension")
56 println("Trying to parse: ${version}")
57 println("Invalid sub version value: ${it}")
58 //TODO: throw exception for jenkins
59 }
60 }
61 }
62 }
63
64 String print() {
65 String ret = ""
66 if (major != -1) {
67 ret += major
68 if (minor != -1) {
69 ret += "." + minor
70 if (revision != -1) {
71 ret += "." + revision
72 if (build != -1) {
73 ret += "." + build
74 }
75 }
76 }
77 if (rc != -1) {
78 ret += "-rc" + rc
79 }
80 }
81 return ret
82 }
83
84 @Override
85 int compareTo(BasicVersion kernelVersion) {
86 return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc
87 }
88 }
89
90 def cutoff = new BasicVersion("3.19", "")
91 def modulesBranches = ["master","stable-2.5.0","stable-2.6.0"]
92 def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
93 def modulesURL = "git://git.lttng.org/lttng-modules.git"
94
95 // Linux specific variable
96 String linuxCheckoutTo = "linux-source"
97 String recipeCheckoutTo = "recipe"
98 String modulesCheckoutTo = "lttng-modules"
99
100 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
101 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
102
103 // Chekf if we are on jenkins
104 // Useful for outside jenkins devellopment related to groovy only scripting
105 def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
106
107 // Split the string into sections based on |
108 // And pipe the results together
109 def out = new StringBuilder()
110 def err = new StringBuilder()
111 Process result = process.tokenize( '|' ).inject( null ) { p, c ->
112 if( p )
113 p | c.execute()
114 else
115 c.execute()
116 }
117
118 result.waitForProcessOutput(out,err)
119
120 if ( result.exitValue() == 0 ) {
121 def branches = out.readLines().collect {
122 // Scrap special string tag
123 it.replaceAll("\\^\\{\\}", '')
124 }
125
126 branches = branches.unique()
127
128 List versions = []
129 branches.each { branch ->
130 def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
131 KernelVersion kVersion = new KernelVersion(stripBranch, branch)
132 versions.add(kVersion)
133 }
134
135 // Sort the version via Comparable implementation of KernelVersion
136 versions = versions.sort()
137
138 // Find the version cut of
139 def cutoffPos = versions.findIndexOf{(it.major >= cutoff.major) && (it.minor >= cutoff.minor) && (it.revision >= cutoff.revision) && (it.build >= cutoff.build) && (it.rc >= cutoff.rc)}
140
141 // Get last version and include only last rc
142 def last
143 def lastNoRcPos
144 last = versions.last()
145 if (last.rc != -1) {
146 int i = versions.size()-1
147 while (i > -1 && versions[i].rc != -1 ) {
148 i--
149 }
150 lastNoRcPos = i + 1
151 } else {
152 lastNoRcPos = versions.size()
153 }
154
155 // Actual job creation
156 for (int i = cutoffPos; i < versions.size() ; i++) {
157
158 // Only create for valid build
159 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
160 println ("Preparing job for")
161 String kernel = versions[i].print()
162 String jobName = "kernel-${kernel}"
163 String moduleJobName = "lttng-modules-master-kernel-${kernel}"
164 println(jobName)
165 println(moduleJobName)
166
167 // Jenkins only dsl
168 if (isJenkinsInstance) {
169 matrixJob("${jobName}") {
170 using("linux-master")
171 scm {
172 git {
173 remote {
174 url("${linuxURL}")
175 }
176 branch(versions[i].gitRefs)
177 shallowClone(true)
178 relativeTargetDir(linuxCheckoutTo)
179 reference(linuxGitReference)
180 }
181 }
182 publishers {
183 downstream(moduleJobName, 'SUCCESS')
184 }
185 }
186 // Corresponding Module job
187 matrixJob("${moduleJobName}") {
188 using("modules")
189 multiscm {
190 git {
191 remote {
192 name("linux")
193 url("${linuxURL}")
194 }
195 branch(versions[i].gitRefs)
196 shallowClone(true)
197 relativeTargetDir(linuxCheckoutTo)
198 reference(linuxGitReference)
199 }
200 git {
201 remote {
202 name("lttng-modules")
203 url(modulesURL)
204 }
205 branch("master")
206 relativeTargetDir(modulesCheckoutTo)
207 }
208 }
209 steps {
210 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
211 latestSuccessful(true) // Latest successful build
212 }
213 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
214 }
215 }
216 }
217 }
218 }
219 }
This page took 0.035305 seconds and 5 git commands to generate.