/
Jenkinsfile
397 lines (343 loc) · 15.8 KB
/
Jenkinsfile
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
import groovy.transform.Field
@Library('sw-jenkins-library@1c4f7b55ac3559620ccbc54a847f5bb46c172619') _
enum BuildScope {
SANITY, HOURLY, NIGHTLY
}
@Field
def isolatedTestPythonVersionsForBuildScope = [
(BuildScope.SANITY) : ["3.8", "3.9"],
(BuildScope.HOURLY) : ["3.8", "3.10", "3.11"],
(BuildScope.NIGHTLY) : ["3.8", "3.9", "3.10", "3.11", "3.12"],
]
@Field
def integrationTestPythonVersionsForBuildScope = [
(BuildScope.SANITY) : ["3.8"],
(BuildScope.HOURLY) : ["3.9"],
(BuildScope.NIGHTLY) : ["3.8", "3.9", "3.10", "3.11", "3.12"],
]
@Field
def integrationTestA121RssVersionsForBuildScope = [
(BuildScope.SANITY) : [branch: "master"],
(BuildScope.HOURLY) : [tag: "a121-v1.6.0"],
(BuildScope.NIGHTLY) : [branch: "master", tag: "a121-v1.6.0"],
]
@Field
def integrationTestA111RssVersionsForBuildScope = [
(BuildScope.SANITY) : [branch: "master"],
(BuildScope.HOURLY) : [],
(BuildScope.NIGHTLY) : [branch: "master", tag: "a111-v2.15.4"],
]
@Field
def modelTestA121RssVersionForBuildScope = [
(BuildScope.SANITY) : [tag: "a121-v1.6.0"],
(BuildScope.HOURLY) : [],
(BuildScope.NIGHTLY) : [],
]
String dockerArgs(env_map) {
return "--hostname ${env_map.NODE_NAME}" +
" --mount type=volume,src=cachepip-${env_map.EXECUTOR_NUMBER},dst=/home/jenkins/.cache/pip"
}
def messageOnFailure = true
def getCronTriggers(String branchName) {
def triggers = []
if (branchName == 'master') {
// Hourly: every hour between 9:00 & 17:00, Monday through Friday
// Nightly: every day at 23:00
triggers << cron("0 9-17 * * 1-5\n0 23 * * *")
}
return pipelineTriggers(triggers)
}
BuildScope getBuildScope() {
if (currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').isEmpty()) {
// currentBuild was not triggered by a cron timer
// => probably triggered by a change
// => run sanity scope.
return BuildScope.SANITY
}
def hour = new Date()[Calendar.HOUR_OF_DAY]
if (hour <= 17) {
return BuildScope.HOURLY
} else {
return BuildScope.NIGHTLY
}
}
def finishBuild(messageOnFailure) {
stage('Report to gerrit') {
int score = currentBuild.currentResult == 'SUCCESS' ? 1 : -1
String success = currentBuild.currentResult == 'SUCCESS' ? "success" : "failure"
String message = "${currentBuild.currentResult}: ${env.BUILD_URL}, Duration: ${currentBuild.durationString - ' and counting'}"
gerritReview labels: [Verified: score], message: message
}
if (messageOnFailure && (currentBuild.currentResult == 'FAILURE')) {
withCredentials([string(credentialsId: 'teams-robot', variable: 'TEAMS_API_TOKEN')]) {
office365ConnectorSend webhookUrl: TEAMS_API_TOKEN
}
}
}
try {
// Ensure cron triggers are setup (for periodic jobs)
properties([getCronTriggers(env.BRANCH_NAME)])
def buildScope = getBuildScope()
def isolatedTestPythonVersions = isolatedTestPythonVersionsForBuildScope[buildScope]
def integrationTestPythonVersions = integrationTestPythonVersionsForBuildScope[buildScope]
def integrationTestA121RssVersions = integrationTestA121RssVersionsForBuildScope[buildScope]
def integrationTestA111RssVersions = integrationTestA111RssVersionsForBuildScope[buildScope]
def modelTestA121RssVersion = modelTestA121RssVersionForBuildScope[buildScope]
if (env.BRANCH_NAME =~ /[0-9]+\/[0-9]+\/[0-9]+/) {
buildType = "change"
messageOnFailure = false
}
stage('Report start to Gerrit') {
gerritReview labels: [Verified: 0], message: "Test started:: ${env.BUILD_URL}, Scope: ${buildScope}"
}
// Meant to catch common (and fast to detect) errors.
stage('Lint') {
node('docker') {
ws('workspace/exptool') {
printNodeInfo()
checkoutAndCleanup()
buildDocker(path: 'docker').inside(dockerArgs(env)) {
sh 'python3 -V'
sh 'nox -s lint'
}
}
}
}
parallel_steps = [:]
parallel_steps['Build package & documentation'] = {
node('docker') {
ws('workspace/exptool') {
stage('Build package & documentation') {
printNodeInfo()
checkoutAndCleanup()
buildDocker(path: 'docker').inside(dockerArgs(env)) {
sh 'python3 -V'
sh 'python3 -m build'
sh 'nox -s docs -- --docs-builders html latexpdf rediraffecheckdiff'
}
archiveArtifacts artifacts: 'dist/*', allowEmptyArchive: true
archiveArtifacts artifacts: 'docs/_build/latex/*.pdf', allowEmptyArchive: true
stash includes: 'dist/**', name: 'dist'
}
}
}
}
parallel_steps['Mypy'] = {
node('docker') {
ws('workspace/exptool') {
stage('Mypy') {
printNodeInfo()
checkoutAndCleanup()
buildDocker(path: 'docker').inside(dockerArgs(env)) {
sh '''nox -s "mypy(python='3.8')"'''
}
}
}
}
}
parallel_steps["Model Regression Tests (${modelTestA121RssVersion})"] = {
node('docker') {
ws('workspace/exptool') {
modelTestA121RssVersion.each { rssVersion ->
stage('Setup') {
printNodeInfo()
checkoutAndCleanup()
findBuildAndCopyArtifacts(
[
projectName: 'sw-main',
artifactNames: ["out/internal_stash_python_libs.tgz"],
] << rssVersion // e.g. [branch: 'master'] or [tag: 'a121-vX.Y.Z']
)
sh 'mkdir -p stash'
sh 'tar -xzf out/internal_stash_python_libs.tgz -C stash'
}
stage("Model Regression Tests (rss=${modelTestA121RssVersion})") {
buildDocker(path: 'docker').inside(dockerArgs(env)) {
sh '''nox -s test -p 3.8 -- --test-groups model'''
}
}
}
}
}
}
parallel_steps["Isolated tests (${isolatedTestPythonVersions})"] = {
node('docker') {
ws('workspace/exptool') {
stage("Isolated tests (${isolatedTestPythonVersions})") {
printNodeInfo()
checkoutAndCleanup()
buildDocker(path: 'docker').inside(dockerArgs(env)) {
isolatedTestPythonVersions.each { v -> sh "python${v} -V" }
List<String> doitTasks = isolatedTestPythonVersions
.collect { v -> "test:${v}" }
sh "doit -f dodo.py -n ${doitTasks.size()} " + doitTasks.join(' ')
}
}
}
}
}
parallel_steps["A121 Mock test (py=${integrationTestPythonVersions}, rss=${integrationTestA121RssVersions})"] = {
node('docker') {
ws('workspace/exptool') {
integrationTestA121RssVersions.each { rssVersion ->
def rssVersionName = rssVersion.getValue()
stage("Setup (rss=${rssVersionName})") {
printNodeInfo()
checkoutAndCleanup()
findBuildAndCopyArtifacts(
[
projectName: 'sw-main',
artifactNames: ["out/internal_stash_binaries_sanitizer_a121.tgz"],
] << rssVersion // e.g. [branch: 'master'] or [tag: 'a121-vX.Y.Z']
)
findBuildAndCopyArtifacts(
[
projectName: 'sw-main',
artifactNames: ["out/internal_stash_python_libs.tgz"],
] << rssVersion // e.g. [branch: 'master'] or [tag: 'a121-vX.Y.Z']
)
sh 'mkdir stash'
sh 'tar -xzf out/internal_stash_binaries_sanitizer_a121.tgz -C stash'
sh 'tar -xzf out/internal_stash_python_libs.tgz -C stash'
}
stage("Run integration tests (py=${integrationTestPythonVersions}, rss=${rssVersionName})") {
buildDocker(path: 'docker').inside(dockerArgs(env)) {
integrationTestPythonVersions.each { v -> sh "python${v} -V" }
List<String> doitTasks = integrationTestPythonVersions
.collect { v -> "integration_test:${v}-a121" }
sh "doit -f dodo.py port_strategy=unique -n ${doitTasks.size()} " + doitTasks.join(' ')
}
}
}
}
}
}
parallel_steps["A111 Mock test (py=${integrationTestPythonVersions}, rss=${integrationTestA111RssVersions})"] = {
node('docker') {
ws('workspace/exptool') {
integrationTestA111RssVersions.each { rssVersion ->
def rssVersionName = rssVersion.getValue()
stage("Setup (rss=${rssVersionName})") {
printNodeInfo()
checkoutAndCleanup()
findBuildAndCopyArtifacts(
[
projectName: 'sw-main',
artifactNames: ["out/internal_stash_binaries_sanitizer_a111.tgz"],
] << rssVersion // e.g. [branch: 'master'] or [tag: 'a111-vX.Y.Z']
)
sh 'mkdir stash'
sh 'tar -xzf out/internal_stash_binaries_sanitizer_a111.tgz -C stash'
}
stage("Run integration tests (py=${integrationTestPythonVersions}, rss=${rssVersionName})") {
buildDocker(path: 'docker').inside(dockerArgs(env)) {
integrationTestPythonVersions.each { v -> sh "python${v} -V" }
List<String> doitTasks = integrationTestPythonVersions
.collect { v -> "integration_test:${v}-a111" }
sh "doit -f dodo.py port_strategy=unique -n ${doitTasks.size()} " + doitTasks.join(' ')
}
}
}
}
}
}
parallel_steps["XM112 test (py=${integrationTestPythonVersions}, rss=${integrationTestA111RssVersions})"] = {
node('exploration_tool') {
ws('workspace/exptool') {
integrationTestA111RssVersions.each { rssVersion ->
def rssVersionName = rssVersion.getValue()
def dockerImg = null
stage("Setup (rss=${rssVersionName})") {
printNodeInfo()
checkoutAndCleanup()
findBuildAndCopyArtifacts(
[
projectName: 'sw-main',
artifactNames: [
"out/internal_stash_python_libs.tgz",
"out/internal_stash_binaries_xm112.tgz",
]
] << rssVersion // e.g. [branch: 'master'] or [tag: 'a111-vX.Y.Z']
)
sh 'mkdir stash'
sh 'tar -xzf out/internal_stash_python_libs.tgz -C stash'
sh 'tar -xzf out/internal_stash_binaries_xm112.tgz -C stash'
dockerImg = buildDocker(path: 'docker')
}
lock("${env.NODE_NAME}-xm112") {
stage ("Flash (rss=${rssVersionName})") {
sh '(cd stash && python3 python_libs/test_utils/flash.py)'
}
dockerImg.inside(dockerArgs(env) + " --net=host --privileged") {
integrationTestPythonVersions.each { pythonVersion ->
stage("Run integration tests (py=${pythonVersion}, rss=${rssVersionName})") {
sh "tests/run-a111-xm112-integration-tests.sh ${pythonVersion}"
}
}
}
}
}
}
}
}
parallel_steps['failFast'] = true
parallel parallel_steps
// Only matches version on the form "vX.Y.Z" where X, Y, Z are integers
version_regex = /v\d+\.\d+\.\d+/
if (env.TAG_NAME ==~ version_regex) {
node('docker') {
ws('workspace/exptool') {
printNodeInfo()
checkoutAndCleanup()
buildDocker(path: 'docker').inside(dockerArgs(env)) {
env.TWINE_NON_INTERACTIVE = '1'
stage('Retrieve binaries from build step') {
unstash 'dist'
}
stage('Publish to Test PyPI') {
withCredentials([usernamePassword(credentialsId: 'testpypi', passwordVariable: 'TWINE_PASSWORD', usernameVariable: 'TWINE_USERNAME')]) {
sh 'python3 -m twine upload -r testpypi dist/*'
}
}
stage('Publish to PyPI') {
withCredentials([usernamePassword(credentialsId: 'pypi', passwordVariable: 'TWINE_PASSWORD', usernameVariable: 'TWINE_USERNAME')]) {
sh 'python3 -m twine upload dist/*'
}
}
}
}
}
}
stage('Manage release branches') {
node('docker') {
ws('workspace/exptool') {
printNodeInfo()
checkoutAndCleanup(lfs: false)
buildDocker(path: 'docker').inside(dockerArgs(env)) {
withCredentials([gitUsernamePassword(credentialsId: '1bef2b16-6cd9-4836-a014-421199e7fb0f'),
string(variable: 'RELEASE_BRANCHES', credentialsId: 'et_update_release_branches')]) {
if (buildScope == BuildScope.NIGHTLY) {
sh "git config user.name 'Jenkins Builder'"
sh "git config user.email 'ai@acconeer.com'"
sh "tests/release_branch/release_branch_update.sh -b ${env.BRANCH_NAME} -p ${RELEASE_BRANCHES}"
} else if (buildScope == BuildScope.SANITY && currentBuild.currentResult == 'SUCCESS') {
sh "tests/release_branch/release_branch_push.sh -p ${RELEASE_BRANCHES}"
}
}
}
}
}
}
stage('Report to gerrit') {
if (currentBuild.currentResult == 'SUCCESS') {
echo "Reporting OK to Gerrit"
gerritReview labels: [Verified: 1], message: "Success: ${env.BUILD_URL}, Duration: ${currentBuild.durationString - ' and counting'}"
} else {
echo "Reporting Fail to Gerrit"
gerritReview labels: [Verified: -1], message: "Failed: ${env.BUILD_URL}, Duration: ${currentBuild.durationString - ' and counting'}"
}
}
} catch (exception) {
currentBuild.result = 'FAILURE'
}
finishBuild(messageOnFailure)