-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcache-save.js
43 lines (36 loc) · 1.45 KB
/
cache-save.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
import * as core from "@actions/core";
import * as cache from "@actions/cache";
import { getCacheDirectory, State } from "./cache-utils";
async function saveCache() {
const enableCache = core.getBooleanInput("cache");
if (!enableCache) {
core.info(`Caching disabled, not saving cache.`);
return;
}
try {
const primaryKey = core.getState(State.CachePrimaryKey);
const matchedKey = core.getState(State.CacheMatchedKey);
if (primaryKey !== matchedKey) {
await cache.saveCache([await getCacheDirectory()], primaryKey);
} else if (primaryKey === "" && matchedKey === "") {
// When using action for the first time and the project doesn't have Scarb.lock,
// `restoreCache()` returns an error during `getCacheKey()` method.
// As a result, primaryKey and matchedKey (by default) are empty strings,
// which would satisfy `else` branch, even though no cache would be found.
core.info(`Cache entry not found, not saving cache.`);
} else {
core.info(`Cache hit occurred, not saving cache.`);
}
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
process.exit(0);
} catch (e) {
core.error(e);
// vide supra
process.exit(1);
}
}
saveCache();