Skip dynamic workflows in purge-old-workflow-runs.js (#40521)
This commit is contained in:
@@ -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}`)
|
||||
|
||||
Reference in New Issue
Block a user