faster builds #5
This file contains hidden or 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: examples | |
| on: | |
| push: | |
| 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 | |
| timeout-minutes: 20 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| - uses: Swatinem/rust-cache@v2 | |
| with: | |
| shared-key: examples-hm | |
| - name: Build hm | |
| run: cargo build --release -p harmont-cli | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: hm-bin | |
| path: target/release/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 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install harmont-py | |
| run: | | |
| git clone --depth 1 https://github.com/harmont-dev/harmont-py /tmp/harmont-py | |
| pip install /tmp/harmont-py | |
| - 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: | |
| # The CLI shells out to `python3 -m harmont` to render the | |
| # pipeline; the system Python on the runner is what setup-python | |
| # just installed. | |
| HM_NONINTERACTIVE: '1' | |
| run: ${{ github.workspace }}/bin/hm run ci |