-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (45 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const core = require("@actions/core");
const sjson = require("secure-json-parse");
const { Octokit } = require("@octokit/action");
const octokit = new Octokit();
const [owner, repo] = core.getInput("repository").split("/");
console.log(`owner: ${owner}`);
console.log(`repository: ${repo}`);
const artifacts_string = core.getInput("artifacts");
console.log(`artifact string: ${artifacts_string}`);
async function run() {
try {
const artifacts = sjson.parse(core.getInput("artifacts"), {
protoAction: "remove",
constructorAction: "remove",
});
console.log(`artifacts: ${JSON.stringify(artifacts)}`);
if (!Array.isArray(artifacts)) {
core.setFailed(`artifact contains empty or invalid value: ${artifacts} `);
return;
}
if (artifacts.length == 0) {
console.log("There are no artifacts to remove!");
}
for (const artifact of artifacts) {
try {
console.log(`current artifact: ${JSON.stringify(artifact)}`);
// See https://docs.github.com/en/rest/reference/actions#delete-an-artifact
await octokit.request(
"DELETE /repos/{owner}/{repo}/actions/artifacts/{artifact_id}",
{
owner: owner,
repo: repo,
artifact_id: artifact.id,
}
);
console.log(`succesfuly removed artifact id: ${artifact.id}`);
} catch (e) {
console.log(e);
}
}
} catch (error) {
core.setFailed(error);
}
}
run();