From e70c69bca8297e0a4f83fe8653a4e537c7075463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Thu, 13 Feb 2025 06:18:08 +0300 Subject: [PATCH] Update auto-merge.yml --- .github/workflows/auto-merge.yml | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index d65c6eb..e4edbe5 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -54,6 +54,46 @@ jobs: core.setOutput("shouldMerge", "true"); result-encoding: string + - name: Wait for checks to pass + if: steps.check.outputs.shouldMerge == 'true' + uses: actions/github-script@v6 + with: + script: | + const prNumber = context.payload.pull_request.number; + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + + // Wait for status checks to pass. + let checksPending = true; + let retries = 0; + const maxRetries = 20; + const waitTime = 30000; + + while (checksPending && retries < maxRetries) { + const { data: combinedStatus } = await github.rest.repos.getCombinedStatusForRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: pr.head.sha + }); + + if (combinedStatus.state === 'success') { + checksPending = false; + } else { + core.info(`Checks still pending. Waiting... (${retries + 1}/${maxRetries})`); + await new Promise(resolve => setTimeout(resolve, waitTime)); + retries++; + } + } + + if (checksPending) { + throw new Error("Checks did not complete successfully within the time limit."); + } + + core.info("All checks passed."); + - name: Auto-Merge PR if: steps.check.outputs.shouldMerge == 'true' uses: actions/github-script@v6