forked from stupidloud/cachewrtbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.js
More file actions
60 lines (50 loc) · 2.04 KB
/
save.js
File metadata and controls
60 lines (50 loc) · 2.04 KB
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
const core = require("@actions/core");
const { execSync } = require("child_process");
const path = require("path");
const cache = require("@actions/cache");
function parseBooleanInput(value, defaultValue = false) {
const normalized = value.trim().toLowerCase();
return { 'true': true, 'false': false }[normalized] ?? defaultValue;
}
async function saveCache() {
try {
const skipSaving = parseBooleanInput(core.getInput("skip_saving"));
const cacheState = core.getState("CACHE_STATE");
if (cacheState !== "hit" && !skipSaving) {
const paths = [];
const mixkey = core.getInput("mixkey");
let keyString = mixkey ? `${mixkey}-cache-openwrt` : "cache-openwrt";
const prefix = core.getInput("prefix");
if (prefix) {
process.chdir(prefix);
core.debug(`Changed working directory to: ${prefix}`);
}
const cacheToolchain = parseBooleanInput(core.getInput("toolchain"), true);
if (cacheToolchain) {
const toolchainHash = execSync(
'git log --pretty=tformat:"%h" -n1 tools toolchain'
).toString().trim();
keyString += `-${toolchainHash}`;
paths.push(
path.join("staging_dir", "host*"),
path.join("staging_dir", "tool*")
);
}
const cacheCcache = parseBooleanInput(core.getInput("ccache"));
if (cacheCcache) {
const timestamp = execSync("date +%s").toString().trim();
keyString += `-${timestamp}`;
paths.push(".ccache");
}
console.log(keyString);
await cache.saveCache(paths, keyString)
.then(res => {
if (res) console.log(res, " cache saved");
})
.catch(err => core.error(`Cache save failed: ${err.stack}`));
}
} catch (error) {
core.warning(error.message);
}
}
saveCache();