forked from metrumresearchgroup/math
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
456 lines (443 loc) · 19.7 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
#!/usr/bin/env groovy
@Library('StanUtils')
import org.stan.Utils
def runTests(String testPath, boolean jumbo = false) {
try {
if (jumbo) {
sh "./runTests.py -j${env.PARALLEL} ${testPath} --jumbo"
} else {
sh "./runTests.py -j${env.PARALLEL} ${testPath}"
}
}
finally { junit 'test/**/*.xml' }
}
def runTestsWin(String testPath, boolean buildLibs = true, boolean jumbo = false) {
withEnv(['PATH+TBB=./lib/tbb']) {
bat "echo $PATH"
if (buildLibs){
bat "mingw32-make.exe -f make/standalone math-libs"
}
try {
if (jumbo) {
bat "runTests.py -j${env.PARALLEL} ${testPath} --jumbo"
} else {
bat "runTests.py -j${env.PARALLEL} ${testPath}"
}
}
finally { junit 'test/**/*.xml' }
}
}
def deleteDirWin() {
bat "attrib -r -s /s /d"
deleteDir()
}
def skipRemainingStages = false
def skipOpenCL = false
def utils = new org.stan.Utils()
def isBranch(String b) { env.BRANCH_NAME == b }
String alsoNotify() {
if (isBranch('master') || isBranch('develop')) {
} else ""
}
Boolean isPR() { env.CHANGE_URL != null }
String fork() { env.CHANGE_FORK ?: "stan-dev" }
String branchName() { isPR() ? env.CHANGE_BRANCH :env.BRANCH_NAME }
String cmdstan_pr() { params.cmdstan_pr ?: ( env.CHANGE_TARGET == "master" ? "downstream_hotfix" : "downstream_tests" ) }
String stan_pr() { params.stan_pr ?: ( env.CHANGE_TARGET == "master" ? "downstream_hotfix" : "downstream_tests" ) }
pipeline {
agent none
parameters {
string(defaultValue: '', name: 'cmdstan_pr', description: 'PR to test CmdStan upstream against e.g. PR-630')
string(defaultValue: '', name: 'stan_pr', description: 'PR to test Stan upstream against e.g. PR-630')
booleanParam(defaultValue: false, name: 'withRowVector', description: 'Run additional distribution tests on RowVectors (takes 5x as long)')
booleanParam(defaultValue: false, name: 'run_win_tests', description: 'Run full unit tests on Windows.')
}
options {
skipDefaultCheckout()
preserveStashes(buildCount: 7)
}
environment {
STAN_NUM_THREADS = '4'
}
stages {
stage('Kill previous builds') {
when {
not { branch 'develop' }
not { branch 'master' }
}
steps {
script {
utils.killOldBuilds()
}
}
}
stage("Clang-format") {
agent any
steps {
sh "printenv"
deleteDir()
retry(3) { checkout scm }
withCredentials([usernamePassword(credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b',
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """#!/bin/bash
set -x
git checkout -b ${branchName()}
clang-format --version
find stan test -name '*.hpp' -o -name '*.cpp' | xargs -n20 -P${env.PARALLEL} clang-format -i
if [[ `git diff` != "" ]]; then
git config --global user.email "[email protected]"
git config --global user.name "Stan Jenkins"
git add stan test
git commit -m "[Jenkins] auto-formatting by `clang-format --version`"
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${fork()}/math.git ${branchName()}
echo "Exiting build because clang-format found changes."
echo "Those changes are now found on stan-dev/math under branch ${branchName()}"
echo "Please 'git pull' before continuing to develop."
exit 1
fi"""
}
}
post {
always { deleteDir() }
failure {
script {
emailext (
subject: "[StanJenkins] Autoformattted: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' " +
"has been autoformatted and the changes committed " +
"to your branch, if permissions allowed." +
"Please pull these changes before continuing." +
"\n\n" +
"See https://github.com/stan-dev/stan/wiki/Coding-Style-and-Idioms" +
" for setting up the autoformatter locally.\n"+
"(Check console output at ${env.BUILD_URL})",
recipientProviders: [[$class: 'RequesterRecipientProvider']],
to: "${env.CHANGE_AUTHOR_EMAIL}"
)
}
}
}
}
stage('Linting & Doc checks') {
agent any
steps {
script {
deleteDir()
retry(3) { checkout scm }
sh "git clean -xffd"
stash 'MathSetup'
sh "echo CXX=${env.CXX} -Werror > make/local"
sh "echo BOOST_PARALLEL_JOBS=${env.PARALLEL} >> make/local"
parallel(
CppLint: { sh "make cpplint" },
Dependencies: { sh """#!/bin/bash
set -o pipefail
make test-math-dependencies 2>&1 | tee dependencies.log""" } ,
Documentation: { sh "make doxygen" },
)
}
}
post {
always {
recordIssues enabledForFailure: true, tools:
[cppLint(),
groovyScript(parserId: 'mathDependencies', pattern: '**/dependencies.log')]
deleteDir()
}
}
}
stage('Verify changes') {
agent { label 'linux' }
steps {
script {
retry(3) { checkout scm }
sh 'git clean -xffd'
def paths = ['stan', 'make', 'lib', 'test', 'runTests.py', 'runChecks.py', 'makefile', 'Jenkinsfile', '.clang-format'].join(" ")
skipRemainingStages = utils.verifyChanges(paths)
def openCLPaths = ['stan/math/opencl', 'test/unit/math/opencl'].join(" ")
skipOpenCL = utils.verifyChanges(openCLPaths)
}
}
}
stage('Headers check') {
when {
expression {
!skipRemainingStages
}
}
agent any
steps {
deleteDir()
unstash 'MathSetup'
sh "echo CXX=${env.CXX} -Werror > make/local"
sh "make -j${env.PARALLEL} test-headers"
}
post { always { deleteDir() } }
}
stage('Full Unit Tests') {
agent any
when {
expression {
!skipRemainingStages
}
}
steps {
deleteDir()
unstash 'MathSetup'
sh "echo CXXFLAGS += -fsanitize=address > make/local"
script {
if (isUnix()) {
runTests("test/unit", true)
} else {
runTestsWin("test/unit", true)
}
}
}
post { always { retry(3) { deleteDir() } } }
}
stage('Always-run tests') {
when {
expression {
!skipRemainingStages
}
}
failFast true
parallel {
stage('MPI tests') {
agent { label 'linux && mpi' }
steps {
deleteDir()
unstash 'MathSetup'
sh "echo CXX=${MPICXX} >> make/local"
sh "echo CXX_TYPE=gcc >> make/local"
sh "echo STAN_MPI=true >> make/local"
runTests("test/unit/math/prim/functor")
runTests("test/unit/math/rev/functor")
}
post { always { retry(3) { deleteDir() } } }
}
stage('OpenCL CPU tests') {
when {
expression {
!skipOpenCL
}
}
agent { label "gelman-group-win2 || linux-gpu" }
steps {
script {
if (isUnix()) {
deleteDir()
unstash 'MathSetup'
sh "echo CXX=${env.CXX} -Werror > make/local"
sh "echo STAN_OPENCL=true>> make/local"
sh "echo OPENCL_PLATFORM_ID=${env.OPENCL_PLATFORM_ID_CPU}>> make/local"
sh "echo OPENCL_DEVICE_ID=${env.OPENCL_DEVICE_ID_CPU}>> make/local"
runTests("test/unit/math/opencl", false)
runTests("test/unit/multiple_translation_units_test.cpp")
} else {
deleteDirWin()
unstash 'MathSetup'
bat "echo CXX=${env.CXX} -Werror > make/local"
bat "echo STAN_OPENCL=true >> make/local"
bat "echo OPENCL_PLATFORM_ID=${env.OPENCL_PLATFORM_ID_CPU} >> make/local"
bat "echo OPENCL_DEVICE_ID=${env.OPENCL_DEVICE_ID_CPU} >> make/local"
bat 'echo LDFLAGS_OPENCL= -L"C:\\Program Files (x86)\\IntelSWTools\\system_studio_2020\\OpenCL\\sdk\\lib\\x64" -lOpenCL >> make/local'
bat "mingw32-make.exe -f make/standalone math-libs"
runTestsWin("test/unit/math/opencl", false, false)
runTestsWin("test/unit/multiple_translation_units_test.cpp", false, false)
}
}
}
}
stage('OpenCL GPU tests') {
agent { label "gelman-group-win2 || linux-gpu" }
steps {
script {
if (isUnix()) {
deleteDir()
unstash 'MathSetup'
sh "echo CXX=${env.CXX} -Werror > make/local"
sh "echo STAN_OPENCL=true>> make/local"
sh "echo OPENCL_PLATFORM_ID=${env.OPENCL_PLATFORM_ID_GPU} >> make/local"
sh "echo OPENCL_DEVICE_ID=${env.OPENCL_DEVICE_ID_GPU} >> make/local"
runTests("test/unit/math/opencl", false)
runTests("test/unit/multiple_translation_units_test.cpp")
} else {
deleteDirWin()
unstash 'MathSetup'
bat "echo CXX=${env.CXX} -Werror > make/local"
bat "echo STAN_OPENCL=true >> make/local"
bat "echo OPENCL_PLATFORM_ID=${env.OPENCL_PLATFORM_ID_GPU} >> make/local"
bat "echo OPENCL_DEVICE_ID=${env.OPENCL_DEVICE_ID_GPU} >> make/local"
bat 'echo LDFLAGS_OPENCL= -L"C:\\Program Files (x86)\\IntelSWTools\\system_studio_2020\\OpenCL\\sdk\\lib\\x64" -lOpenCL >> make/local'
bat "mingw32-make.exe -f make/standalone math-libs"
runTestsWin("test/unit/math/opencl", false, false)
runTestsWin("test/unit/multiple_translation_units_test.cpp", false, false)
}
}
}
}
stage('Distribution tests') {
agent { label "distribution-tests" }
steps {
deleteDir()
unstash 'MathSetup'
sh """
echo CXX=${env.CXX} > make/local
echo O=0 >> make/local
echo N_TESTS=${env.N_TESTS} >> make/local
"""
script {
if (params.withRowVector || isBranch('develop') || isBranch('master')) {
sh "echo CXXFLAGS+=-DSTAN_TEST_ROW_VECTORS >> make/local"
sh "echo CXXFLAGS+=-DSTAN_PROB_TEST_ALL >> make/local"
}
}
sh "./runTests.py -j${env.PARALLEL} test/prob > dist.log 2>&1"
}
post {
always {
script { zip zipFile: "dist.log.zip", archive: true, glob: 'dist.log' }
retry(3) { deleteDir() }
}
failure {
echo "Distribution tests failed. Check out dist.log.zip artifact for test logs."
}
}
}
stage('Expressions test') {
agent any
steps {
unstash 'MathSetup'
script {
sh "echo O=0 > make/local"
sh "python ./test/code_generator_test.py"
sh "python ./test/signature_parser_test.py"
sh "python ./test/statement_types_test.py"
sh "python ./test/varmat_compatibility_summary_test.py"
sh "python ./test/varmat_compatibility_test.py"
withEnv(['PATH+TBB=./lib/tbb']) {
sh "python ./test/expressions/test_expression_testing_framework.py"
}
withEnv(['PATH+TBB=./lib/tbb']) {
try { sh "./runTests.py -j${env.PARALLEL} test/expressions" }
finally { junit 'test/**/*.xml' }
}
sh "make clean-all"
sh "echo STAN_THREADS=true >> make/local"
withEnv(['PATH+TBB=./lib/tbb']) {
try {
sh "./runTests.py -j${env.PARALLEL} test/expressions --only-functions reduce_sum map_rect"
}
finally { junit 'test/**/*.xml' }
}
}
}
post { always { deleteDir() } }
}
stage('Threading tests') {
agent any
steps {
script {
deleteDir()
unstash 'MathSetup'
sh "echo CXX=${env.CXX} -Werror > make/local"
sh "echo STAN_THREADS=true >> make/local"
sh "export STAN_NUM_THREADS=4"
if (isBranch('develop') || isBranch('master')) {
runTests("test/unit")
sh "find . -name *_test.xml | xargs rm"
} else {
runTests("test/unit -f thread")
sh "find . -name *_test.xml | xargs rm"
runTests("test/unit -f map_rect")
sh "find . -name *_test.xml | xargs rm"
runTests("test/unit -f reduce_sum")
}
}
}
post { always { retry(3) { deleteDir() } } }
}
stage('Windows Headers & Unit') {
when {
allOf {
anyOf {
branch 'develop'
branch 'master'
expression { params.run_win_tests }
}
expression {
!skipRemainingStages
}
}
}
agent { label 'windows' }
steps {
deleteDirWin()
unstash 'MathSetup'
bat "mingw32-make.exe -f make/standalone math-libs"
runTestsWin("test/unit", false, false)
}
}
}
}
stage('Upstream tests') {
when {
allOf {
expression {
env.BRANCH_NAME ==~ /PR-\d+/
}
expression {
!skipRemainingStages
}
}
}
steps {
build(job: "Stan/${stan_pr()}",
parameters: [string(name: 'math_pr', value: env.BRANCH_NAME),
string(name: 'cmdstan_pr', value: cmdstan_pr())])
}
}
stage('Upload doxygen') {
agent any
when { branch 'develop'}
steps {
deleteDir()
retry(3) { checkout scm }
withCredentials([usernamePassword(credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b',
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """#!/bin/bash
set -x
make doxygen
git config --global user.email "[email protected]"
git config --global user.name "Stan Jenkins"
git checkout --detach
git branch -D gh-pages
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/stan-dev/math.git :gh-pages
git checkout --orphan gh-pages
git add -f doc
git commit -m "auto generated docs from Jenkins"
git subtree push --prefix doc/api/html https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/stan-dev/math.git gh-pages
"""
}
}
post { always { deleteDir() } }
}
}
post {
always {
node("osx || linux") {
recordIssues enabledForFailure: false, tool: clang()
}
}
success {
script {
utils.updateUpstream(env, 'stan')
utils.mailBuildResults("SUCCESSFUL")
}
}
unstable { script { utils.mailBuildResults("UNSTABLE", alsoNotify()) } }
failure { script { utils.mailBuildResults("FAILURE", alsoNotify()) } }
}
}