File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,39 @@ permissions:
1111 contents : read
1212
1313jobs :
14+ first-commit-check :
15+ runs-on : ubuntu-latest
16+ outputs :
17+ skip_pre-commit : ${{ steps.commit-check.outputs.skip_pre-commit }}
18+ steps :
19+ - name : Checkout
20+ uses : actions/checkout@v4
21+ with :
22+ # Committed tool requires the full history to check commit messages.
23+ fetch-depth : 0
24+
25+ - name : First commit check
26+ id : commit-check
27+ run : |
28+
29+ # This step is here only to ensure that after a new repository is created,
30+ # the pre-commit.yaml workflow does not immediately fail on the later
31+ # Fetch commit refs.
32+ first="0000000000000000000000000000000000000000"
33+
34+ if [[ ${{ github.event_name }} == 'push' && ${{ github.event.before }} == $first ]]; then
35+ echo "This is the first commit in the repository. No commits to check."
36+ echo "skip_pre-commit=true" >> $GITHUB_OUTPUT
37+ elif [[ ${{ github.event_name }} == 'pull_request' && $(git rev-parse origin/${{ github.base_ref }}) == $first ]]; then
38+ echo "This is the first commit in the repository. No commits to check."
39+ echo "skip_pre-commit=true" >> $GITHUB_OUTPUT
40+ else
41+ echo "skip_pre-commit=false" >> $GITHUB_OUTPUT
42+ fi
43+
1444 pre-commit-check :
45+ needs : first-commit-check
46+ if : needs.first-commit-check.outputs.skip_pre-commit == 'false'
1547 runs-on : ubuntu-latest
1648 steps :
1749 - name : Checkout
You can’t perform that action at this time.
0 commit comments