From 0f94afa8d44bf45847ebbb9bcface494fe6e3fa9 Mon Sep 17 00:00:00 2001 From: sebas_correa Date: Tue, 28 Jul 2026 18:11:10 -0300 Subject: [PATCH] fix: avoid self-deadlock waiting on the release PR's checks gh pr checks --watch includes this job's own check run, which never turns green until the step finishes, so the job waited on itself forever. Poll manually and exclude any check whose link points at the current run instead. --- .github/workflows/auto-merge-release.yml | 44 +++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-merge-release.yml b/.github/workflows/auto-merge-release.yml index 970da62..3043be3 100644 --- a/.github/workflows/auto-merge-release.yml +++ b/.github/workflows/auto-merge-release.yml @@ -49,11 +49,47 @@ jobs: app-id: ${{ secrets.app-id }} private-key: ${{ secrets.app-private-key }} - - name: Wait for checks and merge release PR + - name: Wait for other checks to pass env: GH_TOKEN: ${{ steps.app-token.outputs.token }} PR_NUMBER: ${{ github.event.pull_request.number }} - MERGE_METHOD: ${{ inputs.merge_method }} + RUN_ID: ${{ github.run_id }} run: | - gh pr checks "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --watch --fail-fast - gh pr merge "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --"$MERGE_METHOD" + # gh pr checks --watch would include this very job's own check run, + # which never turns green until this step finishes — a deadlock. + # So we poll and explicitly exclude any check whose link points at + # this run (identified via the /runs// segment in its URL). + done_waiting=false + for _ in $(seq 1 90); do + checks="$(gh pr checks "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json name,state,link)" + others="$(echo "$checks" | jq --arg run "/runs/$RUN_ID/" '[.[] | select(.link | contains($run) | not)]')" + + failing="$(echo "$others" | jq 'map(select(.state=="FAILURE" or .state=="ERROR" or .state=="CANCELLED" or .state=="TIMED_OUT")) | length')" + if [ "$failing" -gt 0 ]; then + echo "::error::One or more checks failed on PR #$PR_NUMBER" + echo "$others" + exit 1 + fi + + pending="$(echo "$others" | jq 'map(select(.state=="PENDING" or .state=="QUEUED" or .state=="IN_PROGRESS")) | length')" + if [ "$pending" -eq 0 ]; then + echo "All other checks passed." + done_waiting=true + break + fi + + echo "Waiting on $pending check(s)..." + sleep 15 + done + + if [ "$done_waiting" != true ]; then + echo "::error::Timed out waiting for checks on PR #$PR_NUMBER" + exit 1 + fi + + - name: Merge release PR + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + MERGE_METHOD: ${{ inputs.merge_method }} + run: gh pr merge "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --"$MERGE_METHOD"