mirror of
https://github.com/Sea-Haven-Industries/seahaven-org-baseline.git
synced 2026-09-30 08:03:19 +00:00
Some checks failed
* 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
46 lines
1.6 KiB
YAML
46 lines
1.6 KiB
YAML
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"
|