diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e13c14..a5da9e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,4 +133,18 @@ jobs: GH_TOKEN: ${{ steps.app.outputs.token }} PR: ${{ github.event.pull_request.number }} HEAD: ${{ github.event.pull_request.head.sha }} - run: gh pr merge "$PR" -R "$GITHUB_REPOSITORY" --squash --delete-branch --match-head-commit "$HEAD" + run: | + # A merge right after another can meet "base branch policy prohibits the merge" + # while GitHub catches up: try again up to 3 times, 20 seconds apart. Any + # other refusal (the head moved, a check failed) fails at once. + for try in 1 2 3 4; do + if out="$(gh pr merge "$PR" -R "$GITHUB_REPOSITORY" --squash --delete-branch --match-head-commit "$HEAD" 2>&1)"; then + echo "$out"; exit 0 + fi + echo "$out" >&2 + grep -qi "base branch policy prohibits the merge" <<< "$out" || exit 1 + [ "$try" -lt 4 ] || break + echo "The base branch policy refused the merge (try $try of 4); trying again in 20 seconds." + sleep 20 + done + exit 1