Skip to content

Commit f8607a5

Browse files
committed
fix(ci): skip the diff-based audits when there is no base, instead of guessing one
Follow-up to #7033, which merged with this thread open. A push that creates a branch reports an all-zero `github.event.before`, and the fallback answered that with `HEAD~1` — auditing the single tip commit while reporting on the whole push. That is the same partial-audit-reported-as-complete failure #7033 set out to remove, one case further along. There is no correct base to substitute. Nothing precedes the push, and diffing the whole history would lint every migration ever written. So the audits skip with a `::notice::` naming the reason. A stated skip is honest; a partial audit wearing a green check is not. The same branch also covers `workflow_dispatch`, where `before` is empty rather than all-zero because there is no push payload at all. The guard has to test both — an empty `before` reaching the fetch would run `git fetch origin ""` and fail the job outright, which this workflow allows since it declares `workflow_dispatch`. Dropping the fallback drops its only consumer: `fetch-depth: 2` existed to give `HEAD~1` something to resolve to, and `before` is fetched by SHA, so the checkout returns to the default depth. Traced all four event shapes through the branch — PR, ordinary push, branch creation, manual dispatch — and verified both audits still pass against a raw SHA base.
1 parent efe8a14 commit f8607a5

1 file changed

Lines changed: 23 additions & 28 deletions

File tree

.github/workflows/test-build.yml

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,8 @@ 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.
2517
- name: Checkout code
2618
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
27-
with:
28-
fetch-depth: 2
2919

3020
- name: Setup Bun
3121
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
@@ -114,39 +104,43 @@ jobs:
114104
115105
echo "✅ All env flags are properly configured"
116106
117-
# One fetch for both base-ref audits, and no `|| true`: a swallowed fetch leaves
118-
# the base ref absent, which neither audit can tell apart from a branch that
119-
# changed nothing. The block-registry check at least degrades to a visible
120-
# `⚠ … skipping` line; the migration audit printed `✓ No new migrations to
121-
# check` and exited 0, clearing the only guard on production DDL.
122-
#
123-
# Depth stays at 1 — without a merge-base the migration audit diffs the two
124-
# tips, which under `--diff-filter=AM` is exactly the migrations new here.
125107
# Resolved once for both diff-based audits, and never with `|| true`: a
126108
# swallowed fetch leaves the base absent, which neither audit can tell apart
127-
# from a branch that changed nothing.
109+
# from a branch that changed nothing. That is how the migration audit came
110+
# to print `✓ No new migrations to check` and exit 0 on every push build,
111+
# having read nothing — and it is the only guard on production DDL.
128112
#
129113
# 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.
114+
# this push. It is fetched by SHA at depth 1, so the checkout needs no extra
115+
# history; the audits diff two tips and need no common ancestry between them.
116+
#
117+
# A push that creates the branch reports an all-zero `before` and genuinely
118+
# has no predecessor, so the audits skip with a notice rather than falling
119+
# back to a commit. Auditing one commit while reporting on the whole push is
120+
# the failure this step exists to remove.
135121
- name: Resolve base ref for diff-based audits
136122
id: audit_base
137123
run: |
138124
if [ "${{ github.event_name }}" = "pull_request" ]; then
139125
git fetch --depth=1 origin "${{ github.base_ref }}"
140126
echo "ref=origin/${{ github.base_ref }}" >> "$GITHUB_OUTPUT"
141-
elif [ -n "${{ github.event.before }}" ] &&
142-
[ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
127+
elif [ -z "${{ github.event.before }}" ] ||
128+
[ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
129+
# No predecessor to diff against. All-zero means the push created the
130+
# branch; empty means this was not a push at all — `workflow_dispatch`
131+
# carries no push payload, and dropping that guard would run
132+
# `git fetch origin ""` and fail the job. Say so and let the audits
133+
# skip: naming a commit here would audit that one commit while
134+
# reporting on the whole push.
135+
echo "::notice::No preceding commit to diff against; skipping the diff-based audits."
136+
echo "ref=" >> "$GITHUB_OUTPUT"
137+
else
143138
git fetch --depth=1 origin "${{ github.event.before }}"
144139
echo "ref=${{ github.event.before }}" >> "$GITHUB_OUTPUT"
145-
else
146-
echo "ref=HEAD~1" >> "$GITHUB_OUTPUT"
147140
fi
148141
149142
- name: Check block registry invariants
143+
if: steps.audit_base.outputs.ref != ''
150144
run: bun run apps/sim/scripts/check-block-registry.ts "${{ steps.audit_base.outputs.ref }}"
151145

152146
- name: Lint code
@@ -162,6 +156,7 @@ jobs:
162156
run: bun run docs-manifest:check
163157

164158
- name: Migration safety (zero-downtime) audit
159+
if: steps.audit_base.outputs.ref != ''
165160
run: bun run check:migrations "${{ steps.audit_base.outputs.ref }}"
166161

167162
# Every workspace, not just realtime. packages/emcn, packages/utils,

0 commit comments

Comments
 (0)