/
cache-save.ts
41 lines (39 loc) · 1.12 KB
/
cache-save.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
import * as core from "@actions/core";
import * as cache from "@actions/cache";
import { State } from "./constants";
async function run() {
try {
const cachePath = core.getState(State.CachePath);
const key = core.getState(State.CachePrimaryKey);
const cachedKey = core.getState(State.CacheMatchedKey);
const paths = [cachePath];
// save cache
if (cachedKey !== key) {
core.info(`saving cache for ${key}.`);
try {
await cache.saveCache(paths, key);
} catch (error) {
if (error instanceof Error) {
if (error.name === cache.ValidationError.name) {
throw error;
} else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message);
} else {
core.info(`[warning]${error.message}`);
}
} else {
core.info(`[warning]${error}`);
}
}
} else {
core.info(`cache for ${key} already exists, skip saving.`);
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(error);
} else {
core.setFailed(`${error}`);
}
}
}
run();