-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathJenkinsfile
More file actions
222 lines (203 loc) · 8.7 KB
/
Copy pathJenkinsfile
File metadata and controls
222 lines (203 loc) · 8.7 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
def props = [
buildDiscarder(logRotator(numToKeepStr: '40', daysToKeepStr: '30')),
parameters([
string(defaultValue: '', name: 'stan_pr',
description: "Stan PR to test against. Will check out this PR in the downstream Stan repo."),
string(defaultValue: '', name: 'math_pr',
description: "Math PR to test against. Will check out this PR in the downstream Math repo."),
string(defaultValue: 'nightly', name: 'stanc3_bin_url',
description: 'Custom stanc3 binary url'),
booleanParam(defaultValue: false, name: 'downsteam', description: 'Run downstream tests from stan (was previously downstream_hotfix [master]/downstream_tests [develop])'),
booleanParam(defaultValue: false, name: 'run_all', description: 'Pretend all files changes'),
booleanParam(defaultValue: false, name: 'build_tarballs', description: 'Build tarballs as if for a release'),
])
]
if (!params.downstream) {
props <<= disableConcurrentBuilds(abortPrevious: env.BRANCH_NAME != 'develop')
}
properties(props)
def image = 'stanorg/ci:v1'
def commit
def runRemainingStages = false
def WIN_CXX = 'g++'
def MPI_CXX = 'mpicxx.openmpi'
def MAC_CXX = 'clang++'
def WINSETENV = '''
SET "PATH=%RTOOLS%\\x86_64-w64-mingw32.static.posix\\bin;%RTOOLS%;%RTOOLS%\\usr\\bin;%CONDA%;%PATH%"
'''
catchError {
withEnv([
'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) {
commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
runRemainingStages = params.downstream || params.run_all || filesChanged('src/cmdstan', 'src/test', 'lib', 'examples', 'make', 'stan', 'install-tbb.bat', 'makefile', 'runCmdStanTests.py', 'test-all.sh', 'Jenkinsfile')
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 += "/cmdstan.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/cmdstan under $repo branch $branch"
echo "Please 'git pull' before continuing to develop."
error "clang-format changes"
}
}
}
def scmFull = scmGit(
branches: scm.branches,
userRemoteConfigs: scm.userRemoteConfigs,
extensions: scm.extensions + [cleanBeforeCheckout(),
submodule(recursiveSubmodules: true, shallow: true, depth: 2)])
def prepTests = { extra ->
checkout scmFull
checkoutPR("stan", params.stan_pr)
checkoutPR("stan/lib/stan_math", params.math_pr)
def local = "CXXFLAGS+=-Werror -Wp,-D_GLIBCXX_ASSERTIONS\n"
if (params.stanc3_bin_url != "nightly") {
local += "STANC3_TEST_BIN_URL=${params.stanc3_bin_url}\n"
}
writeFile(file: "make/local", text: local + extra)
}
if (runRemainingStages) {
parallel failFast: true,
windows: {
node('windows') {
stage('Windows interface tests') {
prepTests("CXX=${WIN_CXX}\nCXXFLAGS+=-Wno-error=overloaded-virtual= ")
withEnv(["PATH+TBB=${WORKSPACE}\\stan\\lib\\stan_math\\lib\\tbb"]) {
bat """$WINSETENV
make print-compiler-flags
python runCmdStanTests.py -j%PARALLEL% src/test/interface
"""
}
}
}
}, linux: {
runPod(image: image, checkout: false) {
stage('Linux interface tests with MPI') {
prepTests("""CXX=${MPI_CXX}
STAN_MPI=true
CXX_TYPE=gcc""")
sh "make print-compiler-flags"
sh "make build-mpi"
sh './runCmdStanTests.py -j$PARALLEL src/test/interface'
}
}
}, mac: {
node('macos') {
stage('Mac interface tests') {
prepTests("CXX=${MAC_CXX}\nCXXFLAGS+=-Wno-unused-command-line-argument")
sh 'make print-compiler-flags'
sh 'python3 ./runCmdStanTests.py -j$PARALLEL src/test/interface'
}
}
}, upstream: {
if (params.downstream || env.CHANGE_TARGET) {
stage('Upstream CmdStan Performance tests') {
build(
job: "CCM/Stan/performance-tests-cmdstan/master",
parameters: [
booleanParam(name: 'downstream', value: true),
string(name: 'cmdstan_pr', value: env.BRANCH_NAME),
string(name: 'stan_pr', value: params.stan_pr),
string(name: 'math_pr', value: params.math_pr),
string(name: 'stanc3_bin_url', value: params.stanc3_bin_url),
],
wait: true)
}
}
}
}
if (env.BRANCH_NAME == 'develop') {
podTemplate(inheritFrom: 'jnlp') {
node(POD_LABEL) {
stage('Update performance tests submodule') {
updateSubmodule('performance-tests-cmdstan', 'master', 'cmdstan', commit)
}
}
}
}
if (env.TAG_NAME || params.build_tarballs) {
runPod(image: image, checkout: false) {
def download_stanc = { args ->
def platform = args.platform ?: 'linux';
if (params.stanc3_bin_url != 'nightly') {
sh "curl -fLO '${params.stanc3_bin_url}/bin/${platform}-stanc' --retry 5 --retry-delay 10"
} else {
def tagName = env.TAG_NAME ?: 'nightly';
sh "curl -fLO 'https://github.com/stan-dev/stanc3/releases/download/${tagName}/${platform}-stanc' --retry 5 --retry-delay 10"
}
}
stage("Build tarballs") {
def version = env.TAG_NAME ? env.TAG_NAME.substring(1, env.TAG_NAME.length()) : env.GIT_COMMIT ;
dir("cmdstan-${version}"){
checkout scmGit(
branches: scm.branches,
userRemoteConfigs: scm.userRemoteConfigs,
extensions: scm.extensions + [cleanBeforeCheckout(),
submodule(recursiveSubmodules: true, shallow: true, depth: 2)]);
if (params.stan_pr)
checkoutPR("stan", params.stan_pr)
if (params.math_pr)
checkoutPR("stan/lib/stan_math", params.math_pr)
sh "mkdir -p bin"
dir("bin"){
for (platform in ["windows", "macos", "linux"]) {
download_stanc(platform: platform)
}
}
}
sh "tar --exclude-vcs --hard-dereference -chzf cmdstan-${version}.tar.gz cmdstan-${version}/"
// build the non-x86-linux tarballs
sh "rm cmdstan-${version}/bin/*-stanc"
for(arch in ["arm64", "armel", "armhf", "ppc64el", "s390x"]) {
def platform = "linux-${arch}"
download_stanc(platform: platform)
sh """
mv ${platform}-stanc cmdstan-${version}/bin/linux-stanc
tar --exclude-vcs --hard-dereference -chzf 'cmdstan-${version}-linux-${arch}.tar.gz' cmdstan-${version}/
rm cmdstan-${version}/bin/linux-stanc
"""
}
archiveArtifacts 'cmdstan*.tar.gz'
if (env.TAG_NAME) {
withCredentials([usernamePassword(usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN', credentialsId: 'stan-github')]) {
sh "gh release upload ${env.TAG_NAME} ./*.tar.gz || gh release create ${env.TAG_NAME} --draft ./*.tar.gz"
}
}
}
}
}
}
}
emailFailure()