From b4344094b03f11b8cfe0eba58e615b28b133b265 Mon Sep 17 00:00:00 2001 From: Zbigniew Sobiecki Date: Mon, 22 Jun 2026 17:04:16 +0200 Subject: [PATCH] fix(ci): retry and verify auto-merge enablement in release workflow The Enable auto-merge step ran gh pr merge --auto immediately after creating the dev-to-main PR, but GitHub rejects enablePullRequestAutoMerge with "Pull request is in unstable status" for a few seconds after PR creation (and the command can even exit 0 without enabling while the merge state is UNKNOWN). The step failed every release even though the PR was created fine, forcing a manual merge. Retry up to 12 times with a 6s delay and verify autoMergeRequest actually stuck after each attempt instead of trusting the exit code. Fails loudly only after the retries are exhausted. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/release.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4fe73611..5e8a165f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -107,8 +107,27 @@ jobs: - name: Enable auto-merge if: ${{ !inputs.dry_run }} run: | - gh pr merge "$PR_NUMBER" --auto --merge - echo "Auto-merge enabled on PR #$PR_NUMBER. It will merge once required checks pass." + # GitHub rejects enablePullRequestAutoMerge with "Pull request is in + # unstable status" for a few seconds after a PR is created (its checks / + # merge-state aren't registered yet) — and `gh pr merge --auto` can even + # exit 0 without enabling while the state is UNKNOWN. So retry AND verify + # that auto-merge actually stuck, rather than trusting the exit code. + MAX_ATTEMPTS=12 + RETRY_DELAY_SECONDS=6 + attempt=1 + while [ "$attempt" -le "$MAX_ATTEMPTS" ]; do + gh pr merge "$PR_NUMBER" --auto --merge || true + enabled=$(gh pr view "$PR_NUMBER" --json autoMergeRequest --jq '.autoMergeRequest != null') + if [ "$enabled" = "true" ]; then + echo "Auto-merge enabled on PR #$PR_NUMBER. It will merge once required checks pass." + exit 0 + fi + echo "Auto-merge not registered yet (attempt $attempt/$MAX_ATTEMPTS) — retrying in ${RETRY_DELAY_SECONDS}s..." + sleep "$RETRY_DELAY_SECONDS" + attempt=$((attempt + 1)) + done + echo "::error::Failed to enable auto-merge on PR #$PR_NUMBER after $MAX_ATTEMPTS attempts." + exit 1 env: GH_TOKEN: ${{ secrets.GHCR_PAT }}