forked from runtimeverification/k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
517 lines (511 loc) · 17.9 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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
pipeline {
agent { label 'docker' }
options { ansiColor('xterm') }
environment {
PACKAGE = 'kframework'
ROOT_URL = 'https://github.com/kframework/k/releases/download'
SHORT_REV = """${sh(returnStdout: true, script: 'git rev-parse --short=7 HEAD').trim()}"""
LONG_REV = """${sh(returnStdout: true, script: 'git rev-parse HEAD').trim()}"""
VERSION = """${sh(returnStdout: true, script: 'cat package/version').trim()}"""
K_RELEASE_TAG = "v${env.VERSION}"
MAKE_EXTRA_ARGS = '' // Example: 'DEBUG=--debug' to see stack traces
}
stages {
stage('Init title') {
when { changeRequest() }
steps {
script { currentBuild.displayName = "PR ${env.CHANGE_ID}: ${env.CHANGE_TITLE}" }
milestone(1)
}
}
stage('Create source tarball') {
when {
anyOf {
branch 'release'
changeRequest()
}
beforeAgent true
}
agent {
dockerfile {
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)'
reuseNode true
}
}
steps {
dir("kframework-${env.VERSION}") {
checkout scm
sh '''
find . -name .git | xargs rm -r
cd ..
tar czvf kframework-${VERSION}-src.tar.gz kframework-${VERSION}
'''
deleteDir()
}
stash name: 'src', includes: "kframework-${env.VERSION}-src.tar.gz"
}
}
stage('Build and Package on Ubuntu Bionic') {
when {
anyOf {
branch 'release'
changeRequest()
}
beforeAgent true
}
stages {
stage('Build on Ubuntu Bionic') {
agent {
dockerfile {
filename 'package/debian/Dockerfile'
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --build-arg BASE_IMAGE=ubuntu:bionic'
reuseNode true
}
}
stages {
stage('Checkout code') { steps { dir('k-exercises') { git url: '[email protected]:kframework/k-exercises.git', credentialsId: 'rv-jenkins-access-token' } } }
stage('Build and Test K') {
options { timeout(time: 45, unit: 'MINUTES') }
steps {
sh '''
echo 'Setting up environment...'
eval `opam config env`
export K_OPTS='-Xmx12G'
echo 'Building K...'
mvn --batch-mode verify -U
echo 'Starting kserver...'
k-distribution/target/release/k/bin/spawn-kserver kserver.log
cd k-exercises/tutorial
make -j`nproc` --output-sync ${MAKE_EXTRA_ARGS}
cd ../../k-distribution/k-tutorial/1_basic
./test_kompile.sh
'''
}
post {
always {
sh 'k-distribution/target/release/k/bin/stop-kserver || true'
archiveArtifacts 'kserver.log,k-distribution/target/kserver.log'
}
}
}
stage('Build Debian Package') {
steps {
dir("kframework-${env.VERSION}") {
checkout scm
sh '''
mv package/debian ./debian
mv debian/control.bionic debian/control
dpkg-buildpackage
'''
}
stash name: 'bionic', includes: "kframework_${env.VERSION}_amd64.deb"
}
}
}
}
stage('Test Debian Package') {
agent {
docker {
image 'ubuntu:bionic'
args '-u 0'
reuseNode true
}
}
options { skipDefaultCheckout() }
steps {
unstash 'bionic'
sh 'src/main/scripts/test-in-container-debian'
}
post {
always {
sh 'stop-kserver || true'
archiveArtifacts 'kserver.log,k-distribution/target/kserver.log'
}
}
}
}
}
stage('Build and Package on Ubuntu Focal') {
when {
branch 'release'
beforeAgent true
}
stages {
stage('Build on Ubuntu Focal') {
agent {
dockerfile {
filename 'package/debian/Dockerfile'
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --build-arg BASE_IMAGE=ubuntu:focal --build-arg LLVM_VERSION=12'
reuseNode true
}
}
stages {
stage('Build Debian Package') {
steps {
dir("kframework-${env.VERSION}") {
checkout scm
sh '''
mv package/debian ./debian
mv debian/control.focal debian/control
dpkg-buildpackage
'''
}
stash name: 'focal', includes: "kframework_${env.VERSION}_amd64.deb"
}
}
}
}
stage('Test Debian Package') {
agent {
docker {
image 'ubuntu:focal'
args '-u 0'
reuseNode true
}
}
options { skipDefaultCheckout() }
steps {
unstash 'focal'
sh 'src/main/scripts/test-in-container-debian'
}
post {
always {
sh 'stop-kserver || true'
archiveArtifacts 'kserver.log,k-distribution/target/kserver.log'
}
}
}
}
post {
failure {
slackSend color: '#cb2431' \
, channel: '#k' \
, message: "Ubuntu Focal Packaging Failed: ${env.BUILD_URL}"
}
}
}
stage('Build and Package on Debian Bullseye') {
when {
branch 'release'
beforeAgent true
}
stages {
stage('Build on Debian Bullseye') {
agent {
dockerfile {
filename 'package/debian/Dockerfile'
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --build-arg BASE_IMAGE=debian:bullseye --build-arg LLVM_VERSION=11'
reuseNode true
}
}
stages {
stage('Build Debian Package') {
steps {
dir("kframework-${env.VERSION}") {
checkout scm
sh '''
mv package/debian ./debian
mv debian/control.debian debian/control
dpkg-buildpackage
'''
}
stash name: 'bullseye', includes: "kframework_${env.VERSION}_amd64.deb"
}
}
}
}
stage('Test Debian Package') {
agent {
docker {
image 'debian:bullseye'
args '-u 0'
reuseNode true
}
}
options { skipDefaultCheckout() }
steps {
unstash 'bullseye'
sh '''
# echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/sources.list.d/bullseye-backports.list
src/main/scripts/test-in-container-debian
'''
}
post {
always {
sh 'stop-kserver || true'
archiveArtifacts 'kserver.log,k-distribution/target/kserver.log'
}
}
}
}
post {
failure {
slackSend color: '#cb2431' \
, channel: '#k' \
, message: "Debian Bullseye Packaging Failed: ${env.BUILD_URL}"
}
}
}
stage('Build and Package on Arch Linux') {
when {
branch 'release'
beforeAgent true
}
stages {
stage('Build on Arch Linux') {
agent {
dockerfile {
filename 'package/arch/Dockerfile'
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)'
reuseNode true
}
}
stages {
stage('Build Pacman Package') {
steps {
dir("kframework-arch-${env.VERSION}") {
checkout scm
sh '''
mv package/arch/* ./
makepkg
'''
stash name: 'arch', includes: "kframework-git-${env.VERSION}-1-x86_64.pkg.tar.zst"
}
}
}
}
}
stage('Test Arch Package') {
agent {
docker {
image 'archlinux:base'
args '-u 0'
reuseNode true
}
}
options { skipDefaultCheckout() }
steps {
unstash 'arch'
sh '''
pacman -Syyu --noconfirm
pacman -S --noconfirm opam pkgconf
pacman -U --noconfirm kframework-git-${VERSION}-1-x86_64.pkg.tar.zst
src/main/scripts/test-in-container
'''
}
post {
always {
sh 'stop-kserver || true'
archiveArtifacts 'kserver.log,k-distribution/target/kserver.log'
}
}
}
}
post {
failure {
slackSend color: '#cb2431' \
, channel: '#k' \
, message: "Arch Linux Packaging Failed: ${env.BUILD_URL}"
}
}
}
stage('DockerHub') {
when {
branch 'release'
beforeAgent true
}
environment {
DOCKERHUB_TOKEN = credentials('rvdockerhub')
BIONIC_VERSION_TAG = "ubuntu-bionic-${env.VERSION}"
BIONIC_BRANCH_TAG = "ubuntu-bionic-${env.BRANCH_NAME}"
FOCAL_VERSION_TAG = "ubuntu-focal-${env.VERSION}"
FOCAL_BRANCH_TAG = "ubuntu-focal-${env.BRANCH_NAME}"
DOCKERHUB_REPO = "runtimeverificationinc/kframework-k"
}
stages {
stage('Build Image') {
agent { label 'docker' }
steps {
milestone(2)
dir('bionic') { unstash 'bionic' }
sh '''
mv bionic/kframework_${VERSION}_amd64.deb kframework_amd64_bionic.deb
docker login --username "${DOCKERHUB_TOKEN_USR}" --password "${DOCKERHUB_TOKEN_PSW}"
docker image build . --file package/docker/Dockerfile.ubuntu-bionic --tag "${DOCKERHUB_REPO}:${BIONIC_VERSION_TAG}"
docker image push "${DOCKERHUB_REPO}:${BIONIC_VERSION_TAG}"
docker tag "${DOCKERHUB_REPO}:${BIONIC_VERSION_TAG}" "${DOCKERHUB_REPO}:${BIONIC_BRANCH_TAG}"
docker push "${DOCKERHUB_REPO}:${BIONIC_BRANCH_TAG}"
'''
dir('focal') { unstash 'focal' }
sh '''
mv focal/kframework_${VERSION}_amd64.deb kframework_amd64_focal.deb
docker login --username "${DOCKERHUB_TOKEN_USR}" --password "${DOCKERHUB_TOKEN_PSW}"
docker image build . --file package/docker/Dockerfile.ubuntu-focal --tag "${DOCKERHUB_REPO}:${FOCAL_VERSION_TAG}"
docker image push "${DOCKERHUB_REPO}:${FOCAL_VERSION_TAG}"
docker tag "${DOCKERHUB_REPO}:${FOCAL_VERSION_TAG}" "${DOCKERHUB_REPO}:${FOCAL_BRANCH_TAG}"
docker push "${DOCKERHUB_REPO}:${FOCAL_BRANCH_TAG}"
'''
}
}
stage('Test Bionic Image') {
agent {
docker {
image "${DOCKERHUB_REPO}:${BIONIC_VERSION_TAG}"
args '-u 0'
reuseNode true
}
}
steps {
sh '''
cd ~
echo 'module TEST imports BOOL endmodule' > test.k
kompile test.k --backend llvm
kompile test.k --backend haskell
'''
}
}
stage('Test Focal Image') {
agent {
docker {
image "${DOCKERHUB_REPO}:${FOCAL_VERSION_TAG}"
args '-u 0'
reuseNode true
}
}
steps {
sh '''
cd ~
echo 'module TEST imports BOOL endmodule' > test.k
kompile test.k --backend llvm
kompile test.k --backend haskell
'''
}
}
}
}
stage('Deploy') {
when {
branch 'release'
beforeAgent true
}
agent {
dockerfile {
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)'
reuseNode true
}
}
post { failure { slackSend color: '#cb2431' , channel: '#k' , message: "Deploy Phase Failed: ${env.BUILD_URL}" } }
environment { GITHUB_TOKEN = credentials('rv-jenkins-access-token') }
steps {
unstash 'src'
dir('bionic') { unstash 'bionic' }
dir('focal') { unstash 'focal' }
dir('bullseye') { unstash 'bullseye' }
dir('arch') { unstash 'arch' }
sshagent(['rv-jenkins-github']) {
sh '''
git clone 'ssh://github.com/kframework/k.git' k-release
cd k-release
git fetch --all
release_commit="$LONG_REV"
git checkout $release_commit
git tag -d "${K_RELEASE_TAG}" || true
git push -d origin "${K_RELEASE_TAG}" || true
hub release delete "${K_RELEASE_TAG}" || true
git tag "${K_RELEASE_TAG}" "${release_commit}"
git push origin "${K_RELEASE_TAG}"
mv ../kframework-${VERSION}-src.tar.gz kframework-${VERSION}-src.tar.gz
mv ../bionic/kframework_${VERSION}_amd64.deb kframework_${VERSION}_amd64_bionic.deb
mv ../focal/kframework_${VERSION}_amd64.deb kframework_${VERSION}_amd64_focal.deb
mv ../bullseye/kframework_${VERSION}_amd64.deb kframework_${VERSION}_amd64_bullseye.deb
mv ../arch/kframework-git-${VERSION}-1-x86_64.pkg.tar.zst kframework-git-${VERSION}-1-x86_64.pkg.tar.zst
echo "K Framework Release ${VERSION}" > release.md
echo '' >> release.md
cat k-distribution/INSTALL.md >> release.md
hub release create --prerelease \
--attach kframework-${VERSION}-src.tar.gz'#Source tar.gz' \
--attach kframework_${VERSION}_amd64_bionic.deb'#Ubuntu Bionic (18.04) Package' \
--attach kframework_${VERSION}_amd64_focal.deb'#Ubuntu Focal (20.04) Package' \
--attach kframework_${VERSION}_amd64_bullseye.deb'#Debian Bullseye (11) Package' \
--attach kframework-git-${VERSION}-1-x86_64.pkg.tar.zst'#Arch Package' \
--file release.md "${K_RELEASE_TAG}"
'''
}
}
}
stage('GitHub Pages') {
when {
branch 'release'
beforeAgent true
}
agent {
dockerfile {
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)'
reuseNode true
}
}
post { failure { slackSend color: '#cb2431' , channel: '#k' , message: "GitHub Pages Deploy Failed: ${env.BUILD_URL}" } }
steps {
dir('gh-pages') {
sshagent(['rv-jenkins-github']) {
sh '''
git clone 'ssh://github.com/kframework/k.git' --depth 1 --no-single-branch --branch master --branch gh-pages
cd k
git checkout -B gh-pages origin/master
git submodule update --init --recursive -- ./web
cd web
npm install
npm run build
npm run build-sitemap
cd -
mv web/public_content ./
rm -rf $(find . -maxdepth 1 -not -name public_content -a -not -name .git -a -not -path . -a -not -path .. -a -not -name CNAME)
mv public_content/* ./
rm -rf public_content
git add ./
git commit -m 'gh-pages: Updated the website'
git merge --strategy ours origin/gh-pages --allow-unrelated-histories
git push origin gh-pages
'''
}
}
}
}
stage('Trigger Release') {
when {
branch 'master'
beforeAgent true
}
agent {
dockerfile {
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)'
reuseNode true
}
}
options { skipDefaultCheckout() }
post { failure { slackSend color: '#cb2431' , channel: '#k' , message: "Failed to trigger Release: ${env.BUILD_URL}" } }
steps {
sshagent(['rv-jenkins-github']) {
sh '''
git clone 'ssh://github.com/kframework/k' k-release
cd k-release
git fetch --all
git checkout -B release origin/release
old_master="$(git merge-base origin/master origin/release)"
new_master="$(git rev-parse origin/master)"
if git diff --exit-code ${old_master} ${new_master} -- package/version; then
git merge --no-edit origin/master
./package/version.sh bump
else
git merge --no-edit --strategy-option=theirs origin/master
fi
./package/version.sh sub
git add --update
git commit --no-edit --allow-empty --message "Set Version: $(cat package/version)"
git push origin release
'''
}
}
}
}
}