From 9ca5d5f22ddb3ce0c13bf88877ae1bc7eb158e4c Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 31 Jan 2024 16:37:51 +0000 Subject: [PATCH] fix prune preview deployment script (#2698) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script that prunes old preview deployments in cloudlfare was broken when we moved dotcom into the public repo. This fixes it. ### Change Type - [x] `internal` — Any other changes that don't affect the published package[^2] --- .github/workflows/prune-preview-deploys.yml | 2 +- scripts/prune-preview-deploys.ts | 24 +++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/prune-preview-deploys.yml b/.github/workflows/prune-preview-deploys.yml index 9d3b34d43..1db4b05cf 100644 --- a/.github/workflows/prune-preview-deploys.yml +++ b/.github/workflows/prune-preview-deploys.yml @@ -16,7 +16,7 @@ jobs: deploy: name: Prune preview deploys timeout-minutes: 15 - runs-on: ubuntu-latest-16-cores + runs-on: ubuntu-latest-16-cores-open environment: deploy-staging steps: diff --git a/scripts/prune-preview-deploys.ts b/scripts/prune-preview-deploys.ts index 36ec76d9c..987be5973 100644 --- a/scripts/prune-preview-deploys.ts +++ b/scripts/prune-preview-deploys.ts @@ -16,11 +16,21 @@ async function isPrClosedForAWhile(prNumber: number) { if (_isPrClosedCache.has(prNumber)) { return _isPrClosedCache.get(prNumber)! } - const prResult = await github.getOctokit(env.GH_TOKEN).rest.pulls.get({ - owner: 'tldraw', - repo: 'tldraw', - pull_number: prNumber, - }) + + let prResult + try { + prResult = await github.getOctokit(env.GH_TOKEN).rest.pulls.get({ + owner: 'tldraw', + repo: 'tldraw', + pull_number: prNumber, + }) + } catch (err: any) { + if (err.status === 404) { + _isPrClosedCache.set(prNumber, true) + return true + } + throw err + } const twoDays = 1000 * 60 * 60 * 24 * 2 const result = prResult.data.state === 'closed' && @@ -62,7 +72,7 @@ async function deletePreviewWorkerDeployment(id: string) { ) if (!res.ok) { - throw new Error('Failed to delete worker ' + JSON.stringify(res)) + throw new Error('Failed to delete worker ' + JSON.stringify(await res.json())) } } @@ -77,6 +87,8 @@ async function main() { nicelog(`Skipping ${deployment} because PR is still open`) } } + + nicelog('Done') } main()