@@ -3,6 +3,11 @@ name: Test and Build
33on :
44 workflow_call :
55 workflow_dispatch :
6+ inputs :
7+ comparison_base :
8+ description : ' Full commit SHA to compare against the selected branch'
9+ required : true
10+ type : string
611
712permissions :
813 contents : read
@@ -171,7 +176,7 @@ jobs:
171176 # The diff-based audits below need a base commit to read, and the default
172177 # depth of 1 clones a single commit with no parent. They normally fetch
173178 # their base by SHA (see "Resolve base ref"), so this depth only covers the
174- # `HEAD~1` fallback — but without it that fallback resolves to nothing.
179+ # new-branch push's `HEAD~1` fallback — without it that resolves to nothing.
175180 #
176181 # Worth stating because the failure was invisible for so long: the migration
177182 # audit read the resulting `git diff` failure as "no migrations changed" and
@@ -286,19 +291,33 @@ jobs:
286291 # It is fetched by SHA at depth 1; the audits diff two tips and need no
287292 # common ancestry. An all-zero `before` means the branch is new and has no
288293 # predecessor to diff, so `HEAD~1` remains the fallback there.
294+ # PRs use the event's base SHA, not a branch that can advance while queued.
295+ # Manual runs require an explicit base so earlier commits are audited too.
289296 - name : Resolve base ref for diff-based audits
290297 id : audit_base
298+ env :
299+ EVENT_NAME : ${{ github.event_name }}
300+ PR_BASE_SHA : ${{ github.event.pull_request.base.sha }}
301+ PUSH_BEFORE_SHA : ${{ github.event.before }}
302+ COMPARISON_BASE : ${{ inputs.comparison_base }}
291303 run : |
292- if [ "${{ github.event_name }} " = "pull_request" ]; then
293- git fetch --depth=1 origin "${{ github.base_ref }} "
294- echo "ref=origin/${{ github.base_ref }}" >> "$GITHUB_OUTPUT"
295- elif [ -n "${{ github.event.before }}" ] &&
296- [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
297- git fetch --depth=1 origin "${{ github.event.before }}"
298- echo "ref=${{ github.event.before }}" >> "$GITHUB_OUTPUT "
304+ if [ "$EVENT_NAME " = "pull_request" ]; then
305+ base_sha="$PR_BASE_SHA "
306+ elif [ "$EVENT_NAME" = "workflow_dispatch" ]; then
307+ base_sha="$COMPARISON_BASE"
308+ elif [ -n "$PUSH_BEFORE_SHA" ] &&
309+ [ "$PUSH_BEFORE_SHA" != "0000000000000000000000000000000000000000" ]; then
310+ base_sha="$PUSH_BEFORE_SHA "
299311 else
300- echo "ref=HEAD~1" >> "$GITHUB_OUTPUT"
312+ base_sha="$(git rev-parse --verify 'HEAD~1^{commit}')"
313+ fi
314+ if ! [[ "$base_sha" =~ ^[0-9a-fA-F]{40}$ ]]; then
315+ echo 'Comparison base must be a full commit SHA.' >&2
316+ exit 1
301317 fi
318+ git fetch --no-tags --depth=1 origin "$base_sha"
319+ resolved_base="$(git rev-parse --verify "$base_sha^{commit}")"
320+ echo "ref=$resolved_base" >> "$GITHUB_OUTPUT"
302321
303322 - name : Check block registry invariants
304323 run : bun run apps/sim/scripts/check-block-registry.ts "${{ steps.audit_base.outputs.ref }}"
0 commit comments