|
6 | 6 | # |
7 | 7 | # HOW THE BASELINE GETS HERE |
8 | 8 | # -------------------------- |
9 | | -# The gate needs something to compare against. This workflow pins a baseline from the PR's |
10 | | -# own merge-base checkout, which requires no artifact plumbing and works on a fresh clone. |
| 9 | +# The gate needs a "before" to compare against. The default branch publishes its snapshot |
| 10 | +# once; every PR restores that artifact and diffs against it. The PR job therefore indexes |
| 11 | +# the tree ONCE — it never re-indexes the base — and needs no merge-base checkout and no |
| 12 | +# full-history clone. |
11 | 13 | # |
12 | | -# `fetch-depth: 0` is required. actions/checkout defaults to a depth-1 clone, which has no |
13 | | -# merge-base to check out, and the gate would silently have nothing to compare against. |
| 14 | +# This works because a baseline is portable: `enola check` identifies a repository by its |
| 15 | +# normalized git remote (falling back to the checkout directory name), not by the absolute |
| 16 | +# path it was snapshotted at, so a baseline pinned on one runner grades against a checkout |
| 17 | +# anywhere else. |
14 | 18 | # |
15 | | -# A faster arrangement — publish the snapshot from the default branch once and restore it |
16 | | -# here instead of re-indexing the base — needs baselines to survive moving between |
17 | | -# machines, which they do not yet: comparability compares the absolute repo path, so a |
18 | | -# baseline pinned under one checkout path declines to grade under another. |
| 19 | +# Sizing: roughly 550 KB of gzipped artifact per ~17k facts. For a very large monorepo, |
| 20 | +# prefer actions/cache over a per-run artifact. |
19 | 21 | name: architecture |
20 | 22 |
|
21 | 23 | on: |
| 24 | + push: |
| 25 | + branches: [main] |
22 | 26 | pull_request: |
23 | 27 |
|
24 | 28 | jobs: |
25 | | - gate: |
| 29 | + # Publishes the baseline every time the default branch moves. PRs consume the most |
| 30 | + # recent successful run of this job. |
| 31 | + publish-baseline: |
| 32 | + if: github.event_name == 'push' |
26 | 33 | runs-on: ubuntu-latest |
27 | 34 | steps: |
28 | 35 | - uses: actions/checkout@v4 |
29 | | - with: |
30 | | - fetch-depth: 0 |
31 | 36 |
|
32 | 37 | - name: Install enola |
33 | 38 | run: | |
34 | 39 | curl -fsSL https://raw.githubusercontent.com/enola-labs/enola/main/install.sh | sh |
35 | 40 | echo "$HOME/.local/bin" >> "$GITHUB_PATH" |
36 | 41 |
|
37 | | - - name: Pin a baseline from the merge base |
38 | | - run: | |
39 | | - # Record the PR head as an explicit SHA before moving: `git checkout -` is |
40 | | - # unreliable after a --detach, and returning to the wrong commit would make the |
41 | | - # gate grade the base branch against itself and always report clean. |
42 | | - head=$(git rev-parse HEAD) |
43 | | - base=$(git merge-base "$head" "origin/${{ github.base_ref }}") |
44 | | - echo "Baseline commit: $base" |
45 | | - echo "PR head: $head" |
| 42 | + - name: Pin the baseline |
| 43 | + run: enola baseline pin |
| 44 | + |
| 45 | + - uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: enola-baseline |
| 48 | + path: .enola/baseline/ |
| 49 | + retention-days: 30 |
| 50 | + |
| 51 | + gate: |
| 52 | + if: github.event_name == 'pull_request' |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
46 | 56 |
|
47 | | - git checkout --quiet --detach "$base" |
48 | | - enola --generate |
49 | | - enola baseline pin |
| 57 | + - name: Install enola |
| 58 | + run: | |
| 59 | + curl -fsSL https://raw.githubusercontent.com/enola-labs/enola/main/install.sh | sh |
| 60 | + echo "$HOME/.local/bin" >> "$GITHUB_PATH" |
50 | 61 |
|
51 | | - # .enola/ is untracked, so the pinned baseline survives the checkout back. |
52 | | - git checkout --quiet --detach "$head" |
| 62 | + # The baseline comes from the newest successful publish-baseline run on the default |
| 63 | + # branch. `continue-on-error` covers the first-ever run, before any baseline has been |
| 64 | + # published — see the next step. |
| 65 | + - name: Fetch the published baseline |
| 66 | + id: baseline |
| 67 | + continue-on-error: true |
| 68 | + uses: dawidd6/action-download-artifact@v6 |
| 69 | + with: |
| 70 | + workflow: architecture.yml |
| 71 | + branch: main |
| 72 | + name: enola-baseline |
| 73 | + path: baseline |
| 74 | + if_no_artifact_found: fail |
53 | 75 |
|
54 | 76 | - name: Grade the change |
55 | | - run: enola check |
| 77 | + run: | |
| 78 | + if [ "${{ steps.baseline.outcome }}" != "success" ]; then |
| 79 | + echo "No published baseline yet — skipping the gate." |
| 80 | + echo "It will start enforcing once publish-baseline has run on the default branch." |
| 81 | + exit 0 |
| 82 | + fi |
| 83 | + enola check --baseline baseline |
56 | 84 |
|
57 | 85 | # `enola check` exit codes: |
58 | 86 | # 0 clean · 1 regression (job fails) · 2 error · 3 declined (not comparable) |
59 | 87 | # |
60 | | - # Codes 2 and 3 fail the job here by design: in CI they mean the gate did not |
61 | | - # actually run, and a gate that silently passes when it could not run is worse than |
62 | | - # no gate. Add `|| [ $? -eq 3 ]` if you would rather treat "declined" as a pass |
63 | | - # while rolling this out. |
| 88 | + # Codes 2 and 3 fail the job by design: in CI they mean the gate did not actually |
| 89 | + # run, and a gate that silently passes when it could not run is worse than no gate. |
| 90 | + # Add `|| [ $? -eq 3 ]` if you would rather treat "declined" as a pass while rolling |
| 91 | + # this out — a stale baseline does NOT produce 3, it warns and still grades, so 3 |
| 92 | + # really does mean the comparison was unsound. |
64 | 93 |
|
65 | 94 | - name: Publish the verdict as JSON |
66 | | - if: always() |
67 | | - run: enola check --json > architecture-verdict.json || true |
| 95 | + if: always() && steps.baseline.outcome == 'success' |
| 96 | + run: enola check --baseline baseline --json > architecture-verdict.json || true |
68 | 97 |
|
69 | 98 | - uses: actions/upload-artifact@v4 |
70 | 99 | if: always() |
71 | 100 | with: |
72 | 101 | name: architecture-verdict |
73 | 102 | path: architecture-verdict.json |
| 103 | + if-no-files-found: ignore |
0 commit comments