forked from runtimeverification/k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
675 lines (668 loc) · 27 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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
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 K') {
failFast true
parallel {
stage('Build and Package K on Linux') {
stages {
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' } } }
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}
'''
}
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=10'
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 Buster') {
when {
branch 'release'
beforeAgent true
}
stages {
stage('Build on Debian Buster') {
agent {
dockerfile {
filename 'package/debian/Dockerfile'
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --build-arg BASE_IMAGE=debian:buster --build-arg LLVM_VERSION=8'
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: 'buster', includes: "kframework_${env.VERSION}_amd64.deb"
}
}
}
}
stage('Test Debian Package') {
agent {
docker {
image 'debian:buster'
args '-u 0'
reuseNode true
}
}
options { skipDefaultCheckout() }
steps {
unstash 'buster'
sh '''
echo "deb http://deb.debian.org/debian buster-backports main" > /etc/apt/sources.list.d/buster-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 Buster 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
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('Build Platform Independent K Binary') {
when {
branch 'release'
beforeAgent true
}
agent {
dockerfile {
additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)'
reuseNode true
}
}
steps {
sh '''
eval `opam config env`
mvn --batch-mode clean
mvn --batch-mode install -DskipKTest -Dcheckstyle.skip
mv k-distribution/target/k-nightly.tar.gz ./
'''
stash name: 'binary', includes: 'k-nightly.tar.gz'
}
post {
failure {
slackSend color: '#cb2431' \
, channel: '#k' \
, message: "Platform Independent K Binary Failed: ${env.BUILD_URL}"
}
}
}
}
}
stage('Build and Package on Mac OS') {
when {
branch 'release'
beforeAgent true
}
options { timeout(time: 150, unit: 'MINUTES') }
stages {
stage('Build on Mac OS') {
stages {
stage('Build Homebrew Bottle') {
agent { label 'anka' }
environment { STACK_ROOT = '/opt/stack' }
steps {
unstash 'src'
dir('kframework') { checkout scm }
dir('homebrew-k') {
git url: '[email protected]:kframework/homebrew-k.git'
sh '''
git config --global user.email '[email protected]'
git config --global user.name 'RV Jenkins'
# Note: double-backslash in sed-command is for Jenkins benefit.
brew_base_branch=$(cd ../kframework && git log -n1 --format=%s HEAD | sed -n 's!.*\\[brew-staging: \\(.*\\)\\].*!\\1!p')
[ "$brew_base_branch" != '' ] || brew_base_branch=master
git show-ref --verify refs/remotes/origin/$brew_base_branch
git push -d origin brew-release-$PACKAGE || true
git checkout -b brew-release-$PACKAGE "origin/$brew_base_branch"
git merge origin/master
${WORKSPACE}/package/macos/brew-update-to-local ${PACKAGE} ${VERSION}
git commit Formula/$PACKAGE.rb -m "Update ${PACKAGE} to ${SHORT_REV}: part 1"
${WORKSPACE}/package/macos/brew-build-and-update-to-local-bottle ${PACKAGE} ${VERSION} ${ROOT_URL}
git commit Formula/$PACKAGE.rb -m "Update ${PACKAGE} to ${SHORT_REV}: part 2"
git push origin brew-release-$PACKAGE
'''
stash name: 'mojave', includes: "kframework--${env.VERSION}.mojave.bottle*.tar.gz"
}
}
}
stage('Test Homebrew Bottle') {
agent { label 'anka' }
steps {
dir('homebrew-k') {
git url: '[email protected]:kframework/homebrew-k.git', branch: 'brew-release-kframework'
unstash 'mojave'
sh '${WORKSPACE}/package/macos/brew-install-bottle ${PACKAGE} ${VERSION}'
}
sh '''
brew install opam
k-configure-opam
eval $(opam config env)
cp -R /usr/local/share/kframework/pl-tutorial ~
WD=`pwd`
cd
echo 'Starting kserver...'
spawn-kserver $WD/kserver.log
cd pl-tutorial
echo 'Testing tutorial in user environment...'
make -j`sysctl -n hw.ncpu` ${MAKE_EXTRA_ARGS}
cd ~
echo 'module TEST imports BOOL endmodule' > test.k
kompile test.k --backend ocaml
kompile test.k --backend llvm
kompile test.k --backend haskell
'''
dir('homebrew-k') {
sh '''
${WORKSPACE}/package/macos/brew-update-to-final ${PACKAGE} ${VERSION} ${ROOT_URL}
git commit Formula/$PACKAGE.rb -m "Update ${PACKAGE} to ${SHORT_REV}: part 3"
git push origin brew-release-$PACKAGE
'''
}
}
post {
always {
sh 'stop-kserver || true'
archiveArtifacts 'kserver.log,k-distribution/target/kserver.log'
}
}
}
}
post { always { archiveArtifacts artifacts: 'kserver.log,k-distribution/target/kserver.log', allowEmptyArchive: true } }
}
}
post {
failure {
slackSend color: '#cb2431' \
, channel: '#k' \
, message: "MacOS 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 {
AWS_ACCESS_KEY_ID = credentials('aws-access-key-id')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-access-key')
AWS_REGION = 'us-east-2'
GITHUB_TOKEN = credentials('rv-jenkins')
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
}
steps {
unstash 'src'
unstash 'binary'
dir('bionic') { unstash 'bionic' }
dir('focal') { unstash 'focal' }
dir('buster') { unstash 'buster' }
dir('arch') { unstash 'arch' }
dir('mojave') { unstash 'mojave' }
sshagent(['2b3d8d6b-0855-4b59-864a-6b3ddf9c9d1a']) {
sh '''
git clone 'ssh://github.com/kframework/k.git' k-release
cd k-release
git fetch --all
release_commit="$(git merge-base $LONG_REV origin/master)"
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}"
LOCAL_BOTTLE_NAME=$(find ../mojave -name "kframework--${VERSION}.mojave.bottle*.tar.gz")
BOTTLE_NAME=$(echo ${LOCAL_BOTTLE_NAME#../mojave/} | sed 's!kframework--!kframework-!')
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 ../buster/kframework_${VERSION}_amd64.deb kframework_${VERSION}_amd64_buster.deb
mv ../arch/kframework-git-${VERSION}-1-x86_64.pkg.tar.zst kframework-git-${VERSION}-1-x86_64.pkg.tar.zst
mv $LOCAL_BOTTLE_NAME $BOTTLE_NAME
mv ../k-nightly.tar.gz k-nightly_${VERSION}.tar.gz
echo "K Framework Release ${VERSION}" > release.md
echo '' >> release.md
cat k-distribution/INSTALL.md >> release.md
hub release create \
--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_buster.deb'#Debian Buster (10) Package' \
--attach kframework-git-${VERSION}-1-x86_64.pkg.tar.zst'#Arch Package' \
--attach $BOTTLE_NAME'#Mac OS X Homebrew Bottle' \
--attach k-nightly_${VERSION}.tar.gz'#Platform Indepdendent K Binary' \
--file release.md "${K_RELEASE_TAG}"
'''
}
dir('homebrew-k') {
git url: '[email protected]:kframework/homebrew-k.git', branch: 'brew-release-kframework'
sshagent(['2b3d8d6b-0855-4b59-864a-6b3ddf9c9d1a']) {
sh '''
git checkout master
git merge brew-release-$PACKAGE
git push origin master
git push origin -d brew-release-$PACKAGE
'''
}
}
}
}
stage('Update Dependents') {
when {
branch 'release'
beforeAgent true
}
steps {
build job: 'rv-devops/master', propagate: false, wait: false \
, parameters: [ booleanParam ( name: 'UPDATE_DEPS' , value: true ) \
, string ( name: 'UPDATE_DEPS_REPO' , value: 'kframework/k' ) \
, string ( name: 'UPDATE_DEPS_VERSION' , value: "${env.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(['2b3d8d6b-0855-4b59-864a-6b3ddf9c9d1a']) {
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(['2b3d8d6b-0855-4b59-864a-6b3ddf9c9d1a']) {
sh '''
git clone 'ssh://github.com/kframework/k' k-release
cd k-release
git fetch --all
git checkout -B release origin/release
git merge origin/master
./package/version.sh bump
./package/version.sh sub
git add -u
git commit -m "Set Version: $(cat package/version)"
git push origin release
'''
}
}
}
}
}