forked from jpribyl/action-docker-layer-caching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
47 lines (40 loc) · 1.27 KB
/
main.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
41
42
43
44
45
46
47
import * as core from "@actions/core";
import * as exec from "actions-exec-listener";
import { LayerCache } from "./src/LayerCache";
import { ImageDetector } from "./src/ImageDetector";
const main = async () => {
const primaryKey = core.getInput(`key`, { required: true });
const restoreKeys = core
.getInput(`restore-keys`, { required: false })
.split(`\n`)
.filter((key) => key !== ``);
const imageDetector = new ImageDetector();
const alreadyExistingImages = await imageDetector.getExistingImages();
core.saveState(
`already-existing-images`,
JSON.stringify(alreadyExistingImages)
);
const layerCache = new LayerCache([]);
layerCache.concurrency = parseInt(
core.getInput(`concurrency`, { required: true }),
10
);
const restoredKey = await layerCache.restore(primaryKey, restoreKeys);
await layerCache.cleanUp();
core.saveState(
`restored-key`,
JSON.stringify(restoredKey !== undefined ? restoredKey : "")
);
core.saveState(
`restored-images`,
JSON.stringify(
await imageDetector.getImagesShouldSave(alreadyExistingImages)
)
);
};
main().catch((e) => {
console.error(e);
core.setFailed(e);
core.saveState(`restored-key`, JSON.stringify(``));
core.saveState(`restored-images`, JSON.stringify([]));
});