-
Notifications
You must be signed in to change notification settings - Fork 0
496 lines (416 loc) Β· 18.3 KB
/
ci-cd.yaml
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
name: 'CI/CD'
on:
pull_request:
push:
branches:
- canary
- main
# GitHub hosted runners are available for Linux x64, Windows x64, and macOS (x64 and arm).
# https://docs.github.com/en/actions/using-github-hosted-runners/using-larger-runners/about-larger-runners#runner-images
# https://github.com/actions/runner-images
# There are other providers that offer ARM runners for Linux (e.g. WarpBuild).
# https://github.com/neysofu/awesome-github-actions-runners#list-of-providers
env:
GRAALVM_VERSION: 23.0.0
HEAP_SIZE_AT_BUILD_TIME: '-R:MaxHeapSize=1024m'
JAVA_VERSION: 21
OPTIMIZATION_LEVEL: '-O2'
UBERJAR_ID: pod.jackdbd.jsoup # See deps.edn and the pom.xml generated when building the uberjar.
BINARY_NAME: pod-jackdbd-jsoup
jobs:
shared-outputs:
name: Shared outputs
runs-on: ubuntu-latest
outputs:
is_prerelease: ${{ steps.set_outputs.outputs.is_prerelease }}
version: ${{ steps.set_outputs.outputs.version }}
steps:
- name: ποΈ Checkout
uses: actions/checkout@v4
- name: π§ Setup Babashka
uses: DeLaGuardo/setup-clojure@12.5
with:
bb: 'latest'
- name: Set job outputs
id: set_outputs
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "is_prerelease=false" >> $GITHUB_OUTPUT
else
echo "is_prerelease=true" >> $GITHUB_OUTPUT
fi
VERSION=$(bb -e '(-> (slurp "deps.edn") edn/read-string :aliases :neil :project :version)' | tr -d '"')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Log job outputs
run: |
echo "is_prerelease is ${{ steps.set_outputs.outputs.is_prerelease }}"
echo "version is ${{ steps.set_outputs.outputs.version }}"
uberjar:
name: Uberjar
runs-on: ubuntu-latest
needs: [shared-outputs]
env:
UBERJAR_VERSION: ${{ needs.shared-outputs.outputs.version }}
steps:
- name: ποΈ Checkout
uses: actions/checkout@v4
# https://github.com/marketplace/actions/github-action-for-graalvm
- name: π§ Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
check-for-updates: true
distribution: graalvm-community
java-version: ${{ env.JAVA_VERSION }}
version: ${{ env.GRAALVM_VERSION }}
# It's important to install java before installing clojure tools, because
# clojure tools needs java exclusions: babashka, clj-kondo and cljstyle.
# https://github.com/marketplace/actions/setup-clojure
- name: π§ Setup Clojure tools
uses: DeLaGuardo/setup-clojure@12.5
with:
cli: 'latest' # Clojure CLI based on tools.deps
# https://github.com/actions/cache
- name: Cache clojure dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
# List all files containing dependencies:
# key: cljdeps-${{ hashFiles('deps.edn') }}
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-
- name: π¦ Compile uberjar
run: clojure -T:build uber
- name: β¬οΈ Upload uberjar
uses: actions/upload-artifact@v4
with:
name: uberjar
path: target/${{ env.UBERJAR_ID }}-${{ env.UBERJAR_VERSION }}-standalone.jar
if-no-files-found: error
linux-amd64-binary:
name: Linux amd64 binary, Test
runs-on: ubuntu-latest
needs: [shared-outputs, uberjar]
env:
UBERJAR_VERSION: ${{ needs.shared-outputs.outputs.version }}
steps:
- name: ποΈ Checkout
uses: actions/checkout@v4
- name: π§ Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
check-for-updates: true
distribution: graalvm-community
java-version: ${{ env.JAVA_VERSION }}
native-image-job-reports: true
native-image-musl: true # Use musl to build a statically compiled binary (Linux only)
native-image-pr-reports: true
version: ${{ env.GRAALVM_VERSION }}
- name: π§ Setup Clojure tools
uses: DeLaGuardo/setup-clojure@12.5
with:
cli: 'latest'
- name: Cache clojure dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
# List all files containing dependencies:
# key: cljdeps-${{ hashFiles('deps.edn') }}
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-
# This takes ~7 minutes both on my laptop and on GitHub Actions. Maybe look for an alternative.
# - name: π‘οΈ Audit deps.edn dependencies
# run: clojure -M:clj-nvd check
- name: β¬οΈ Download uberjar
uses: actions/download-artifact@v4
with:
name: uberjar
- name: π¦ Compile uberjar to amd64-linux binary with GraalVM native-image
run: ./script/compile.sh
# The tests expect the uberjar and the binary to be in a directory called "target"
- name: Copy uberjar and binary to target/
run: |
mkdir target
cp ${{ env.UBERJAR_ID }}-${{ env.UBERJAR_VERSION }}-standalone.jar target/
cp ${{ env.BINARY_NAME }} target/
- name: β¬οΈ Upload amd64 Linux binary
uses: actions/upload-artifact@v4
with:
name: ubuntu-latest-amd64-binary
path: target/${{ env.BINARY_NAME }}
if-no-files-found: error
- name: π Run all tests
run: clojure -X:test
macos-aarch64-binary:
name: macOS aarch64 binary, Test
runs-on: macOS-latest
needs: [shared-outputs, uberjar]
env:
UBERJAR_VERSION: ${{ needs.shared-outputs.outputs.version }}
steps:
- name: ποΈ Checkout
uses: actions/checkout@v4
- name: π§ Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
check-for-updates: true
distribution: graalvm-community
java-version: ${{ env.JAVA_VERSION }}
native-image-job-reports: true
native-image-pr-reports: true
version: ${{ env.GRAALVM_VERSION }}
- name: π§ Setup Clojure tools
uses: DeLaGuardo/setup-clojure@12.5
with:
cli: 'latest'
- name: Cache clojure dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-
- name: β¬οΈ Download uberjar
uses: actions/download-artifact@v4
with:
name: uberjar
- name: π¦ Compile uberjar to AArch64-macOS binary with GraalVM native-image
# I tried setting -march=x86_64 and the GitHub hosted runner macos-latest
# gave me this error:
# On AArch64, only 'ARMV8_A', 'ARMV8_1_A', 'COMPATIBILITY', 'NATIVE' are available.
run: |
native-image -jar ${{ env.UBERJAR_ID }}-${{ env.UBERJAR_VERSION }}-standalone.jar ${{ env.BINARY_NAME }} \
'-H:ReflectionConfigurationFiles=reflection.json' \
'-H:+ReportExceptionStackTraces' \
'-J-Dclojure.compiler.direct-linking=true' \
${{ env.HEAP_SIZE_AT_BUILD_TIME }} \
${{ env.OPTIMIZATION_LEVEL }} \
'-march=armv8-a' \
'--initialize-at-build-time' \
'--native-image-info' \
'--no-fallback' \
'--report-unsupported-elements-at-runtime'
# The tests expect the uberjar and the binary to be in a directory called "target"
- name: Copy uberjar and binary to target/
run: |
mkdir target
cp ${{ env.UBERJAR_ID }}-${{ env.UBERJAR_VERSION }}-standalone.jar target/
cp ${{ env.BINARY_NAME }} target/
- name: β¬οΈ Upload aarch64 macOS binary
uses: actions/upload-artifact@v4
with:
name: macos-latest-aarch64-binary
path: target/${{ env.BINARY_NAME }}
if-no-files-found: error
- name: π Run all tests
run: clojure -X:test
windows-amd64-binary:
name: Windows amd64 binary, Test
runs-on: windows-latest
needs: [shared-outputs, uberjar]
env:
UBERJAR_VERSION: ${{ needs.shared-outputs.outputs.version }}
steps:
- name: ποΈ Checkout
uses: actions/checkout@v4
- name: π§ Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
check-for-updates: true
distribution: graalvm-community
java-version: ${{ env.JAVA_VERSION }}
native-image-job-reports: true
native-image-pr-reports: true
version: ${{ env.GRAALVM_VERSION }}
- name: π§ Setup Clojure tools
uses: DeLaGuardo/setup-clojure@12.5
with:
cli: 'latest'
- name: Cache clojure dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-
- name: β¬οΈ Download uberjar
uses: actions/download-artifact@v4
with:
name: uberjar
# When compiling a windows executable, native-image adds the `.exe` extension.
# See: https://github.com/babashka/pod-babashka-buddy/blob/main/script/compile.bat
- name: π¦ Compile uberjar to amd64-windows binary with GraalVM native-image
run: >
native-image -jar ${{ env.UBERJAR_ID }}-${{ env.UBERJAR_VERSION }}-standalone.jar ${{ env.BINARY_NAME }}
'-H:ReflectionConfigurationFiles=reflection.json'
'-H:+ReportExceptionStackTraces'
'-J-Dclojure.compiler.direct-linking=true'
${{ env.HEAP_SIZE_AT_BUILD_TIME }}
${{ env.OPTIMIZATION_LEVEL }}
'-march=x86-64-v3'
'--initialize-at-build-time'
'--native-image-info'
'--no-fallback'
'--report-unsupported-elements-at-runtime'
- name: Copy uberjar and binary to target/
run: |
mkdir target
move ${{ env.UBERJAR_ID }}-${{ env.UBERJAR_VERSION }}-standalone.jar target\\${{ env.UBERJAR_ID }}-${{ env.UBERJAR_VERSION }}-standalone.jar
move ${{ env.BINARY_NAME }}.exe target\\${{ env.BINARY_NAME }}.exe
shell: cmd
# Troubleshooting: Windows command prompt equivalent for `ls -la`
- run: dir /A /Q
shell: cmd
- name: β¬οΈ Upload amd64-windows binary
uses: actions/upload-artifact@v4
with:
name: windows-latest-amd64-binary
path: ".\\target\\${{ env.BINARY_NAME }}.exe"
if-no-files-found: error
- name: π Run all tests
run: clojure -X:test
clojars-release:
name: Clojars release
if: ${{ github.event_name != 'pull_request' }}
# Only the uberjar is published to Clojars, but since some tests require the
# native binary (for Linux/macOS/Windows), I have to wait for those tests to
# pass before publishing the uberjar to Clojars.
needs: [shared-outputs, linux-amd64-binary, macos-aarch64-binary, windows-amd64-binary] # publish only when all tests on all platforms pass
runs-on: ubuntu-latest
env:
ARTIFACT_VERSION: ${{ needs.shared-outputs.outputs.version }}
permissions:
contents: write
steps:
- name: ποΈ Checkout
uses: actions/checkout@v4
- name: π§ Setup Clojure tools
uses: DeLaGuardo/setup-clojure@12.5
with:
cli: 'latest'
- name: π¦ Compile uberjar
run: clojure -T:build uber
- name: π Publish version ${{ env.ARTIFACT_VERSION }} to Clojars
env:
CLOJARS_USERNAME: jackdbd
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
run: clojure -T:build deploy
- name: Tag release commit and push it
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#about-contexts
env:
BOT_NAME: commit-tagger[bot]
run: |
git config user.name "Commit Tagger Bot"
git config user.email "commit-tagger-bot@giacomodebidda.com"
git tag -a v${{ env.ARTIFACT_VERSION }} -m "This version was published to Clojars: https://clojars.org/com.github.jackdbd/pod.jackdbd.jsoup/versions/${{ env.ARTIFACT_VERSION }}"
git remote set-url origin https://${{ env.BOT_NAME }}:${{ github.token }}@github.com/${{ github.repository }}.git
git push origin v${{ env.ARTIFACT_VERSION }}
github-release:
name: GitHub release
if: ${{ github.event_name != 'pull_request' }}
needs: [shared-outputs, uberjar, linux-amd64-binary, macos-aarch64-binary, windows-amd64-binary, clojars-release]
runs-on: ubuntu-latest
env:
IS_PRERELEASE: ${{ needs.shared-outputs.outputs.is_prerelease }}
VERSION: ${{ needs.shared-outputs.outputs.version }}
permissions:
contents: write
steps:
- name: ποΈ Checkout
uses: actions/checkout@v4
- name: π§ Setup Babashka
uses: DeLaGuardo/setup-clojure@12.5
with:
bb: 'latest'
cljfmt: 'latest'
- name: β¬οΈ Download uberjar
uses: actions/download-artifact@v4
with:
name: uberjar
- name: β¬οΈ Download amd64-linux binary
uses: actions/download-artifact@v4
with:
name: ubuntu-latest-amd64-binary
path: ubuntu-latest-amd64
- name: β¬οΈ Download aarch64 macOS binary
uses: actions/download-artifact@v4
with:
name: macos-latest-aarch64-binary
path: macos-latest-aarch64
- name: β¬οΈ Download amd64-windows binary
uses: actions/download-artifact@v4
with:
name: windows-latest-amd64-binary
path: windows-latest-amd64
- name: π¦ Create archives for all assets to be included in the GitHub release
run: |
pushd . && cd ubuntu-latest-amd64 && zip "${{ env.BINARY_NAME }}-${{ env.VERSION }}-ubuntu-latest-amd64.zip" "${{ env.BINARY_NAME }}" && popd
pushd . && cd macos-latest-aarch64 && zip "${{ env.BINARY_NAME }}-${{ env.VERSION }}-macos-latest-aarch64.zip" "${{ env.BINARY_NAME }}" && popd
pushd . && cd windows-latest-amd64 && zip "${{ env.BINARY_NAME }}-${{ env.VERSION }}-windows-latest-amd64.zip" "${{ env.BINARY_NAME }}.exe" && popd
mv ubuntu-latest-amd64/${{ env.BINARY_NAME }}-${{ env.VERSION }}-ubuntu-latest-amd64.zip .
mv macos-latest-aarch64/${{ env.BINARY_NAME }}-${{ env.VERSION }}-macos-latest-aarch64.zip .
mv windows-latest-amd64/${{ env.BINARY_NAME }}-${{ env.VERSION }}-windows-latest-amd64.zip .
# Troubleshooting: do we have every assets we want to include in the GitHub release?
- run: ls -la
# - run: ls -R
# https://github.com/marketplace/actions/gh-release
- name: π Create or update GitHub release
uses: softprops/action-gh-release@v2
id: github_release
with:
body: |
π¦ **${{ env.BINARY_NAME }}** version `${{ env.VERSION }}` is [available on Clojars](https://clojars.org/com.github.jackdbd/pod.jackdbd.jsoup/versions/${{ env.VERSION }}).
# draft: true
fail_on_unmatched_files: true
files: |
${{ env.UBERJAR_ID }}-${{ env.VERSION }}-standalone.jar
${{ env.BINARY_NAME }}-${{ env.VERSION }}-macos-latest-aarch64.zip
${{ env.BINARY_NAME }}-${{ env.VERSION }}-ubuntu-latest-amd64.zip
${{ env.BINARY_NAME }}-${{ env.VERSION }}-windows-latest-amd64.zip
# body is prepended to these automatically generated release notes.
# See here for how to configure these release notes:
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes
generate_release_notes: true
name: v${{ env.VERSION }}
prerelease: ${{ env.IS_PRERELEASE }}
tag_name: v${{ env.VERSION }}
# Troubleshooting: show help of manifest.edn CLI
- run: bb bb/manifest.bb --help
# ATTENTION: the order of `steps.github_release.outputs.assets` depends on
# the order of the `files` defined in the `github_release` step.
# https://github.com/marketplace/actions/gh-release#outputs
- name: π Create manifest.edn
run: |
RELEASE_URL=${{ steps.github_release.outputs.url }}
RELEASE_ID=${{ steps.github_release.outputs.id }}
UPLOAD_URL=${{ steps.github_release.outputs.upload_url }}
ASSETS=${{ steps.github_release.outputs.assets }}
UBERJAR_URL=${{ fromJSON(steps.github_release.outputs.assets)[0].browser_download_url }}
MACOS_LATEST_AARCH64_ZIP_URL=${{ fromJSON(steps.github_release.outputs.assets)[1].browser_download_url }}
UBUNTU_LATEST_amd64_ZIP_URL=${{ fromJSON(steps.github_release.outputs.assets)[2].browser_download_url }}
WINDOWS_LATEST_amd64_ZIP_URL=${{ fromJSON(steps.github_release.outputs.assets)[3].browser_download_url }}
echo "RELEASE_URL is $RELEASE_URL"
echo "UBERJAR_URL is $UBERJAR_URL"
echo "MACOS_LATEST_AARCH64_ZIP_URL is $MACOS_LATEST_AARCH64_ZIP_URL"
echo "UBUNTU_LATEST_amd64_ZIP_URL is $UBUNTU_LATEST_amd64_ZIP_URL"
echo "WINDOWS_LATEST_amd64_ZIP_URL is $WINDOWS_LATEST_amd64_ZIP_URL"
bb bb/manifest.bb --uberjar $UBERJAR_URL --linux-amd64 $UBUNTU_LATEST_amd64_ZIP_URL --macos-aarch64 $MACOS_LATEST_AARCH64_ZIP_URL --windows-amd64 $WINDOWS_LATEST_amd64_ZIP_URL
cljfmt fix --remove-multiple-non-indenting-spaces --split-keypairs-over-multiple-lines manifest.edn
echo "Here is the manifest.edn generated"
cat manifest.edn
# Don't forget to register the pod: open a PR on Babashka Pod registry and upload the manifest.edn there.
- name: π Add manifest.edn to GitHub release
uses: softprops/action-gh-release@v2
with:
files: |
manifest.edn
tag_name: v${{ env.VERSION }}