Skip to content

Instantly share code, notes, and snippets.

@kristof-mattei
Created October 29, 2021 16:42
Show Gist options
  • Save kristof-mattei/8150bca62a032b1e85741e15f1e9fc13 to your computer and use it in GitHub Desktop.
Save kristof-mattei/8150bca62a032b1e85741e15f1e9fc13 to your computer and use it in GitHub Desktop.
Clean up all workflow runs.
const { Octokit } = require("@octokit/rest");
const { serializeError } = require("serialize-error");
const octokit = new Octokit({
auth: "PUT TOKEN HERE"
});
const baseRef = {
owner: "Kristof-Mattei",
repo: "rust-integrity-playground"
};
async function delete_workflow_run_or_err(run_id) {
try {
await octokit.rest.actions.deleteWorkflowRun({
...baseRef,
run_id: run_id
});
console.log(`Deleted ${run_id}.`);
}
catch (e) {
console.log(`Couldn't delete ${run_id}, error returned.`);
return e;
}
}
class AggregateError extends Error {
constructor(message, errors = []) {
super(message);
this.name = "ValidationError";
this.innerErrors = errors;
}
}
(async () => {
try {
let runs = [];
do {
runs = await octokit.rest.actions.listWorkflowRunsForRepo({
...baseRef,
per_page: 20,
})
let run_ids = runs.data.workflow_runs.map(e => e.id);
let errors = (await Promise.all(run_ids.map(delete_workflow_run_or_err))).filter(e => e != null);
if (null !== errors && errors.length !== 0) {
throw new AggregateError("Aggregation of errors of this delete run, check innerErrors", errors);
}
} while (runs.data.workflow_runs.length !== 0);
console.log("Done!");
} catch (e) {
console.log("Check the fan, something hit it.");
console.error(serializeError(e));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment