Skip to content

Commit 36da0cb

Browse files
committed
fix(ci.yml): handle force push gracefully in script validation
Previously, the validate-scripts job would fail when commit history changed (e.g. via force push) because git merge-base couldn't find a common ancestor with the replaced commits. For PRs: Now directly compares against the base branch to avoid merge-base issues entirely For push events: Added error handling with fallback comparison Fixes #153
1 parent 9e0e1e1 commit 36da0cb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,23 @@ jobs:
3333
echo "Checking for changed scripts..."
3434
3535
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
36-
BASE_SHA="${{ github.event.pull_request.base.sha }}"
36+
# For PRs, always use the base branch to avoid issues with force pushes
37+
BASE_SHA="origin/${{ github.event.pull_request.base.ref }}"
3738
else
39+
# For push events, try to find common ancestor
3840
BASE_SHA="${{ github.event.before }}"
41+
HEAD_SHA="${{ github.sha }}"
42+
43+
if ! COMMON_ANCESTOR=$(git merge-base "$BASE_SHA" "$HEAD_SHA" 2>/dev/null); then
44+
echo "Could not find common ancestor (likely due to force push)"
45+
echo "Comparing with HEAD^ instead"
46+
BASE_SHA="HEAD^"
47+
else
48+
BASE_SHA="$COMMON_ANCESTOR"
49+
fi
3950
fi
4051
4152
HEAD_SHA="${{ github.sha }}"
42-
43-
# Ensure a valid common ancestor (handles force-pushes)
44-
BASE_SHA=$(git merge-base "$BASE_SHA" "$HEAD_SHA")
45-
4653
files=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
4754
echo "Changed files: $files"
4855

0 commit comments

Comments
 (0)