From 7c827d1a4d8e24ba1c5b3a98aa2ecaf7a246583d Mon Sep 17 00:00:00 2001 From: David Ratunuman Date: Wed, 12 Jun 2024 11:50:43 -0700 Subject: [PATCH 1/2] Preview link: Better handeling for secondary rate limit with added retry --- .github/workflows/preview.yaml | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index aeac06cb..a29da179 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -30,18 +30,29 @@ jobs: uses: actions/github-script@v7 with: script: | - const response = await github.rest.search.issuesAndPullRequests({ - q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', - per_page: 1, - }) - const items = response.data.items - if (items.length < 1) { - console.error('No PRs found') - return + async function findPR() { + for (let retries = 3; retries > 0; retries--) { + try { + const response = await github.rest.search.issuesAndPullRequests({ + q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', + per_page: 1, + }); + const items = response.data.items; + if (items.length < 1) { + throw new Error('No PRs found'); + } + const pullRequestNumber = items[0].number + console.info("Pull request number is", pullRequestNumber); + return pullRequestNumber + } catch (error) { + console.error(`Retrying... (${3 - retries + 1}/3)`); + if (retries === 1) throw error; + await new Promise(res => setTimeout(res, 10000)); + } + } } - const pullRequestNumber = items[0].number - console.info("Pull request number is", pullRequestNumber) - return pullRequestNumber + return findPR(); + github-token: ${{ secrets.GITHUB_TOKEN }} # deploy - name: Deploy to Cloudflare Pages From 82981976293118494e64692300d36cfc04ab844d Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Fri, 14 Jun 2024 12:19:27 +0100 Subject: [PATCH 2/2] revert, set retries on action --- .github/workflows/preview.yaml | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index a29da179..ac90ffc2 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -29,30 +29,20 @@ jobs: id: pr uses: actions/github-script@v7 with: + retries: 3 script: | - async function findPR() { - for (let retries = 3; retries > 0; retries--) { - try { - const response = await github.rest.search.issuesAndPullRequests({ - q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', - per_page: 1, - }); - const items = response.data.items; - if (items.length < 1) { - throw new Error('No PRs found'); - } - const pullRequestNumber = items[0].number - console.info("Pull request number is", pullRequestNumber); - return pullRequestNumber - } catch (error) { - console.error(`Retrying... (${3 - retries + 1}/3)`); - if (retries === 1) throw error; - await new Promise(res => setTimeout(res, 10000)); - } - } + const response = await github.rest.search.issuesAndPullRequests({ + q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', + per_page: 1, + }) + const items = response.data.items + if (items.length < 1) { + console.error('No PRs found') + return } - return findPR(); - github-token: ${{ secrets.GITHUB_TOKEN }} + const pullRequestNumber = items[0].number + console.info('Pull request number is', pullRequestNumber) + return pullRequestNumber # deploy - name: Deploy to Cloudflare Pages