-
-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathJenkinsfile
More file actions
235 lines (223 loc) · 9.58 KB
/
Copy pathJenkinsfile
File metadata and controls
235 lines (223 loc) · 9.58 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
properties([
disableConcurrentBuilds(abortPrevious: !params.downstream),
buildDiscarder(logRotator(numToKeepStr: '20', daysToKeepStr: '30')),
parameters([
string(defaultValue: '', name: 'math_pr', description: "Leave blank "
+ "unless testing against a specific math repo pull request, "
+ "e.g. PR-640."),
string(defaultValue: 'develop', name: 'cmdstan_pr',
description: 'PR to test CmdStan upstream against e.g. PR-630'),
string(defaultValue: 'nightly', name: 'stanc3_bin_url',
description: 'Custom stanc3 binary url'),
booleanParam(defaultValue: false, name: 'downsteam', description: 'Run downstream tests from math (was previously downstream_hotfix/downstream_tests [develop])'),
booleanParam(defaultValue: false, name: 'run_tests_all_os', description: 'Run unit and integration tests on all OS.'),
booleanParam(defaultValue: false, name: 'compile_all_models', description: 'Run integration tests on the full test model suite.'),
booleanParam(defaultValue: false, name: 'run_all', description: 'Pretend all files changes'),
])
])
def image = 'stanorg/ci:v1'
def commit
def runRemainingStages = false
def LINUX_CXX = 'clang++-7 -Werror -Wno-inconsistent-missing-override -Wno-error=return-type -Wno-error=division-by-zero'
def WIN_CXX = 'g++ -Werror -Wno-error=overloaded-virtual -Wno-error=template-id-cdtor -Wno-error=deprecated-declarations -Wno-error=cast-user-defined -Wno-error=unused-value -Wno-error=array-bounds'
def MAC_CXX = 'clang++' // -Werror -Wno-inconsistent-missing-override -Wno-unused-but-set-variable
def WINSETENV = '''
SET "PATH=%RTOOLS%\\x86_64-w64-mingw32.static.posix\\bin;%RTOOLS%;%RTOOLS%\\usr\\bin;%CONDA%;%PATH%"
'''
def stanc3_bin_url = params.stanc3_bin_url != "nightly" ? "STANC3_TEST_BIN_URL=${params.stanc3_bin_url}\n" : ''
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') {
commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
runRemainingStages = params.downstream || params.run_all || filesChanged(
'make', 'src/stan', 'src/test', 'Jenkinsfile', 'makefile', 'runTests.py',
'lib/stan_math/stan', 'lib/stan_math/make', 'lib/stan_math/lib', 'lib/stan_math/test',
'lib/stan_math/runTests.py', 'lib/stan_math/runChecks.py', 'lib/stan_math/makefile',
'lib/stan_math/Jenkinsfile', 'lib/stan_math/.clang-format')
}
stage("Clang-format") {
def dirty = sh returnStatus: true, script: """
clang-format --version
git ls-files 'src/*.hpp' 'src/*.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 += "/stan.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/stan under $repo branch $branch"
echo "Please 'git pull' before continuing to develop."
error "clang-format changes"
}
}
stage('Linting & Doc checks') {
checkoutPR("lib/stan_math", params.math_pr)
writeFile(file: "make/local", text: "CXX=$LINUX_CXX\n$stanc3_bin_url")
parallel(
CppLint: { sh "make cpplint" },
API_docs: { sh 'make doxygen' },
)
}
}
if (runRemainingStages) {
stage('Unit tests') {
def runUnit = { args ->
def local = "CXX=$args.cxx\n$stanc3_bin_url"
if (args.local)
local += args.local
writeFile(file: "make/local", text: local)
def pre = args.pre ?: ''
batsh(pre + 'make -j$PARALLEL test-headers')
batsh(pre + 'python3 runTests.py -j$PARALLEL src/test/unit --make-only')
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
batsh(pre + 'python3 runTests.py -j$PARALLEL src/test/unit')
}
junit 'test/**/*.xml'
}
parallel windows: {
node('windows') {
stage('Windows Headers & Unit') {
checkout scm
bat """$WINSETENV
make -f lib/stan_math/make/standalone math-libs
"""
withEnv(["PATH+TBB=$WORKSPACE\\lib\\stan_math\\lib\\tbb"]) {
runUnit(cxx: WIN_CXX, pre: WINSETENV)
}
}
}
}, linux: {
runPod(image: image, gpus: 1) {
stage('Linux Unit') {
runUnit(cxx: LINUX_CXX, local: """
STAN_OPENCL=true
OPENCL_PLATFORM_ID=0
OPENCL_DEVICE_ID=0
LDFLAGS_OPENCL=-L/usr/local/cuda/targets/x86_64-linux/lib
""")
}
}
}, mac: {
if (!params.downstream && (env.BRANCH_NAME == "develop" || env.BRANCH_NAME == "master") || params.run_tests_all_os) {
node('macos') {
stage('Mac Unit') {
checkout scm
runUnit(cxx: MAC_CXX)
}
}
}
}
}
stage('Integration') {
// TODO: this was disabled before
def integration_tests_flags = params.compile_all_models ? '--no-ignore-models' : ''
def runIntegration = { args ->
def pre = args.pre ?: ''
deleteDir()
checkout scmGit(userRemoteConfigs: [[url: 'https://github.com/stan-dev/performance-tests-cmdstan']],
extensions: [cloneOption(shallow: true, depth: 2), submodule(recursiveSubmodules: true, shallow: true, depth: 32)])
dir('stanc3') {
checkout scmGit(userRemoteConfigs: [[url: 'https://github.com/stan-dev/stanc3']],
extensions: [cloneOption(shallow: true, depth: 8)])
}
checkoutPR('cmdstan', params.cmdstan_pr)
dir('cmdstan/stan') {
checkout scm
writeFile(file: 'make/local', text: stanc3_bin_url)
}
writeFile(file: 'cmdstan/make/local', text: args.local+"\n$stanc3_bin_url")
batsh pre + """
make -C cmdstan -j\$PARALLEL build
python3 ./runPerformanceTests.py -j\$PARALLEL $integration_tests_flags --runs=0 stanc3/test/integration/good
python3 ./runPerformanceTests.py -j\$PARALLEL $integration_tests_flags --runs=0 example-models
"""
dir('cmdstan/stan') {
batsh pre + """
python3 ./runTests.py src/test/integration/compile_standalone_functions_test.cpp
python3 ./runTests.py src/test/integration/standalone_functions_test.cpp
python3 ./runTests.py src/test/integration/multiple_translation_units_test.cpp
"""
}
}
parallel linux: {
runPod(image: image, checkout: false, cpus: 16, memory: '128Gi') {
stage('Integration Linux') {
runIntegration(local: "O=0\nCXX=${LINUX_CXX}")
}
}
}, mac: {
if (!params.downstream && (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master') || params.run_tests_all_os) {
node('macos') {
stage('Integration Mac') {
runIntegration(local: "O=0\nCXX=${MAC_CXX}")
}
}
}
}, windows: {
node('windows') {
stage('Integration Windows') {
withEnv(["PATH+TBB=${WORKSPACE}\\cmdstan\\stan\\lib\\stan_math\\lib\\tbb"]) {
runIntegration(local: "CXX=${WIN_CXX}\nPRECOMPILED_HEADERS=true\n", pre: WINSETENV)
}
}
}
}
}
if (env.CHANGE_TARGET || params.downstream) {
stage('Upstream CmdStan tests') {
build(job: "CCM/Stan/cmdstan/$params.cmdstan_pr",
parameters: [
booleanParam(name: 'downstream', value: true),
string(name: 'stan_pr', value: env.BRANCH_NAME),
string(name: 'math_pr', value: params.math_pr),
string(name: 'stanc3_bin_url', value: params.stanc3_bin_url)
])
}
}
}
}
if (env.BRANCH_NAME == 'develop') {
podTemplate(inheritFrom: 'jnlp') {
node(POD_LABEL) {
stage('Update upstream') {
dir('cmdstan') {
updateSubmodule('cmdstan', 'develop', 'stan', commit)
}
dir('rstan') {
updateSubmodule('rstan', 'develop', 'StanHeaders/inst/include/upstream', commit)
}
}
}
}
}
}
emailFailure()