@@ -14,7 +14,7 @@ def runTests(String testPath, boolean jumbo = false) {
1414}
1515
1616def skipRemainingStages = false
17-
17+ def changedDistributionTests = []
1818def utils = new org.stan.Utils ()
1919
2020def isBranch (String b ) { env. BRANCH_NAME == b }
@@ -38,11 +38,12 @@ pipeline {
3838 booleanParam(defaultValue : false , name : ' withRowVector' , description : ' Run additional distribution tests on RowVectors (takes 5x as long)' )
3939 booleanParam(defaultValue : false , name : ' disableJumbo' , description : ' Disable Jumbo tests. This takes longer and should only be used for debugging if it is believed that the jumbo tests are causing failures.' )
4040 booleanParam(defaultValue : false , name : ' optimizeUnitTests' , description : ' Use O=3 for unit tests (takex ~3x as long)' )
41+ booleanParam(defaultValue : false , name : ' runAllDistributions' , description : ' Run all distribution tests, even ones which are unchanged compared to develop' )
4142 }
4243 options {
4344 skipDefaultCheckout()
4445 preserveStashes(buildCount : 7 )
45- parallelsAlwaysFailFast()
46+ parallelsAlwaysFailFast()
4647 }
4748 environment {
4849 STAN_NUM_THREADS = 4
@@ -57,6 +58,10 @@ pipeline {
5758 OPENCL_PLATFORM_ID_CPU = 0
5859 OPENCL_PLATFORM_ID_GPU = 0
5960 PARALLEL = 4
61+ GIT_AUTHOR_NAME = ' Stan Jenkins'
62+ GIT_AUTHOR_EMAIL = ' mc.stanislaw@gmail.com'
63+ GIT_COMMITTER_NAME = ' Stan Jenkins'
64+ GIT_COMMITTER_EMAIL = ' mc.stanislaw@gmail.com'
6065 }
6166 stages {
6267
@@ -85,14 +90,12 @@ pipeline {
8590 usernameVariable : ' GIT_USERNAME' , passwordVariable : ' GIT_PASSWORD' )]) {
8691 sh """ #!/bin/bash
8792 set -x
88- git config user.email "mc.stanislaw@gmail.com"
89- git config user.name "Stan Jenkins"
9093 git checkout -b ${ branchName()}
9194 clang-format --version
9295 find stan test -name '*.hpp' -o -name '*.cpp' | xargs -n20 -P${ PARALLEL} clang-format -i
9396 if [[ `git diff` != "" ]]; then
9497 git add stan test
95- git commit --author='Stan BuildBot <mc.stanislaw@gmail.com>' - m "[Jenkins] auto-formatting by `clang-format --version`"
98+ git commit -m "[Jenkins] auto-formatting by `clang-format --version`"
9699 git push https://${ GIT_USERNAME} :${ GIT_PASSWORD} @github.com/${ fork()} /math.git ${ branchName()}
97100 echo "Exiting build because clang-format found changes."
98101 echo "Those changes are now found on stan-dev/math under branch ${ branchName()} "
@@ -121,7 +124,7 @@ pipeline {
121124 }
122125 }
123126 }
124- }
127+ }
125128
126129 stage(' Linting & Doc checks' ) {
127130 agent {
@@ -175,27 +178,65 @@ pipeline {
175178
176179 }
177180 }
181+ post { always { retry(3 ) { deleteDir() } } }
178182 }
179183
180- stage(' Headers check' ) {
181- agent {
182- docker {
183- image ' stanorg/ci:gpu-cpp17'
184- label ' linux'
185- }
186- }
184+ stage(' Quick tests' ) {
187185 when {
188186 expression {
189187 ! skipRemainingStages
190188 }
191189 }
192- steps {
193- unstash ' MathSetup'
194- sh " echo CXX=${ CLANG_CXX} -Werror > make/local"
195- sh " echo O=0 >> make/local"
196- sh " make -j${ PARALLEL} test-headers"
190+ failFast true
191+ parallel {
192+ stage(' Headers check' ) {
193+ when {
194+ expression {
195+ ! skipRemainingStages
196+ }
197+ }
198+ agent {
199+ docker {
200+ image ' stanorg/ci:gpu-cpp17'
201+ label ' linux'
202+ }
203+ }
204+
205+ steps {
206+ unstash ' MathSetup'
207+ sh " echo CXX=${ CLANG_CXX} -Werror > make/local"
208+ sh " make -j${ PARALLEL} test-headers"
209+ }
210+ post { always { deleteDir() } }
211+ }
212+ stage(' Run changed unit tests' ) {
213+ agent {
214+ docker {
215+ image ' stanorg/ci:gpu-cpp17'
216+ label ' linux'
217+ args ' --cap-add SYS_PTRACE'
218+ }
219+ }
220+ when {
221+ allOf {
222+ expression {
223+ env. BRANCH_NAME ==~ / PR-\d +/
224+ }
225+ expression {
226+ ! skipRemainingStages
227+ }
228+ }
229+ }
230+ steps {
231+ retry(3 ) { checkout scm }
232+
233+ sh " echo CXXFLAGS += -fsanitize=address >> make/local"
234+ sh " ./runTests.py -j${ PARALLEL} --changed --debug"
235+
236+ }
237+ post { always { retry(3 ) { deleteDir() } } }
238+ }
197239 }
198- post { always { deleteDir() } }
199240 }
200241
201242 stage(' Full Unit Tests' ) {
@@ -406,35 +447,66 @@ pipeline {
406447 }
407448 }
408449
409- stage (' Distribution tests' ) {
450+ stage (' Discover changed distribution tests' ) {
410451 when {
411452 expression {
412453 ! skipRemainingStages
413454 }
414455 }
456+ agent {
457+ docker {
458+ image ' stanorg/ci:gpu-cpp17'
459+ label ' linux'
460+ }
461+ }
462+ steps {
463+ script {
464+ retry(3 ) { checkout scm }
465+ if (params. runAllDistributions || isBranch(' develop' ) || isBranch(' master' )) {
466+ changedDistributionTests = sh(script :" python3 test/prob/getDependencies.py --pretend-all" , returnStdout :true ). trim(). readLines()
467+ } else {
468+ changedDistributionTests = sh(script :" python3 test/prob/getDependencies.py" , returnStdout :true ). trim(). readLines()
469+ }
470+ }
471+ }
472+ }
473+
474+ stage (' Distribution tests' ) {
475+ when {
476+ allOf {
477+ expression {
478+ ! skipRemainingStages
479+ }
480+ expression {
481+ ! changedDistributionTests. isEmpty()
482+ }
483+ }
484+ }
415485 agent { label ' linux && docker' }
416486 steps {
417487 script {
418- unstash ' MathSetup'
419488 def tests = [:]
420- def files = sh(script :" find test/prob/* -type d" , returnStdout :true ). trim(). split(' \n ' )
421- for (f in files. toList(). collate(8 )) {
489+ for (f in changedDistributionTests. collate(24 )) {
422490 def names = f. join(" " )
423491 tests[" Distribution Tests: ${ names} " ] = { node (" linux && docker" ) {
492+ deleteDir()
424493 docker. image(' stanorg/ci:gpu-cpp17' ). inside {
425- unstash ' MathSetup'
426- sh """
427- echo CXX=${ CLANG_CXX} > make/local
428- echo O=0 >> make/local
429- echo N_TESTS=${ N_TESTS} >> make/local
430- """
431- script {
432- if (params. withRowVector || isBranch(' develop' ) || isBranch(' master' )) {
433- sh " echo CXXFLAGS+=-DSTAN_TEST_ROW_VECTORS >> make/local"
434- sh " echo CXXFLAGS+=-DSTAN_PROB_TEST_ALL >> make/local"
494+ catchError {
495+ unstash ' MathSetup'
496+ sh """
497+ echo CXX=${ CLANG_CXX} > make/local
498+ echo O=0 >> make/local
499+ echo N_TESTS=${ N_TESTS} >> make/local
500+ """
501+ script {
502+ if (params. withRowVector || isBranch(' develop' ) || isBranch(' master' )) {
503+ sh " echo CXXFLAGS+=-DSTAN_TEST_ROW_VECTORS >> make/local"
504+ sh " echo CXXFLAGS+=-DSTAN_PROB_TEST_ALL >> make/local"
505+ }
435506 }
507+ sh " ./runTests.py -j${ PARALLEL} ${ names} "
436508 }
437- sh " ./runTests.py -j ${ PARALLEL } ${ names } "
509+ deleteDir()
438510 }
439511 } }
440512 }
0 commit comments