Skip to content

Commit efe8a14

Browse files
authored
fix(ci): give push builds a base their audits can actually read (#7033)
Push builds fail the migration audit: ✗ Migration safety check could not run. Cannot diff against 'HEAD~1'. `actions/checkout` sets no `fetch-depth`, so it defaults to 1 — a single-commit clone in which `HEAD~1` does not resolve. Both diff-based audits named `HEAD~1` as their push base, so neither has ever had a base to read. The migration audit answered that with `✓ No new migrations to check` and exit 0, so it had never run on a push build at all; #7022 made it say it could not run instead, which is what surfaced this. The block-registry check reports `⚠ … skipping` on the same input — visible, and equally never run. `HEAD~1` was the wrong base regardless. It names the last commit, so a push carrying several commits audits the tip and lets every earlier commit through: 3-commit push, HEAD~1 base: mig3.sql 3-commit push, before base: mig1.sql mig2.sql mig3.sql The base is now `github.event.before` — the tip the branch had before the push, which is what GitHub provides for exactly this. It is fetched by SHA at depth 1; the audits diff two tips and need no common ancestry between them. Resolved once in a step both audits read, so the two cannot drift apart. `HEAD~1` survives only as the fallback for an all-zero `before` (a new branch, with no predecessor to diff), which is what `fetch-depth: 2` now covers. Verified: both audits accept a raw SHA base and pass; the multi-commit case above is a real reproduction, not a description.
1 parent 528b34f commit efe8a14

1 file changed

Lines changed: 33 additions & 15 deletions

File tree

.github/workflows/test-build.yml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ jobs:
1414
timeout-minutes: 15
1515

1616
steps:
17+
# The diff-based audits below need a base commit to read, and the default
18+
# depth of 1 clones a single commit with no parent. They normally fetch
19+
# their base by SHA (see "Resolve base ref"), so this depth only covers the
20+
# `HEAD~1` fallback — but without it that fallback resolves to nothing.
21+
#
22+
# Worth stating because the failure was invisible for so long: the migration
23+
# audit read the resulting `git diff` failure as "no migrations changed" and
24+
# exited 0, so it had never actually run on a push build.
1725
- name: Checkout code
1826
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
27+
with:
28+
fetch-depth: 2
1929

2030
- name: Setup Bun
2131
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
@@ -112,18 +122,32 @@ jobs:
112122
#
113123
# Depth stays at 1 — without a merge-base the migration audit diffs the two
114124
# tips, which under `--diff-filter=AM` is exactly the migrations new here.
115-
- name: Fetch base ref for diff-based audits
116-
if: github.event_name == 'pull_request'
117-
run: git fetch --depth=1 origin "${{ github.base_ref }}"
118-
119-
- name: Check block registry invariants
125+
# Resolved once for both diff-based audits, and never with `|| true`: a
126+
# swallowed fetch leaves the base absent, which neither audit can tell apart
127+
# from a branch that changed nothing.
128+
#
129+
# On push the base is `github.event.before`, the tip the branch had before
130+
# this push — not `HEAD~1`, which names only the last commit and would let a
131+
# multi-commit push slip every earlier commit's migrations past the audit.
132+
# It is fetched by SHA at depth 1; the audits diff two tips and need no
133+
# common ancestry. An all-zero `before` means the branch is new and has no
134+
# predecessor to diff, so `HEAD~1` remains the fallback there.
135+
- name: Resolve base ref for diff-based audits
136+
id: audit_base
120137
run: |
121138
if [ "${{ github.event_name }}" = "pull_request" ]; then
122-
BASE_REF="origin/${{ github.base_ref }}"
139+
git fetch --depth=1 origin "${{ github.base_ref }}"
140+
echo "ref=origin/${{ github.base_ref }}" >> "$GITHUB_OUTPUT"
141+
elif [ -n "${{ github.event.before }}" ] &&
142+
[ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
143+
git fetch --depth=1 origin "${{ github.event.before }}"
144+
echo "ref=${{ github.event.before }}" >> "$GITHUB_OUTPUT"
123145
else
124-
BASE_REF="HEAD~1"
146+
echo "ref=HEAD~1" >> "$GITHUB_OUTPUT"
125147
fi
126-
bun run apps/sim/scripts/check-block-registry.ts "$BASE_REF"
148+
149+
- name: Check block registry invariants
150+
run: bun run apps/sim/scripts/check-block-registry.ts "${{ steps.audit_base.outputs.ref }}"
127151

128152
- name: Lint code
129153
run: bun run lint:check
@@ -138,13 +162,7 @@ jobs:
138162
run: bun run docs-manifest:check
139163

140164
- name: Migration safety (zero-downtime) audit
141-
run: |
142-
if [ "${{ github.event_name }}" = "pull_request" ]; then
143-
BASE_REF="origin/${{ github.base_ref }}"
144-
else
145-
BASE_REF="HEAD~1"
146-
fi
147-
bun run check:migrations "$BASE_REF"
165+
run: bun run check:migrations "${{ steps.audit_base.outputs.ref }}"
148166

149167
# Every workspace, not just realtime. packages/emcn, packages/utils,
150168
# apps/desktop and apps/docs had no type check in CI at all; apps/sim's

0 commit comments

Comments
 (0)