front-integrations/.github/workflows/auto-merge.yaml
Adam Moussa a042994ea9
ci: enable squash auto-merge on ready PRs (PLAT-108) (#51)
* ci: enable squash auto-merge on ready PRs

* fix(ci): serialize auto-merge enable and ignore already-enabled
2026-08-21 23:34:25 +00:00

44 lines
1.4 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
if [ "$(gh pr view "$PR" --repo "$REPO" --json autoMergeRequest --jq '.autoMergeRequest != null')" = "true" ]; then
echo "auto-merge already enabled"
exit 0
fi
if ! out=$(gh pr merge "$PR" --repo "$REPO" --auto 2>&1); then
echo "$out"
if [ "$(gh pr view "$PR" --repo "$REPO" --json autoMergeRequest --jq '.autoMergeRequest != null')" = "true" ]; then
echo "auto-merge already enabled"
exit 0
fi
exit 1
fi
printf '%s\n' "$out"