Skip to content

Commit c6c9c8f

Browse files
committed
ci: add workflow to block autosquash commits in PRs
Adds a GitHub Actions check that fails if a PR contains fixup!, squash!, or amend! commits that haven't been rebased yet.
1 parent 9d0f8ae commit c6c9c8f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check for autosquash commits
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check-autosquash:
8+
name: Block autosquash commits
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
15+
- name: Check for autosquash commits
16+
run: |
17+
base="${{ github.event.pull_request.base.sha }}"
18+
head="${{ github.event.pull_request.head.sha }}"
19+
20+
bad_commits=$(git log --oneline "$base".."$head" | grep -iE '^\S+ (fixup|squash|amend)!' || true)
21+
22+
if [ -n "$bad_commits" ]; then
23+
echo "::error::PR contains autosquash commits that need to be rebased before merging:"
24+
echo "$bad_commits"
25+
exit 1
26+
fi
27+
28+
echo "No autosquash commits found."

0 commit comments

Comments
 (0)