Skip to content

Commit 83cf205

Browse files
committed
build: guard against missing commit hash
1 parent 528278e commit 83cf205

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

.github/workflows/run_affected_tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,18 @@ jobs:
136136
ancestor_commit=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
137137
files=$(git diff --diff-filter=AM --name-only $ancestor_commit ${{ github.event.pull_request.head.sha }})
138138
else
139-
# Get changed files by comparing the current commit to the commit before the push event or with its parent:
139+
# Check if the commit SHA exists:
140+
if git rev-parse ${{ github.event.before }} >/dev/null 2>&1 && git rev-parse ${{ github.event.after }} >/dev/null 2>&1; then
141+
# Get changed files by comparing the current commit to the commit before the push event or with its parent:
140142
if [ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]; then
141143
files=$(git diff --diff-filter=AM --name-only HEAD~ ${{ github.event.after }})
142144
else
143145
files=$(git diff --diff-filter=AM --name-only ${{ github.event.before }} ${{ github.event.after }})
144146
fi
147+
else
148+
echo "Commit SHA not found, skipping file changes detection..."
149+
files=""
150+
fi
145151
fi
146152
directories=$(for file in $files; do dirname $file; done | uniq | tr '\n' ' ' | sed 's/ $//')
147153
echo "directories=${directories}" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)