mkdir ./run && cd ./run
# copy files into directory...
npm install octokit
node ./app.js
Last active
November 26, 2024 09:16
-
-
Save guitarrapc/1c43ed8796370331cc958d54d952aab5 to your computer and use it in GitHub Desktop.
Clean up specified workflow run history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Octokit, App } from "octokit"; | |
const octokit = new Octokit({ | |
auth: '<GITHUB_PAT>' | |
}); | |
const owner = '<organization>' | |
const repo = '<repository_name>'; | |
const workflow = '<workflow_file_name_OR_id>'; | |
const dry_run = true; // set `false` when execute delete. | |
async function deleteWorkflowRuns() { | |
let page = 1; | |
let hasMorePages = true; | |
while (hasMorePages) { | |
const runs = await octokit.request(`GET /repos/${owner}/${repo}/actions/workflows/${workflow}/runs`, { | |
owner: `${owner}`, | |
repo: `${repo}`, | |
workflow_id: `${workflow}`, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
}, | |
per_page: 100, | |
page: page | |
}); | |
const tasks = [] | |
for (const run of runs.data.workflow_runs) { | |
console.log(`Deleting run for ${workflow} - ${run.id}`); | |
if (!dry_run) { | |
const task = octokit.request(`DELETE /repos/${owner}/${repo}/actions/runs/${run.id}`, { | |
owner: `${owner}`, | |
repo: `${repo}`, | |
run_id: `${run.id}`, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
} | |
}); | |
tasks.push(task); | |
} | |
} | |
await Promise.all(tasks); | |
hasMorePages = runs.data.workflow_runs.length === 100; | |
page++; | |
} | |
} | |
deleteWorkflowRuns(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "app", | |
"version": "1.0.0", | |
"main": "app.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"description": "", | |
"dependencies": { | |
"octokit": "^4.0.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment