ci: enable squash auto-merge on ready PRs (PLAT-108) (#115)
Some checks failed
Deploy / deploy-management (push) Has been cancelled
Deploy / deploy-external-dev (push) Has been cancelled
Deploy / deploy-security (push) Has been cancelled
Deploy / deploy-dev (push) Has been cancelled
Deploy / deploy-prod (push) Has been cancelled

* ci: enable squash auto-merge on ready PRs

* fix(ci): grant contents read so auto-merge can query the PR

* fix(ci): restore contents write for enablePullRequestAutoMerge

* fix(ci): serialize auto-merge enable and ignore already-enabled

* fix(ci): request squash auto-merge so PRs enter the merge queue
This commit is contained in:
Adam Moussa 2026-08-21 23:32:53 +00:00 • committed by GitHub
parent e8f241712a
commit de0e7456e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

46
.github/workflows/auto-merge.yaml vendored Normal file
View file

@ -0,0 +1,46 @@
name: Enable auto-merge
on:
pull_request:
types: [opened, ready_for_review, reopened, synchronize]
branches: [main]
concurrency:
group: enable-auto-merge-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
enable:
if: >-
github.event.pull_request.draft == false
&& github.event.pull_request.head.repo.full_name == github.repository
&& github.event.pull_request.user.login != 'dependabot[bot]'
&& github.event.pull_request.user.login != 'renovate[bot]'
runs-on: ubuntu-latest
steps:
- name: Enable squash auto-merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
method="$(gh pr view "$PR" --repo "$REPO" --json autoMergeRequest --jq '.autoMergeRequest.mergeMethod // empty')"
# Merge queue requires squash. `gh pr merge --auto` with no method
# records MERGE and never enqueues.
if [ "$method" = "MERGE" ] || [ "$method" = "REBASE" ]; then
gh pr merge "$PR" --repo "$REPO" --disable-auto
fi
if ! out=$(gh pr merge "$PR" --repo "$REPO" --squash --auto 2>&1); then
echo "$out"
if [ "$(gh pr view "$PR" --repo "$REPO" --json autoMergeRequest --jq '.autoMergeRequest.mergeMethod // empty')" = "SQUASH" ]; then
echo "squash auto-merge already enabled"
exit 0
fi
exit 1
fi
printf '%s\n' "$out"