-
-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathJenkinsfile
More file actions
300 lines (284 loc) · 11.4 KB
/
Copy pathJenkinsfile
File metadata and controls
300 lines (284 loc) · 11.4 KB
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
properties([
disableConcurrentBuilds(abortPrevious: true),
buildDiscarder(logRotator(numToKeepStr: '20', daysToKeepStr: '30')),
parameters([
string(defaultValue: 'develop', name: 'cmdstan_pr', description: 'PR to test CmdStan upstream against e.g. PR-630'),
string(defaultValue: 'develop', 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: '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.'),
booleanParam(defaultValue: false, name: 'optimizeUnitTests', description: 'Use O=3 for unit tests (takex ~3x as long)'),
booleanParam(defaultValue: false, name: 'runAllDistributions', description: 'Run all distribution tests, even ones which are unchanged compared to develop'),
booleanParam(defaultValue: false, name: 'run_all', description: 'Pretend all files changes'),
])
])
def image = 'stanorg/ci:v1'
def runRemainingStages = false
def CLANG_CXX = 'clang++-7'
def GCC = 'g++'
def MPICXX = 'mpicxx.openmpi'
def mainBranch = env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master'
def noOptimize = !(params.optimizeUnitTests || mainBranch)
def jumboFlags = params.disableJumbo ? '' : ' --jumbo --debug'
def runTests(String local, String args) {
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
writeFile(file: "make/local", text: local)
sh "cat make/local"
sh "make print-compiler-flags"
sh "python3 runTests.py -j\$PARALLEL $args"
}
junit 'test/**/*.xml'
sh "find test -name *.xml -delete"
}
catchError {
withEnv([
'GCC=g++',
'GIT_AUTHOR_NAME=Stan Jenkins',
'GIT_AUTHOR_EMAIL=mc.stanislaw@gmail.com',
'GIT_COMMITTER_NAME=Stan Jenkins',
'GIT_COMMITTER_EMAIL=mc.stanislaw@gmail.com'
]) {
runPod(image: image, cpus: 2) {
stage('Verify changes') {
runRemainingStages = params.run_all || filesChanged(
'stan', 'make', 'lib', 'test', 'runTests.py', 'runChecks.py', 'makefile', 'Jenkinsfile', '.clang-format')
}
stage("Clang-format") {
def dirty = sh returnStatus: true, script: """
clang-format --version
git ls-files 'stan/*.hpp' 'test/*.hpp' 'stan/*.cpp' 'test/*.cpp' | xargs -n20 -P\$PARALLEL clang-format -i
git diff --exit-code
"""
if (dirty) {
def branch = env.CHANGE_BRANCH ?: env.BRANCH_NAME
def repo = env.CHANGE_FORK ?: "stan-dev"
if (!("/" in repo))
repo += "/math.git"
echo "Exiting build because clang-format found changes."
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.
See https://github.com/stan-dev/stan/wiki/Coding-Style-and-Idioms for setting
up the autoformatter locally. (Check console output at ${env.BUILD_URL})
""",
recipientProviders: [[$class: 'RequesterRecipientProvider']],
to: env.CHANGE_AUTHOR_EMAIL)
sh '''
git add -u src
git commit -m "[Jenkins] auto-formatting by `clang-format --version`"
'''
gitPush(gitScm: scmGit(
userRemoteConfigs: [[credentialsId: "stan-github", name: 'dest', url: "https://github.com/$repo"]],
branches: [[name: "refs/heads/$branch"]]),
targetBranch: branch,
targetRepo: 'dest')
echo "Those changes are now found on stan-dev/math under $repo branch $branch"
echo "Please 'git pull' before continuing to develop."
error "clang-format changes"
}
}
stage('Linting & Doc checks') {
writeFile(file: "make/local", text: "CXX=$CLANG_CXX\nBOOST_PARALLEL_JOBS=\$PARALLEL")
parallel(
CppLint: { sh "make cpplint" },
Dependencies: { sh "make test-math-dependencies" },
Documentation: { sh "make doxygen" },
)
/* TODO: recordIsuses? */
}
}
if (runRemainingStages) {
stage('Quick tests') {
parallel headers: {
runPod(image: image) {
stage('Headers check') {
writeFile(file: 'make/local', text: "CXX=$CLANG_CXX -Werror")
sh 'make -j$PARALLEL test-headers'
}
}
}, unit: {
if (env.CHANGE_TARGET) {
runPod(image: image) {
stage('Run changed unit tests') {
writeFile(file: 'make/local', text: "O=3\nCXXFLAGS+=-march=native -mtune=native")
sh './runTests.py -j$PARALLEL --changed --debug'
}
}
}
}
}
stage('Full Unit Tests') {
parallel failFast: true,
revfwd: {
runPod(image: image) {
stage('Rev/Fwd Unit Tests') {
def local = 'CXXFLAGS+= -fsanitize=address\n'
if (noOptimize)
local += 'O=0\n'
runTests(local, "test/unit/math/rev")
runTests(local, "test/unit/math/fwd")
}
}
},
mix: {
runPod(image: image, cpus: 8, memory: '192Gi') {
stage('Mix Unit Tests') {
def local = 'CXXFLAGS+= -fsanitize=address\n'
if (noOptimize)
local += 'O=1\n'
runTests(local, "test/unit/math/mix" + jumboFlags)
}
}
},
prim: {
runPod(image: image) {
stage('Prim Unit Tests') {
def local = 'CXXFLAGS+= -fsanitize=address\n'
if (noOptimize)
local += 'O=0\n'
runTests(local, "test/unit/*_test.cpp")
runTests(local, "test/unit/math/*_test.cpp")
runTests(local, "test/unit/math/prim" + jumboFlags)
runTests(local, "test/unit/math/memory")
}
}
},
laplace: {
runPod(image: image, memory: '32Gi') {
stage('Laplace Unit Tests') {
def local = 'CXXFLAGS+= -march=native -mtune=native\nO=3\n'
if (!noOptimize)
local += 'CXXFLAGS+= -fsanitize=address'
runTests(local, "test/unit/math/laplace/*_test.cpp")
}
}
},
gpu: {
runPod(image: image, memory: '32Gi', gpus: 1) {
stage('OpenCL GPU tests') {
def local = """CXX=$CLANG_CXX -Werror
STAN_OPENCL=true
OPENCL_PLATFORM_ID_GPU=0
OPENCL_DEVICE_ID=0
LDFLAGS_OPENCL=-L/usr/local/cuda/targets/x86_64-linux/lib
"""
if (noOptimize)
local += 'O=1\n'
runTests(local, "test/unit/math/opencl") // TODO(bward): try to enable
runTests(local, "test/unit/multiple_translation_units_test.cpp")
}
}
}
}
stage('Always-run tests') {
parallel failFast: true,
mpi: {
runPod(image: image) {
stage('Laplace Unit Tests') {
def local = "CXX=$MPICXX\nCXX_TYPE=gcc\nSTAN_MPI=true\n"
runTests(local, "test/unit/math/prim/functor")
runTests(local, "test/unit/math/rev/functor")
}
}
},
expr: {
runPod(image: image, memory: '64Gi') {
stage('Expressions test') {
def local = "CXX=$CLANG_CXX -Werror\nO=0\n"
writeFile(file: 'make/local', text: 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"
runTests(local, 'test/expressions')
sh "make clean-all"
runTests(local + "STAN_THREADS=true\n", 'test/expressions --only-functions reduce_sum map_rect')
}
}
}
},
thread: {
runPod(image: image, memory: '32Gi') {
stage('Threading tests') {
def local = "CXX=$CLANG_CXX -Werror\nSTAN_THREADS=true\n"
if (mainBranch) {
runTests(local, "test/unit")
} else {
runTests(local, "test/unit -f thread")
runTests(local, "test/unit -f map_rect")
runTests(local, "test/unit -f reduce_sum")
}
}
}
}
}
def cores_per_test = 6
def parallel_tests = 10
runPod(image: image, cpus: cores_per_test*parallel_tests, memory: '128Gi') {
stage ('Distribution tests') {
def local = "CXX=$CLANG_CXX\nO=0\nN_TESTS=100\n"
if (params.withRowVector || mainBranch) {
local += "CXXFLAGS+= -DSTAN_TEST_ROW_VECTORS -DSTAN_PROB_TEST_ALL\n"
}
writeFile(file: 'make/local', text: local)
def cmd = 'python3 test/prob/getDependencies.py'
if (params.runAllDistributions || mainBranch) {
cmd += ' --pretend-all'
}
sh """
$cmd > changed-tests
if [ -s changed-tests ] ; then
./runTests.py -j${cores_per_test*parallel_tests} --make-only `< changed-tests`
unset PARALLEL
parallel --halt now,fail=1 -r -j$parallel_tests ./runTests.py --test-only -j$cores_per_test {} < changed-tests
fi
"""
}
}
if (env.CHANGE_TARGET) {
stage('Upstream tests') {
build(job: "CCM/Stan/stan/$params.stan_pr",
parameters: [
booleanParam(name: 'downstream', value: true),
string(name: 'math_pr', value: env.BRANCH_NAME),
string(name: 'cmdstan_pr', value: params.cmdstan_pr)
])
}
}
}
if (env.BRANCH_NAME == 'develop') {
runPod(image: image, cpus: 2) {
stage('Upload doxygen') {
def branch = 'gh-pages'
sh 'make doxygen'
dir('gh-pages') {
def scm = scmGit(
branches: [[name: "refs/heads/$branch"]],
userRemoteConfigs: [[credentialsId: 'stan-github', url: 'https://github.com/stan-dev/math.git']])
checkout(scm: scm, changelog: false, poll: false)
sh '''
rm -rf *
mv ../doc/api/html/* .
git add .
git commit --amend -m "auto generated docs from Jenkins"
'''
withCredentials([gitUsernamePassword(credentialsId: 'stan-github', gitToolName: 'git-tool')]) {
sh "git push --force origin HEAD:$branch"
}
}
}
stage('Update upstream') {
dir('stan') {
updateSubmodule('stan', 'develop', 'lib/stan_math')
}
}
}
}
}
}
emailFailure()