From 50ff9ab77715e52e93acd87ef8890f743cd5af55 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 18 Aug 2026 10:42:01 +0200 Subject: [PATCH] chore: wait for the pull request to merge in the backport command (#32942) --- .github/workflows/command-backport.yml | 32 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/command-backport.yml b/.github/workflows/command-backport.yml index 138a8836a..4b3e610b2 100644 --- a/.github/workflows/command-backport.yml +++ b/.github/workflows/command-backport.yml @@ -57,11 +57,33 @@ jobs: core.setFailed(message); }; - const { data: pr } = await github.rest.pulls.get({ - owner, - repo, - pull_number: context.payload.issue.number, - }); + // the command is usually posted right before hitting merge, so give the + // pull request time to land instead of failing on the race + const deadline = Date.now() + 5 * 60 * 1000; + let pr; + for (;;) { + try { + ({ data: pr } = await github.rest.pulls.get({ + owner, + repo, + pull_number: context.payload.issue.number, + })); + // a closed pull request will never merge, no point in waiting it out + if (pr.merged || pr.state === 'closed') { + break; + } + } catch (err) { + // a blip while polling must not fail the command, but a request that + // is still failing when the time is up is a real error + if (Date.now() >= deadline) { + throw err; + } + } + if (Date.now() >= deadline) { + break; + } + await new Promise((resolve) => setTimeout(resolve, 15000)); + } if (!pr.merged) { fail(`pull request #${pr.number} is not merged`); return;