diff --git a/.github/actions-scripts/purge-old-workflow-runs.js b/.github/actions-scripts/purge-old-workflow-runs.js index 6129335fab..382290ef7a 100755 --- a/.github/actions-scripts/purge-old-workflow-runs.js +++ b/.github/actions-scripts/purge-old-workflow-runs.js @@ -25,6 +25,7 @@ import fs from 'fs' import assert from 'node:assert/strict' import { getOctokit } from '@actions/github' +import { RequestError } from '@octokit/request-error' main() async function main() { @@ -51,10 +52,12 @@ async function main() { repo, }) + const validWorkflows = allWorkflows.filter((w) => !w.path.startsWith('dynamic/')) + const sortByDate = (a, b) => a.updated_at.localeCompare(b.updated_at) const workflows = [ - ...allWorkflows.filter((w) => !fs.existsSync(w.path)).sort(sortByDate), - ...allWorkflows.filter((w) => fs.existsSync(w.path)).sort(sortByDate), + ...validWorkflows.filter((w) => !fs.existsSync(w.path)).sort(sortByDate), + ...validWorkflows.filter((w) => fs.existsSync(w.path)).sort(sortByDate), ] let deletions = 0 @@ -65,11 +68,25 @@ async function main() { ? `${workflow.path} still exists on disk` : `${workflow.path} no longer exists on disk`, ) - deletions += await deleteWorkflowRuns(github, owner, repo, workflow, { - dryRun: DRY_RUN, - minAgeDays: MIN_AGE_DAYS, - maxDeletions: MAX_DELETIONS - deletions, - }) + try { + deletions += await deleteWorkflowRuns(github, owner, repo, workflow, { + dryRun: DRY_RUN, + minAgeDays: MIN_AGE_DAYS, + maxDeletions: MAX_DELETIONS - deletions, + }) + } catch (error) { + // Generally, if it fails, it's because of a network error or + // because busy servers. It's not our fault, but considering that + // this script is supposed to run on frequent schedule, we don't + // need to fret. We'll just try again next time. + if (error instanceof RequestError && error.status >= 500) { + console.log(`RequestError: ${error.message}`) + console.log(` status: ${error.status}`) + break + } else { + throw error + } + } if (deletions >= MAX_DELETIONS) { console.log(`Reached max number of deletions: ${MAX_DELETIONS}`) diff --git a/package-lock.json b/package-lock.json index 348713aede..7c61f84b90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "dependencies": { "@elastic/elasticsearch": "7.11.0", "@github/failbot": "0.8.3", + "@octokit/request-error": "5.0.0", "@primer/behaviors": "^1.3.3", "@primer/css": "^21.0.1", "@primer/octicons": "^19.1.0", @@ -1953,6 +1954,17 @@ "universal-user-agent": "^6.0.0" } }, + "node_modules/@octokit/core/node_modules/@octokit/request-error": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz", + "integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==", + "dev": true, + "dependencies": { + "@octokit/types": "^6.0.3", + "deprecation": "^2.0.0", + "once": "^1.4.0" + } + }, "node_modules/@octokit/endpoint": { "version": "6.0.12", "dev": true, @@ -2081,9 +2093,36 @@ } }, "node_modules/@octokit/request-error": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.0.0.tgz", + "integrity": "sha512-1ue0DH0Lif5iEqT52+Rf/hf0RmGO9NWFjrzmrkArpG9trFfDM/efx00BJHdLGuro4BR/gECxCU2Twf5OKrRFsQ==", + "dependencies": { + "@octokit/types": "^11.0.0", + "deprecation": "^2.0.0", + "once": "^1.4.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/request-error/node_modules/@octokit/openapi-types": { + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-18.0.0.tgz", + "integrity": "sha512-V8GImKs3TeQRxRtXFpG2wl19V7444NIOTDF24AWuIbmNaNYOQMWRbjcGDXV5B+0n887fgDcuMNOmlul+k+oJtw==" + }, + "node_modules/@octokit/request-error/node_modules/@octokit/types": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-11.1.0.tgz", + "integrity": "sha512-Fz0+7GyLm/bHt8fwEqgvRBWwIV1S6wRRyq+V6exRKLVWaKGsuy6H9QFYeBVDV7rK6fO3XwHgQOPxv+cLj2zpXQ==", + "dependencies": { + "@octokit/openapi-types": "^18.0.0" + } + }, + "node_modules/@octokit/request/node_modules/@octokit/request-error": { "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz", + "integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==", "dev": true, - "license": "MIT", "dependencies": { "@octokit/types": "^6.0.3", "deprecation": "^2.0.0", @@ -4878,7 +4917,6 @@ }, "node_modules/deprecation": { "version": "2.3.1", - "dev": true, "license": "ISC" }, "node_modules/dequal": { diff --git a/package.json b/package.json index fd50fbe6fa..51343774cd 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "dependencies": { "@elastic/elasticsearch": "7.11.0", "@github/failbot": "0.8.3", + "@octokit/request-error": "5.0.0", "@primer/behaviors": "^1.3.3", "@primer/css": "^21.0.1", "@primer/octicons": "^19.1.0",