Skip to content

refactor: extract hm-util crate + modernize CancellationToken (#5) #54

refactor: extract hm-util crate + modernize CancellationToken (#5)

refactor: extract hm-util crate + modernize CancellationToken (#5) #54

Workflow file for this run

name: examples
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
# Cancel superseded runs on rapid pushes — 17-leg matrix is expensive.
concurrency:
group: examples-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
# Fail fast if the matrix list has drifted from examples/. Cheaper than
# waiting for 17 legs to finish and finding out a new example was added
# but never wired into CI.
validate-matrix:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
- name: Diff examples/ against matrix slugs
run: |
on_disk="$(ls examples | grep -v '^README\.md$' | sort)"
in_matrix="$(awk '/^ example:$/{flag=1;next}/^ steps:$/{flag=0}flag' .github/workflows/examples.yml \
| sed -n 's/^\s*- //p' | sort)"
if [ "$on_disk" != "$in_matrix" ]; then
echo "matrix list out of sync with examples/ directory" >&2
diff <(printf '%s\n' "$on_disk") <(printf '%s\n' "$in_matrix") >&2 || true
exit 1
fi
# Build `hm` once and share the binary across every matrix leg.
# Each leg only needs Python + Docker + the binary; making them
# re-compile the whole workspace 17× was the long tent-pole.
build-hm:
needs: validate-matrix
runs-on: ubuntu-latest
# Debug build only — examples just need a working `hm` binary;
# release-mode LTO/codegen on wasmtime+cranelift can't finish in
# GH's 6h cap on a 2-vCPU runner. Debug builds in ~10 minutes
# cold, ~1 minute warm.
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
# crates/hm/build.rs cross-compiles hm-plugin-docker as a wasm
# plugin embedded into the binary, so the target must be on
# the toolchain.
targets: wasm32-wasip1
- uses: Swatinem/rust-cache@v2
with:
shared-key: examples-hm
- name: Build hm
run: cargo build -p harmont-cli
- uses: actions/upload-artifact@v4
with:
name: hm-bin
path: target/debug/hm
retention-days: 1
if-no-files-found: error
run-example:
needs: build-hm
name: ${{ matrix.example }}
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
example:
- c
- cpp
- csharp
- go
- haskell
- java
- kotlin
- nextjs
- ocaml
- perl
- php-laravel
- python-uv
- react
- ruby
- rust
- typescript
- zig-js
- zig
steps:
- uses: actions/checkout@v4
# `hm run` shells out to `/usr/bin/python3` with PATH restricted
# to /usr/bin:/usr/local/bin:/bin (see render.rs), so harmont-py
# has to land in the *system* Python's site-packages — not the
# actions/setup-python hostedtoolcache. PEP 668's
# externally-managed marker requires --break-system-packages.
- name: Install harmont-py into system Python
run: |
git clone --depth 1 https://github.com/harmont-dev/harmont-py /tmp/harmont-py
sudo /usr/bin/python3 -m pip install --break-system-packages /tmp/harmont-py
/usr/bin/python3 -c "import harmont; print('harmont', harmont.__file__)"
- name: Download hm binary
uses: actions/download-artifact@v4
with:
name: hm-bin
path: bin
- name: Mark hm executable
run: chmod +x bin/hm
- name: Run example via hm run
working-directory: examples/${{ matrix.example }}
env:
HM_NONINTERACTIVE: '1'
run: ${{ github.workspace }}/bin/hm run ci