Files
hapi/.github/workflows/auto-merge.yml
T
weishuandGitHub 7c715843bb ci: merge owner-approved PRs automatically after checks pass (#2217)
* ci: merge owner-approved PRs automatically after checks pass

Approval by the repo owner on a PR should be the only manual step before
merge. The auto-merge workflow squash-merges open PRs the owner approved
at their current head once every required check's latest run on that
head has passed (test, integration, windows-codex-mcp).

Fork PR review events receive no secrets, so a no-op signal workflow
runs on pull_request_review and its completion triggers the privileged
workflow, which runs default-branch code. Merges use AUTO_MERGE_TOKEN, a
user token, so the resulting pushes to main trigger push workflows; the
workflow refuses to merge if that secret is missing.

* ci: load the auto-merge script from main on every trigger

workflow_dispatch checks out the ref chosen by the caller, so a manual
run from a topic branch would execute unmerged merge logic with the
owner's token. Pin the checkout to main.
2026-10-28 13:02:05 +08:00

47 lines
1.6 KiB
YAML

name: Auto Merge
# Squash-merges open PRs that the repository owner approved at their current
# head once every check on that head has passed. Re-evaluated whenever an
# approval or a PR check workflow completes, with a periodic sweep as fallback.
on:
workflow_run:
workflows: [Auto Merge Signal, Test, android, ios, fixtures, Push Relay Image, Codex PR Review]
types: [completed]
schedule:
- cron: '7,37 * * * *'
workflow_dispatch:
concurrency:
group: auto-merge
cancel-in-progress: false
jobs:
merge:
if: |
github.event_name != 'workflow_run' ||
(github.event.workflow_run.event != 'push' && github.event.workflow_run.conclusion != 'skipped')
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
# The merge script runs with the owner's token, so always load it from
# the default branch; workflow_dispatch would otherwise check out
# whichever ref the caller selected.
- uses: actions/checkout@v4
with:
ref: main
- name: Merge approved PRs
uses: actions/github-script@v7
env:
AUTO_MERGE_TOKEN_CONFIGURED: ${{ secrets.AUTO_MERGE_TOKEN != '' }}
AUTO_MERGE_APPROVER: ${{ vars.AUTO_MERGE_APPROVER }}
AUTO_MERGE_REQUIRED_CHECKS: ${{ vars.AUTO_MERGE_REQUIRED_CHECKS }}
with:
# A user token so merges trigger push workflows on main.
github-token: ${{ secrets.AUTO_MERGE_TOKEN || github.token }}
script: |
const { autoMerge } = require('./.github/scripts/auto-merge.cjs');
await autoMerge({ github, context, core });