fix prune preview deployment script (#2698)

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]
This commit is contained in:
alex 2024-01-31 16:37:51 +00:00 committed by GitHub
parent 45c8777ea0
commit 9ca5d5f22d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 7 deletions

View file

@ -16,7 +16,7 @@ jobs:
deploy: deploy:
name: Prune preview deploys name: Prune preview deploys
timeout-minutes: 15 timeout-minutes: 15
runs-on: ubuntu-latest-16-cores runs-on: ubuntu-latest-16-cores-open
environment: deploy-staging environment: deploy-staging
steps: steps:

View file

@ -16,11 +16,21 @@ async function isPrClosedForAWhile(prNumber: number) {
if (_isPrClosedCache.has(prNumber)) { if (_isPrClosedCache.has(prNumber)) {
return _isPrClosedCache.get(prNumber)! return _isPrClosedCache.get(prNumber)!
} }
const prResult = await github.getOctokit(env.GH_TOKEN).rest.pulls.get({
owner: 'tldraw', let prResult
repo: 'tldraw', try {
pull_number: prNumber, 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 twoDays = 1000 * 60 * 60 * 24 * 2
const result = const result =
prResult.data.state === 'closed' && prResult.data.state === 'closed' &&
@ -62,7 +72,7 @@ async function deletePreviewWorkerDeployment(id: string) {
) )
if (!res.ok) { 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(`Skipping ${deployment} because PR is still open`)
} }
} }
nicelog('Done')
} }
main() main()