From b20cefa9106c03d09bb5bb35aa505bc5400ce4c6 Mon Sep 17 00:00:00 2001 From: Rachael Sewell Date: Tue, 8 Jun 2021 11:53:39 -1000 Subject: [PATCH] Fix a repo-sync failure (#19792) --- .github/workflows/repo-sync.yml | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/repo-sync.yml b/.github/workflows/repo-sync.yml index 70a378ff2e..5f1cfb12d9 100644 --- a/.github/workflows/repo-sync.yml +++ b/.github/workflows/repo-sync.yml @@ -156,11 +156,32 @@ jobs: console.log(`Pull request base sha: ${pull.data.base.sha}`) if (mainHeadSha.data.object.sha !== pull.data.base.sha || pull.data.mergeable_state === 'behind') { - const updateBranch = await github.pulls.updateBranch({ - ...context.repo, - pull_number: parseInt(${{ steps.find-pull-request.outputs.number }}) - }) - console.log(updateBranch.data.message) + try { + const updateBranch = await github.pulls.updateBranch({ + ...context.repo, + pull_number: parseInt(${{ steps.find-pull-request.outputs.number }}) + }) + console.log(updateBranch.data.message) + } catch (error) { + // When the head branch is modified an error with status 422 is thrown + // We should retry one more time to update the branch + if (error.status === 422) { + try { + const updateBranch = await github.pulls.updateBranch({ + ...context.repo, + pull_number: parseInt(${{ steps.find-pull-request.outputs.number }}) + }) + console.log(updateBranch.data.message) + } catch (error) { + // Only retry once. We'll rely on the update branch workflow to update + // this PR in the case of a second failure. + console.log(`Retried updating the branch, but an error occurred: ${error}`) + } + } else { + // A failed branch update shouldn't fail this worklow. + console.log(`An error occurred when updating the branch: ${error}`) + } + } } else { console.log(`Branch is already up-to-date`) }