forked from satackey/action-docker-layer-caching
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpost.ts
68 lines (58 loc) · 1.83 KB
/
post.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as core from "@actions/core";
import { LayerCache } from "./src/LayerCache";
import { ImageDetector } from "./src/ImageDetector";
const main = async () => {
if (JSON.parse(core.getInput("skip-save", { required: true }))) {
core.info("Skipping save.");
return;
}
const primaryKey = core.getInput("key", { required: true });
const restoredKey = JSON.parse(core.getState(`restored-key`));
const alreadyExistingImages = JSON.parse(
core.getState(`already-existing-images`)
);
const restoredImages = JSON.parse(core.getState(`restored-images`));
if (typeof restoredKey !== "string") {
throw Error(
`restoredKey is not of type string, instead it is of type ${typeof restoredKey}`
);
}
alreadyExistingImages.map((image: string) => {
if (typeof image !== "string") {
throw Error(
`alreadyExistingImage is not of type string, instead it is of type ${typeof image}`
);
}
});
restoredImages.map((image: string) => {
if (typeof image !== "string") {
throw Error(
`restoredImage is not of type string, instead it is of type ${typeof image}`
);
}
});
const imageDetector = new ImageDetector();
const existingAndRestoredImages =
alreadyExistingImages.concat(restoredImages);
const newImages = await imageDetector.getImagesShouldSave(
existingAndRestoredImages
);
if (newImages.length < 1) {
core.info(`There is no image to save.`);
return;
}
const imagesToSave = await imageDetector.getImagesShouldSave(
alreadyExistingImages
);
const layerCache = new LayerCache(imagesToSave);
layerCache.concurrency = parseInt(
core.getInput(`concurrency`, { required: true }),
10
);
await layerCache.store(primaryKey);
await layerCache.cleanUp();
};
main().catch((e) => {
console.error(e);
core.setFailed(e);
});