forked from GeekyEggo/delete-artifact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
41 lines (33 loc) · 1.05 KB
/
index.ts
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
import * as core from "@actions/core";
import RuntimeHttpClient from "./runtime-http-client";
import { fail } from "./utils";
import { getDefaultFilter } from "./artifact-filter";
/**
* The main run function.
*/
async function run(): Promise<void> {
const client = new RuntimeHttpClient();
// get the artifacts
const artifacts = await client.listArtifacts();
if (!artifacts.success) {
fail("Failed to load artifacts.");
return;
}
let failureCount = 0;
const filter = getDefaultFilter();
// iterate over the matching artifacts
for (const artifact of filter(artifacts.data.value)) {
const del = await client.deleteArtifact(artifact.url);
if (del.success) {
core.info(`Successfully deleted artifact: "${artifact.name}"`);
} else {
core.error(`Failed to delete artifact: "${artifact.name}"`);
failureCount++;
}
}
// determine the overall success
if (failureCount > 0) {
fail("1 or more artifacts failed to delete.");
}
}
run();