Skip to content

Commit 3a5fa1b

Browse files
PicazsooCopilot
andcommitted
fix: run all samples when base SHA is unreachable after force-push
When github.event.before points to a commit rewritten by a force-push, git diff fails and the HEAD~1 fallback only examines the latest commit, silently skipping sample builds for changes in earlier commits. Add a git cat-file reachability check: if BASE_SHA is unreachable, set RUN_ALL=true and include all samples in the matrix output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 67ae687 commit 3a5fa1b

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

.github/actions/compute-matrix/action.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,25 @@ runs:
3838
HEAD_SHA: ${{ github.sha }}
3939
ALL_SAMPLES: ${{ inputs.all_samples }}
4040
run: |
41+
RUN_ALL=false
42+
4143
# Resolve the base SHA — github.event.before is all zeros for brand-new branches
4244
if [[ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]] || [[ -z "$BASE_SHA" ]]; then
4345
BASE_SHA=$(git rev-parse HEAD~1 2>/dev/null || echo "")
46+
elif ! git cat-file -e "$BASE_SHA^{commit}" 2>/dev/null; then
47+
# BASE_SHA is set but unreachable locally — happens after a force-push that rewrites
48+
# history. git diff would fail and fall back to HEAD~1, which only sees the latest
49+
# commit and can miss changes in earlier commits. Run all samples to be safe.
50+
RUN_ALL=true
4451
fi
4552
4653
# Get list of changed files relative to the base commit
47-
if [[ -n "$BASE_SHA" ]]; then
48-
CHANGED=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" 2>/dev/null || git diff --name-only HEAD~1 HEAD)
49-
else
50-
CHANGED=$(git diff --name-only HEAD~1 HEAD)
54+
if [[ "$RUN_ALL" == "false" ]]; then
55+
if [[ -n "$BASE_SHA" ]]; then
56+
CHANGED=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" 2>/dev/null || git diff --name-only HEAD~1 HEAD)
57+
else
58+
CHANGED=$(git diff --name-only HEAD~1 HEAD)
59+
fi
5160
fi
5261
5362
# Filter: keep only sample dirs where at least one changed file lives inside them
@@ -62,7 +71,7 @@ runs:
6271
sample="${sample%/}"
6372
6473
# A file belongs to a sample dir if its path starts with "<sample>/"
65-
if echo "$CHANGED" | grep -q "^${sample}/"; then
74+
if [[ "$RUN_ALL" == "true" ]] || echo "$CHANGED" | grep -q "^${sample}/"; then
6675
RESULT+=("$sample")
6776
fi
6877
done <<< "$ALL_SAMPLES"

0 commit comments

Comments
 (0)