Skip to content

Commit

Permalink
ci: added check for fixup commits
Browse files Browse the repository at this point in the history
  • Loading branch information
frazarshad committed Aug 9, 2024
1 parent b290b1b commit 2dfc192
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
33 changes: 31 additions & 2 deletions .github/workflows/mergify-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,43 @@ jobs:
fixup_commits=
for commit in $(git rev-list $BASE_SHA..$HEAD_SHA); do
case $(git show --pretty=format:%s -s $commit) in fixup\!*|squash\!*)
case $(git show --pretty=format:%s -s $commit) in fixup\!*|squash\!*|amend\!*)
fixup_commits="$fixup_commits\n$commit"
;;
esac
done
if [ -n "$fixup_commits" ]; then
echo "Error: fixup/squash commits found in $BASE_LABEL..$HEAD_LABEL"
echo "Error: fixup/squash/amend commits found in $BASE_LABEL..$HEAD_LABEL"
echo -e "$fixup_commits"
exit 1
fi
no-fixup-commits:
runs-on: ubuntu-latest
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.draft == false &&
github.event.pull_request.base.ref == 'master' &&
contains(github.event.pull_request.labels.*.name, 'automerge:rebase') &&
!contains(github.event.pull_request.labels.*.name, 'bypass:linear-history')
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for fixup commits
id: fixup-commits
run: |
if [[ $(git rev-list "$BASE_SHA".."$HEAD_SHA" --grep="^\(fixup\|amend\|squash\)! " | wc -l) -eq 0 ]]; then
echo "No fixup/amend/squash commits found in commit history"
else
echo "fixup/amend/squash commits found in commit history"
exit 1
fi
12 changes: 12 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ queue_rules:
- label=proto:expect-breakage
merge_conditions:
- base=master
# Rebase PRs with fixup commits are allowed to enter the merge queue but
# should not be allowed to merge if there are leftover fixup commits after rebase
- or:
- label=bypass:linear-history
- check-success=no-fixup-commits
- check-skipped=no-fixup-commits
# Require integration tests before merging only
- or:
- label=bypass:integration
Expand All @@ -45,6 +51,12 @@ queue_rules:
- label=proto:expect-breakage
merge_conditions:
- base=master
# Rebase PRs with fixup commits are allowed to enter the merge queue but
# should not be allowed to merge if there are leftover fixup commits after rebase
- or:
- label=bypass:linear-history
- check-success=no-fixup-commits
- check-skipped=no-fixup-commits
# Require integration tests before merging only
- or:
- label=bypass:integration
Expand Down

0 comments on commit 2dfc192

Please sign in to comment.