Skip to content

Commit 3e1b813

Browse files
committed
fix(infra): correct first commit check in pre-commit workflow
1 parent c66eb19 commit 3e1b813

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ jobs:
3030
# the pre-commit.yaml workflow does not immediately fail on the later
3131
# Fetch commit refs.
3232
first="0000000000000000000000000000000000000000"
33+
event_before="${{ github.event.before }}"
34+
base_ref="${{ github.base_ref }}"
35+
36+
if [[ -z "$base_ref" ]]; then
37+
first_base_ref=""
38+
else
39+
first_base_ref="$(git rev-parse origin/$base_ref)"
40+
fi
3341
3442
if [[ ${{ github.event_name }} == 'push' ]]; then
35-
if [[ ${{ github.event.before }} == $first ]]; then
43+
if [[ $event_before == $first ]]; then
3644
echo "This is the first commit in the repository. No commits to check."
3745
echo "skip_pre-commit=true" >> $GITHUB_OUTPUT
3846
else
3947
echo "skip_pre-commit=false" >> $GITHUB_OUTPUT
4048
fi
4149
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then
42-
if [[ $(git rev-parse origin/${{ github.base_ref }}) == $first ]];then
50+
if [[ $first_base_ref == $first ]];then
4351
echo "This is the first commit in the repository. No commits to check."
4452
echo "skip_pre-commit=true" >> $GITHUB_OUTPUT
4553
else

0 commit comments

Comments
 (0)