ci: fix if expression #64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
POD_ID: pod.jackdbd.jsoup | |
POD_NAME: pod-jackdbd-jsoup | |
jobs: | |
set-shared-outputs: | |
name: Set shared outputs | |
runs-on: ubuntu-latest | |
outputs: | |
pod_version: ${{ steps.set_outputs.outputs.pod_version }} | |
prerelease: ${{ steps.set_outputs.outputs.prerelease }} | |
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: | | |
POD_VERSION=$(bb -e '(-> (slurp "deps.edn") edn/read-string :aliases :neil :project :version)' | tr -d '"') | |
echo "pod_version=$POD_VERSION" >> $GITHUB_OUTPUT | |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
echo "PRERELEASE=false" >> $GITHUB_ENV | |
else | |
echo "PRERELEASE=true" >> $GITHUB_ENV | |
fi | |
echo "prerelease=$PRERELEASE" >> $GITHUB_OUTPUT | |
- name: Log job outputs | |
run: | | |
echo "pod_version is ${{ steps.set_outputs.outputs.pod_version }}" | |
echo "prerelease is ${{ steps.set_outputs.outputs.prerelease }}" | |
build-uberjar: | |
name: Build uberjar | |
runs-on: ubuntu-latest | |
needs: [set-shared-outputs] | |
env: | |
POD_VERSION: ${{ needs.set-shared-outputs.outputs.pod_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 pod into an uberjar | |
run: clojure -T:build uber | |
- name: β¬οΈ Upload uberjar | |
uses: actions/upload-artifact@v4 | |
with: | |
name: uberjar | |
path: target/${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar | |
linux: | |
name: Compile ubuntu-latest-x86_64-binary, Test | |
runs-on: ubuntu-latest | |
needs: [set-shared-outputs, build-uberjar] | |
env: | |
POD_VERSION: ${{ needs.set-shared-outputs.outputs.pod_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 x86_64-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 the uberjar and the binary to the target directory | |
run: | | |
mkdir target | |
cp ${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar target/ | |
cp ${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone target/${{ env.POD_NAME }} | |
- name: β¬οΈ Upload the x86_64 Linux binary | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ubuntu-latest-x86_64-binary | |
path: target/${{ env.POD_NAME }} | |
- name: π Run all tests | |
run: clojure -X:test | |
macos: | |
name: Compile macos-latest-aarch64-binary, Test | |
runs-on: macOS-latest | |
needs: [set-shared-outputs, build-uberjar] | |
env: | |
POD_VERSION: ${{ needs.set-shared-outputs.outputs.pod_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.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar \ | |
'-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 the uberjar and the binary to the target directory | |
run: | | |
mkdir target | |
cp ${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar target/ | |
cp ${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone target/${{ env.POD_NAME }} | |
- name: β¬οΈ Upload the aarch64 macOS binary | |
uses: actions/upload-artifact@v4 | |
with: | |
name: macos-latest-aarch64-binary | |
path: target/${{ env.POD_NAME }} | |
- name: π Run all tests | |
run: clojure -X:test | |
windows: | |
name: Compile windows-latest-x86_64-binary, Test | |
runs-on: windows-latest | |
needs: [set-shared-outputs, build-uberjar] | |
env: | |
POD_VERSION: ${{ needs.set-shared-outputs.outputs.pod_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 | |
# See: https://github.com/babashka/pod-babashka-buddy/blob/main/script/compile.bat | |
- name: π¦ Compile uberjar to x86_64-windows binary with GraalVM native-image | |
run: > | |
native-image | |
-jar ${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar | |
'-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 the uberjar and the binary to the target directory | |
run: | | |
mkdir target | |
move ${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar target\\${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar | |
move "${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.exe" ".\\target\\${{ env.POD_NAME }}.exe" | |
shell: cmd | |
- name: β¬οΈ Upload the x86_64 Windows binary | |
uses: actions/upload-artifact@v4 | |
with: | |
name: windows-latest-x86_64-binary | |
path: ".\\target\\${{ env.POD_NAME }}.exe" | |
- name: π Run all tests | |
run: clojure -X:test | |
clojars: | |
name: Publish to Clojars | |
if: ${{ github.event_name != 'pull_request' }} | |
needs: [linux, macos, windows] # publish only when all tests on all platforms pass | |
runs-on: ubuntu-latest | |
steps: | |
- name: ποΈ Checkout | |
uses: actions/checkout@v4 | |
- name: π§ Setup Clojure tools | |
uses: DeLaGuardo/setup-clojure@12.5 | |
with: | |
cli: 'latest' | |
- name: π¦ Compile pod into an uberjar | |
run: clojure -T:build uber | |
- name: π Publish to Clojars | |
env: | |
CLOJARS_USERNAME: jackdbd | |
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} | |
run: clojure -T:build deploy | |
tag-latest-snapshot: | |
name: Tag commit associated with latest snapshot version on Clojars | |
if: ${{ github.event_name != 'pull_request' && github.ref != 'refs/heads/main' }} | |
needs: [set-shared-outputs, clojars] | |
runs-on: ubuntu-latest | |
env: | |
POD_VERSION: ${{ needs.set-shared-outputs.outputs.pod_version }} | |
steps: | |
- name: ποΈ Checkout | |
uses: actions/checkout@v4 | |
- name: Tag commit | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "<>" | |
git status | |
git tag -a v${{ env.POD_VERSION }} -m "This version was published to Clojars: https://clojars.org/com.github.jackdbd/pod.jackdbd.jsoup/versions/${{ env.POD_VERSION }}" --force | |
git describe | |
github-release: | |
name: GitHub release | |
if: ${{ github.event_name != 'pull_request' }} | |
needs: [set-shared-outputs, build-uberjar, linux, macos, windows, clojars] | |
runs-on: ubuntu-latest | |
env: | |
POD_VERSION: ${{ needs.set-shared-outputs.outputs.pod_version }} | |
PRERELEASE: ${{ needs.set-shared-outputs.outputs.prerelease }} | |
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 x86_64 Linux binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: ubuntu-latest-x86_64-binary | |
path: ubuntu-latest-x86_64 | |
- name: β¬οΈ Download aarch64 macOS binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: macos-latest-aarch64-binary | |
path: macos-latest-aarch64 | |
- name: β¬οΈ Download x86_64 Windows binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: windows-latest-x86_64-binary | |
path: windows-latest-x86_64 | |
- name: π¦ Create archives for all assets to be included in the GitHub release | |
run: | | |
pushd . && cd ubuntu-latest-x86_64 && zip "${{ env.POD_NAME }}-${{ env.POD_VERSION }}-ubuntu-latest-x86_64.zip" "pod-jackdbd-jsoup" && popd | |
pushd . && cd macos-latest-aarch64 && zip "${{ env.POD_NAME }}-${{ env.POD_VERSION }}-macos-latest-aarch64.zip" "pod-jackdbd-jsoup" && popd | |
pushd . && cd windows-latest-x86_64 && zip "${{ env.POD_NAME }}-${{ env.POD_VERSION }}-windows-latest-x86_64.zip" "pod-jackdbd-jsoup.exe" && popd | |
mv ubuntu-latest-x86_64/${{ env.POD_NAME }}-${{ env.POD_VERSION }}-ubuntu-latest-x86_64.zip . | |
mv macos-latest-aarch64/${{ env.POD_NAME }}-${{ env.POD_VERSION }}-macos-latest-aarch64.zip . | |
mv windows-latest-x86_64/${{ env.POD_NAME }}-${{ env.POD_VERSION }}-windows-latest-x86_64.zip . | |
# Troubleshooting: do we have every assets we want to include in the GitHub release? | |
# - 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: | | |
This is a release of **${{ env.POD_NAME }}** version `${{ env.POD_VERSION }}`. | |
The pod is also [published as an uberjar to Clojars](https://clojars.org/com.github.jackdbd/pod.jackdbd.jsoup). | |
# draft: true | |
fail_on_unmatched_files: true | |
files: | | |
${{ env.POD_ID }}-${{ env.POD_VERSION }}-standalone.jar | |
${{ env.POD_NAME }}-${{ env.POD_VERSION }}-macos-latest-aarch64.zip | |
${{ env.POD_NAME }}-${{ env.POD_VERSION }}-ubuntu-latest-x86_64.zip | |
${{ env.POD_NAME }}-${{ env.POD_VERSION }}-windows-latest-x86_64.zip | |
generate_release_notes: false # TODO: decide whether to use this or not | |
name: v${{ env.POD_VERSION }} | |
prerelease: ${{ env.PRERELEASE }} | |
tag_name: v${{ env.POD_VERSION }} | |
# 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_x86_64_ZIP_URL=${{ fromJSON(steps.github_release.outputs.assets)[2].browser_download_url }} | |
WINDOWS_LATEST_x86_64_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_x86_64_ZIP_URL is $UBUNTU_LATEST_x86_64_ZIP_URL" | |
echo "WINDOWS_LATEST_x86_64_ZIP_URL is $WINDOWS_LATEST_x86_64_ZIP_URL" | |
bb bb/manifest.bb --uberjar $UBERJAR_URL --linux-x86_64 $UBUNTU_LATEST_x86_64_ZIP_URL --macos-aarch64 $MACOS_LATEST_AARCH64_ZIP_URL --windows-x86_64 $WINDOWS_LATEST_x86_64_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.POD_VERSION }} |