|
| 1 | +# Regenerate `api.md` from the engine's RPC registry once a day. |
| 2 | +# |
| 3 | +# `api.md` used to live in `nasty-project/nasty` next to the source it |
| 4 | +# was generated from. After it moved here in 2026-03 the regeneration |
| 5 | +# pipeline didn't come with it, so the file went stale. |
| 6 | +# |
| 7 | +# This workflow checks out the nasty repo's `main`, runs |
| 8 | +# `cargo run -p nasty-apidoc` (which walks every `JsonSchema`-derived |
| 9 | +# type and emits the markdown), copies the result on top of this |
| 10 | +# repo's `api.md`, and commits if anything changed. |
| 11 | +# |
| 12 | +# Up to ~24h lag behind the engine's RPC surface — fine for an API |
| 13 | +# reference, and avoids the cross-repo PAT setup the on-every-push |
| 14 | +# variant would need. |
| 15 | + |
| 16 | +name: Regenerate api.md |
| 17 | + |
| 18 | +on: |
| 19 | + schedule: |
| 20 | + # 04:00 UTC = quiet on the runner side, well after the integration |
| 21 | + # tests have finished their nightly cycle in the source repo. |
| 22 | + - cron: '0 4 * * *' |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +permissions: |
| 26 | + # Needed for the final `git push` of the regenerated file. |
| 27 | + contents: write |
| 28 | + |
| 29 | +concurrency: |
| 30 | + group: regen-api-md |
| 31 | + # Cancel any already-running daily — if the previous one is still |
| 32 | + # going we'd just race it to the same commit. |
| 33 | + cancel-in-progress: true |
| 34 | + |
| 35 | +jobs: |
| 36 | + regen: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + # 1. Check this repo out so we can commit the result back. |
| 40 | + - name: Checkout nasty-docs |
| 41 | + uses: actions/checkout@v5 |
| 42 | + with: |
| 43 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + # 2. Check the source repo (nasty) out into a sibling dir. The |
| 46 | + # nasty-apidoc binary writes to `<workspace>/docs/api.md` |
| 47 | + # relative to `engine/Cargo.toml`, so we capture from there. |
| 48 | + - name: Checkout nasty |
| 49 | + uses: actions/checkout@v5 |
| 50 | + with: |
| 51 | + repository: nasty-project/nasty |
| 52 | + ref: main |
| 53 | + path: nasty |
| 54 | + |
| 55 | + # 3. Rust toolchain pinned to what the source repo uses. Keep in |
| 56 | + # sync with `engine/rust-toolchain.toml` in the nasty repo — |
| 57 | + # bumping there is the trigger to bump here. |
| 58 | + - name: Set up Rust |
| 59 | + uses: dtolnay/rust-toolchain@1.95.0 |
| 60 | + |
| 61 | + # 4. Cache cargo artifacts across runs so this stays a 1-2 min |
| 62 | + # job in steady state. Cold cache is ~10 min; cache hit is |
| 63 | + # a couple of minutes for the build + the apidoc run itself. |
| 64 | + - name: Cargo cache |
| 65 | + uses: Swatinem/rust-cache@v2 |
| 66 | + with: |
| 67 | + workspaces: nasty/engine -> target |
| 68 | + |
| 69 | + - name: Generate api.md |
| 70 | + working-directory: nasty/engine |
| 71 | + run: cargo run --release -p nasty-apidoc |
| 72 | + |
| 73 | + - name: Copy generated api.md |
| 74 | + run: cp nasty/docs/api.md api.md |
| 75 | + |
| 76 | + # 5. Commit only if anything moved. `git diff --quiet` returns |
| 77 | + # 1 (= changes present) when api.md content drifted from the |
| 78 | + # last checked-in version. No-op runs are normal between |
| 79 | + # real engine changes. |
| 80 | + - name: Commit if changed |
| 81 | + run: | |
| 82 | + if git diff --quiet api.md; then |
| 83 | + echo "api.md unchanged, nothing to commit" |
| 84 | + exit 0 |
| 85 | + fi |
| 86 | + git config user.name "github-actions[bot]" |
| 87 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 88 | + # Source-repo HEAD SHA goes in the commit message so it's |
| 89 | + # obvious which engine state the regeneration captured. |
| 90 | + NASTY_SHA=$(git -C nasty rev-parse --short HEAD) |
| 91 | + git add api.md |
| 92 | + git commit -m "api.md: regenerate from nasty@${NASTY_SHA}" |
| 93 | + git push |
0 commit comments