Files
pezkuwi-wallet-utils/.github/workflows/auto-merge.yml
T
pezkuwichain 1b49b149d0 fix: auto-merge only waited on Code Quality, never retried after Security
auto-merge.yml only listened for the "Code Quality" workflow_run event.
Whenever "Security" (CodeQL etc., usually the slower of the two) finished
after Code Quality, the merge attempt fired too early, failed against the
still-pending required check, and nothing ever re-triggered it - the PR sat
open until someone noticed and merged it by hand. This is the actual cause
behind the recurring "master->main sync PR stuck" issue, not a one-off fluke.

Now listens for both workflows, and verifies every required check is
actually green (via `gh pr checks --required`) before merging rather than
trusting that the one workflow which fired us means everything is done -
whichever of the two finishes last will now successfully trigger the merge.
2026-07-11 08:12:47 -07:00

63 lines
2.4 KiB
YAML

name: Auto Merge
on:
workflow_run:
# Both required workflows must be listed - this used to list only "Code Quality", so whenever "Security"
# (which includes CodeQL, usually the slower one) finished AFTER Code Quality, nothing ever re-triggered
# the merge attempt and the PR sat open until someone noticed and merged it manually. Listing both means
# whichever finishes LAST fires this workflow, and the check-verification step below (not just "trust the
# one workflow that happened to trigger us") confirms every required check is actually green before merging.
workflows: ["Code Quality", "Security"]
types: [completed]
jobs:
auto-merge:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request'
permissions:
contents: write
pull-requests: write
steps:
- name: Find and merge master → main PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}"
echo "Workflow ran on branch: $HEAD_BRANCH"
# Only merge PRs from master to main
if [ "$HEAD_BRANCH" != "master" ]; then
echo "Not a master branch PR, skipping"
exit 0
fi
PR_NUMBER=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head master \
--state open \
--json number \
--jq '.[0].number')
if [ -z "$PR_NUMBER" ]; then
echo "No open PR from master to main found, skipping"
exit 0
fi
# Don't trust that the workflow which triggered us means every required check is done - the other
# workflow (Code Quality vs Security) might still be running. Verify every required check is
# actually green before attempting to merge; if not, exit quietly and let whichever check finishes
# last re-trigger this workflow.
if ! gh pr checks "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --required --watch=false; then
echo "Not all required checks are green yet for PR #$PR_NUMBER - skipping, will retry when the remaining workflow completes"
exit 0
fi
echo "Merging PR #$PR_NUMBER"
gh pr merge "$PR_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--merge \
--delete-branch=false