ci: remove automerge label workflow in favor of GitHub native auto-merge (#544)
## Summary Removes the custom `automerge.yml` workflow and its `automerge` label flow. GitHub now provides native auto-merge that merges a PR automatically once required CI checks pass, making the custom workflow redundant. ## Changes - Delete `.github/workflows/automerge.yml` ## Follow-up (manual, outside this PR) - Enable **Settings → General → Allow auto-merge**. - Add a branch protection rule requiring the CI check so native auto-merge waits for it. - Remove the now-unused `MERGE_TOKEN` secret if nothing else uses it. - Use **Enable auto-merge** per PR (or `gh pr merge --auto --squash`).
This commit is contained in:
parent
da0c8c58fc
commit
3d0fd9cc70
|
|
@ -1,57 +0,0 @@
|
|||
name: automerge
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ['CI']
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
if: >
|
||||
github.event.workflow_run.conclusion == 'success' &&
|
||||
github.event.workflow_run.event == 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Merge PR with automerge label
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.MERGE_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
run: |
|
||||
HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}"
|
||||
|
||||
PR_NUMBER=$(gh pr list --repo "$REPO" --head "$HEAD_BRANCH" --state open --json number --jq '.[0].number')
|
||||
|
||||
if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" = "null" ]; then
|
||||
echo "No open PR found for branch $HEAD_BRANCH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
HAS_LABEL=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels --jq '[.labels[].name] | map(select(. == "automerge")) | length')
|
||||
|
||||
if [ "$HAS_LABEL" -eq 0 ]; then
|
||||
echo "PR #$PR_NUMBER does not have automerge label, skipping"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Ensure the CI run matches the PR's latest commit to avoid merging stale results
|
||||
CI_SHA="${{ github.event.workflow_run.head_sha }}"
|
||||
PR_SHA=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json headRefOid --jq '.headRefOid')
|
||||
|
||||
if [ "$CI_SHA" != "$PR_SHA" ]; then
|
||||
echo "CI ran on $CI_SHA but PR head is $PR_SHA, skipping"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Ensure no checks have failed on the PR
|
||||
FAILED=$(gh pr checks "$PR_NUMBER" --repo "$REPO" --json state --jq '[.[] | select(.state == "FAILURE")] | length')
|
||||
|
||||
if [ "$FAILED" -gt 0 ]; then
|
||||
echo "PR #$PR_NUMBER has $FAILED failed check(s), skipping merge"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "PR #$PR_NUMBER has automerge label and all checks passed. Merging..."
|
||||
gh pr merge "$PR_NUMBER" --squash --repo "$REPO" --delete-branch
|
||||
Loading…
Reference in New Issue