Skip to content

Commit 8eccbd9

Browse files
williamwclaude
andcommitted
Fix git diff to use reliable commit references
The previous approach used GitHub event SHAs that may not be available in the repository. Updated to use: - origin/main..HEAD for PRs (more reliable) - Fallback to HEAD~1 for pushes when event.before is not available - Added git cat-file check to verify commit existence before using it This should fix the "Could not access" git errors and properly detect changed directories for test execution. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7431db7 commit 8eccbd9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ jobs:
5454
id: changed-dirs
5555
run: |
5656
if [ "${{ github.event_name }}" = "pull_request" ]; then
57-
CHANGED_DIRS=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -v '^\.github/' | cut -d'/' -f1 | sort -u | tr '\n' ' ')
57+
# For PR, use origin/main as base
58+
CHANGED_DIRS=$(git diff --name-only origin/main..HEAD | grep -v '^\.github/' | cut -d'/' -f1 | sort -u | tr '\n' ' ')
5859
else
59-
CHANGED_DIRS=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -v '^\.github/' | cut -d'/' -f1 | sort -u | tr '\n' ' ')
60+
# For push, use the before commit if available, otherwise use HEAD~1
61+
if [ -n "${{ github.event.before }}" ] && git cat-file -e "${{ github.event.before }}" 2>/dev/null; then
62+
CHANGED_DIRS=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -v '^\.github/' | cut -d'/' -f1 | sort -u | tr '\n' ' ')
63+
else
64+
CHANGED_DIRS=$(git diff --name-only HEAD~1..HEAD | grep -v '^\.github/' | cut -d'/' -f1 | sort -u | tr '\n' ' ')
65+
fi
6066
fi
6167
echo "Changed directories: $CHANGED_DIRS"
6268
echo "dirs=$CHANGED_DIRS" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)