Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: force rebase and autosquash before merging #9794

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
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
27 changes: 27 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 All @@ -65,6 +77,9 @@ pull_request_rules:
conditions:
- base=master
- label=automerge:rebase
- or:
- '#commits-behind>0'
- linear-history
actions:
queue:
merge_method: merge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is the default, but should we specify autosquash: true here too to make things more obvious?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that field is deprecated and will probably wont be supported in a few months time like the other deprecated fields

Expand All @@ -76,3 +91,15 @@ pull_request_rules:
actions:
queue:
merge_method: squash
- name: rebase and autosquash
conditions:
- base=master
- label=automerge:rebase
- '#commits-behind=0'
- or:
- -linear-history
- check-failure=no-fixup-commits
- -draft
actions:
rebase:
autosquash: true
Loading