Skip to content

Commit

Permalink
try/catch listing the workflow runs (#40546)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Heis <[email protected]>
  • Loading branch information
rsese and heiskr authored Aug 11, 2023
1 parent 671247c commit 9c285a0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions .github/actions-scripts/purge-old-workflow-runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,25 @@ async function main() {
// In practice it appears to list those that are oldest first.
// But to guarantee that it reaches the oldest, we paginate over
// all of them.
const allWorkflows = await github.paginate('GET /repos/{owner}/{repo}/actions/workflows', {
owner,
repo,
})
let allWorkflows = []

try {
allWorkflows = await github.paginate('GET /repos/{owner}/{repo}/actions/workflows', {
owner,
repo,
})
} 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}`)
} else {
throw error
}
}

const validWorkflows = allWorkflows.filter((w) => !w.path.startsWith('dynamic/'))

Expand Down

0 comments on commit 9c285a0

Please sign in to comment.