Skip to content

Commit cfce8c8

Browse files
committed
Added index.js
1 parent 70d49d9 commit cfce8c8

File tree

3 files changed

+324
-0
lines changed

3 files changed

+324
-0
lines changed

package-lock.json

Lines changed: 256 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "delete-github-actions-artifacts",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"description": "Clean up all GitHub Actions artifacts using the GitHub API",
6+
"main": "src/index.js",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/Zeryther/delete-github-actions-artifacts.git"
10+
},
11+
"author": "Mehdi Baaboura <[email protected]>",
12+
"license": "MIT",
13+
"bugs": {
14+
"url": "https://github.com/Zeryther/delete-github-actions-artifacts/issues"
15+
},
16+
"homepage": "https://github.com/Zeryther/delete-github-actions-artifacts#readme",
17+
"dependencies": {
18+
"cli-progress": "^3.11.1",
19+
"node-fetch": "^3.2.4",
20+
"readline-sync": "^1.4.10"
21+
}
22+
}

src/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import fetch from 'node-fetch';
2+
import readline from 'readline-sync';
3+
import progress from 'cli-progress';
4+
5+
const token = await readline.question('GitHub API Token: ');
6+
const repository = await readline.question('Repository (ex. organization/name): ');
7+
8+
const headers = {
9+
'Authorization': 'Token ' + token,
10+
'Accept': 'application/vnd.github.v3+json',
11+
'User-Agent': 'https://github.com/Zeryther/delete-github-actions-artifacts'
12+
};
13+
14+
let artifacts = [];
15+
const pageSize = 100;
16+
let pageIndex = 1;
17+
let page = undefined;
18+
19+
while (!page || page.length >= pageSize) {
20+
page = (await (await fetch(`https://api.github.com/repos/${repository}/actions/artifacts?per_page=${pageSize}&page=${pageIndex}`, {
21+
headers
22+
})).json()).artifacts;
23+
24+
pageIndex++;
25+
26+
artifacts = artifacts.concat(page);
27+
}
28+
29+
console.log(`Found ${artifacts.length} artifacts`);
30+
31+
const bar = new progress.SingleBar({}, progress.Presets.shades_classic);
32+
33+
bar.start(artifacts.length, 0);
34+
35+
artifacts.forEach(async artifact => {
36+
await fetch(`https://api.github.com/repos/${repository}/actions/artifacts/${artifact.id}`, {
37+
method: 'delete',
38+
headers
39+
});
40+
41+
bar.increment();
42+
});
43+
44+
bar.stop();
45+
46+
console.log('Done');

0 commit comments

Comments
 (0)