Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions .github/workflows/git.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@ name: Git Checks

on: [ pull_request ]

permissions:
contents: read

jobs:
# Fails while the pull request has commits that git rebase --autosquash would fold: fixup!,
# squash! and amend!.
block-merge-with-autosquash-commits:
name: Block merge with autosquash commits
runs-on: ubuntu-24.04
timeout-minutes: 5

steps:
- name: Block merge with autosquash commits
uses: xt0rted/block-autosquash-commits-action@v2
- name: Clone repository
uses: actions/checkout@v6
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
persist-credentials: false

- name: Block merge with autosquash commits
shell: bash
env:
BASE: ${{ github.event.pull_request.base.sha }}
HEAD: ${{ github.event.pull_request.head.sha }}
run: |
# git log runs on its own, so its failure fails the job instead of passing as no match.
log=$(git log --format='%h %s' "$BASE..$HEAD")
commits=$(grep -E '^[0-9a-f]+ (fixup|squash|amend)! ' <<<"$log") || exit 0
echo "::error::Squash these commits before merge: git rebase -i --autosquash origin/${GITHUB_BASE_REF}"
# Subjects are untrusted: stop them from being read as workflow commands.
token=$(openssl rand -hex 16)
echo "::stop-commands::$token"
printf '%s\n' "$commits"
echo "::$token::"
exit 1
Loading