ci: let Babashka download the pod instead of downloading it manually #25
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 | |
env: | |
BINARY_NAME: fosdem-dl | |
GRAALVM_VERSION: 23.0.0 | |
HEAP_SIZE_AT_BUILD_TIME: '-R:MaxHeapSize=1024m' | |
JAVA_VERSION: 21 | |
OPTIMIZATION_LEVEL: '-O2' | |
UBERJAR_NAME: fosdem-dl | |
jobs: | |
shared-outputs: | |
name: Shared outputs | |
runs-on: ubuntu-latest | |
# env: | |
# POD_JACKDBD_JSOUP_VERSION: 0.4.0 | |
# VERSION: 0.1.0-RC.1 | |
outputs: | |
is_prerelease: ${{ steps.set_outputs.outputs.is_prerelease }} | |
# pod_jackdbd_jsoup_path_linux: ${{ steps.set_outputs.outputs.pod_jackdbd_jsoup_path_linux }} | |
# pod_jackdbd_jsoup_path_macos: ${{ steps.set_outputs.outputs.pod_jackdbd_jsoup_path_macos }} | |
version: ${{ steps.set_outputs.outputs.version }} | |
steps: | |
- name: 🛎️ Checkout | |
uses: actions/checkout@v4 | |
- name: 🔧 Setup Babashka | |
uses: DeLaGuardo/[email protected] | |
with: | |
bb: 'latest' | |
# Note: if in bb.edn we declare a version of a pod using :path instead of | |
# :version (e.g. we have to do this when the pod is not registered on the | |
# pod registry), we can't run Babashka commands until we have downloaded | |
# that pod manually and moved it to the :path specified in bb.edn. | |
- 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 | |
# POD_JACKDBD_JSOUP_PATH_LINUX=/home/runner/.babashka/pods/repository/com.github.jackdbd/pod.jackdbd.jsoup/${{ env.POD_JACKDBD_JSOUP_VERSION }}/linux/x86_64/pod-jackdbd-jsoup | |
# echo "pod_jackdbd_jsoup_path_linux=$POD_JACKDBD_JSOUP_PATH_LINUX" >> $GITHUB_OUTPUT | |
# POD_JACKDBD_JSOUP_PATH_MACOS=/Users/runner/.babashka/pods/repository/com.github.jackdbd/pod.jackdbd.jsoup/${{ env.POD_JACKDBD_JSOUP_VERSION }}/mac_os_x/aarch64/pod-jackdbd-jsoup | |
# echo "pod_jackdbd_jsoup_path_macos=$POD_JACKDBD_JSOUP_PATH_MACOS" >> $GITHUB_OUTPUT | |
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 "pod_jackdbd_jsoup_path_linux is ${{ steps.set_outputs.outputs.pod_jackdbd_jsoup_path_linux }}" | |
# echo "pod_jackdbd_jsoup_path_macos is ${{ steps.set_outputs.outputs.pod_jackdbd_jsoup_path_macos }}" | |
echo "version is ${{ steps.set_outputs.outputs.version }}" | |
uberjar: | |
name: Uberjar | |
needs: [shared-outputs] | |
runs-on: ubuntu-latest | |
env: | |
# POD_JACKDBD_JSOUP_PATH_LINUX: ${{ needs.shared-outputs.outputs.pod_jackdbd_jsoup_path_linux }} | |
# POD_JACKDBD_JSOUP_PATH_MACOS: ${{ needs.shared-outputs.outputs.pod_jackdbd_jsoup_path_macos }} | |
VERSION: ${{ needs.shared-outputs.outputs.version }} | |
steps: | |
- name: 🛎️ Checkout | |
uses: actions/checkout@v4 | |
- name: 🔧 Setup Clojure CLI and Babashka | |
uses: DeLaGuardo/[email protected] | |
with: | |
cli: 'latest' | |
bb: 'latest' | |
# Downloading the pod manually should only be necessary if the version of | |
# the pod we want is not registered on the pod registry. | |
# This action uses the GitHub CLI. | |
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-github-cli-in-workflows | |
# - name: ⬇️ Download com.github.jackdbd/pod-jackdbd-jsoup | |
# env: | |
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# run: ./download_pod_jackdbd_jsoup.sh | |
- name: 📦 Build a Babashka uberjar | |
run: bb build:bb-uber | |
# Troubleshooting: Babashka pods should be somewhere here. | |
- run: ls -1 -R ~/.babashka | |
- name: "CLI talks --help" | |
run: bb target/${{env.UBERJAR_NAME }}-${{ env.VERSION }}.jar talks --help | |
- name: "CLI tracks --help" | |
run: bb target/${{env.UBERJAR_NAME }}-${{ env.VERSION }}.jar tracks --help | |
- name: ⬆️ Upload Babashka uberjar | |
uses: actions/upload-artifact@v4 | |
with: | |
name: bb-uberjar | |
path: target/${{ env.UBERJAR_NAME }}-${{ env.VERSION }}.jar | |
if-no-files-found: error | |
- name: 📦 Build normal uberjar | |
run: | | |
clojure -T:build clean | |
clojure -T:build uber | |
- name: ⬆️ Upload uberjar | |
uses: actions/upload-artifact@v4 | |
with: | |
name: uberjar | |
path: target/${{ env.UBERJAR_NAME }}-${{ env.VERSION }}-standalone.jar | |
if-no-files-found: error | |
# - name: ⬆️ Upload pod-jackdbd-jsoup (Linux) | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: pod-jackdbd-jsoup-linux | |
# path: ${{ env.POD_JACKDBD_JSOUP_PATH_LINUX }} | |
# if-no-files-found: error | |
# - name: ⬆️ Upload pod-jackdbd-jsoup (macOS) | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: pod-jackdbd-jsoup-macos | |
# path: ${{ env.POD_JACKDBD_JSOUP_PATH_MACOS }} | |
# if-no-files-found: error | |
- name: 🔍 Run all tests | |
run: bb test_runner.clj | |
# https://github.com/liquidz/babashka-test-action/ | |
# - name: Run babashka-test-action | |
# uses: liquidz/babashka-test-action@v1 | |
# with: | |
# source-paths: 'src' | |
# test-paths: 'test' | |
# test-file-pattern: '_test.clj$' | |
container-image: | |
name: Container image | |
needs: [shared-outputs] | |
runs-on: ubuntu-latest | |
steps: | |
- name: 🛎️ Checkout | |
uses: actions/checkout@v4 | |
- name: 🔧 Setup Clojure CLI and Babashka | |
uses: DeLaGuardo/[email protected] | |
with: | |
cli: 'latest' | |
bb: 'latest' | |
- name: 🐋 Build container image | |
run: bb container:build | |
# Print a few commands to double check that the CLI is working as expected | |
- run: bb container:cli help | |
- run: bb container:cli talks --help | |
- run: bb container:cli tracks --help | |
linux-amd64-binary: | |
name: Linux amd64 binary | |
needs: [shared-outputs] | |
runs-on: ubuntu-latest | |
env: | |
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 CLI and Babashka | |
uses: DeLaGuardo/[email protected] | |
with: | |
cli: 'latest' | |
bb: 'latest' | |
- name: 📦 Build Babashka uberjar | |
run: bb build:bb-uber | |
# - name: ⬇️ Download pod-jackdbd-jsoup-linux | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: pod-jackdbd-jsoup-linux | |
# - name: ⬇️ Download pod-jackdbd-jsoup-macos | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: pod-jackdbd-jsoup-macos | |
# - name: ⬇️ Download uberjar | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: uberjar | |
# - name: Copy uberjar and binary to target/ | |
# run: | | |
# mkdir target | |
# cp ${{ env.UBERJAR_NAME }}-${{ env.VERSION }}-standalone.jar target/ | |
- name: 📦 Compile uberjar to x86_64-linux binary with GraalVM native-image | |
run: ./script/compile.sh | |
- name: ⬆️ Upload Linux amd64 binary | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-amd64-binary | |
path: target/${{ env.BINARY_NAME }} | |
if-no-files-found: error | |
macos-aarch64-binary: | |
name: macOS aarch64 binary | |
needs: [shared-outputs] | |
runs-on: macos-latest | |
env: | |
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 Babashka | |
uses: DeLaGuardo/[email protected] | |
with: | |
bb: 'latest' | |
- name: 📦 Build Babashka uberjar | |
run: bb build:bb-uber | |
# Troubleshooting: Babashka pods should be somewhere here. | |
# - run: ls -1 -R ~/.babashka | |
# - name: ⬇️ Download uberjar | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: uberjar | |
# - name: Copy uberjar and binary to target/ | |
# run: | | |
# mkdir target | |
# cp ${{ env.UBERJAR_NAME }}-${{ env.VERSION }}-standalone.jar target/ | |
# TODO: bundle pod-jackdbd-jsoup when building with GraalVM native-image | |
- name: 📦 Compile uberjar to AArch64-macOS binary with GraalVM native-image | |
run: | | |
native-image -jar ${{ env.UBERJAR_NAME }}-${{ env.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' | |
github-release: | |
name: GitHub release | |
if: ${{ github.event_name != 'pull_request' }} | |
needs: [shared-outputs, uberjar, linux-amd64-binary, macos-aarch64-binary, container-image] | |
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: ⬇️ Download uberjar | |
uses: actions/download-artifact@v4 | |
with: | |
name: uberjar | |
- name: ⬇️ Download bb-uberjar | |
uses: actions/download-artifact@v4 | |
with: | |
name: bb-uberjar | |
# Troubleshooting: do we have every assets we want to include in the GitHub release? | |
- run: ls -la | |
# https://github.com/marketplace/actions/gh-release | |
- name: Add uberjar to GitHub release | |
uses: softprops/action-gh-release@v2 | |
id: github_release | |
with: | |
body: | | |
📦 **${{ env.UBERJAR_NAME }}** version `${{ env.VERSION }}`. | |
You will also need to download a [release of pod-jackdbd-jsoup](https://github.com/jackdbd/pod-jackdbd-jsoup/releases) and extact the pod to `resources/pod/pod-jackdbd-jsoup`. | |
# draft: true | |
fail_on_unmatched_files: true | |
# TODO: add all binaries compiled with GraalVM native-image | |
files: | | |
${{ env.UBERJAR_NAME }}-${{ env.VERSION }}-standalone.jar | |
${{ env.UBERJAR_NAME }}-${{ env.VERSION }}.jar | |
# 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 }} |