File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- name : Test Single Commit
1+ name : Check single commit
22
33on :
44 pull_request :
88 check-single-commit :
99 runs-on : ubuntu-latest
1010 steps :
11- - name : Checkout code
12- uses : actions/checkout@v4
13- with :
14- fetch-depth : 0
15-
16- - name : Count commits
17- id : commits
11+ - name : Check PR commit count
12+ id : pr
1813 run : |
19- BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
20- COMMIT_COUNT=$(git rev-list --count --no-merges origin/$BASE_BRANCH..HEAD)
14+ COMMIT_COUNT=$(gh pr view ${{ github.event.pull_request.number }} --json commits -q '.commits | length')
2115 echo "count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
2216
2317 - name : Enforce single commit
2418 run : |
25- if [ "${{ steps.commits .outputs.count }}" -gt 1 ]; then
26- echo "❌ PR has more than one commit (${{ steps.commits .outputs.count }} commits )."
19+ if [ "${{ steps.pr .outputs.count }}" -gt 1 ]; then
20+ echo "❌ PR has more than one commit (${{ steps.pr .outputs.count }})."
2721 exit 1
2822 else
29- echo "✅ PR has 1 commit."
23+ echo "✅ PR has a single commit."
3024 fi
Original file line number Diff line number Diff line change 1+ This is the second commit and should trigger the single commit check to fail.
You can’t perform that action at this time.
0 commit comments