generated from actions/hello-world-javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathfetch.js
More file actions
76 lines (61 loc) · 2.51 KB
/
fetch.js
File metadata and controls
76 lines (61 loc) · 2.51 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 fetchCache() {
try {
const paths = [];
const restoreKeys = [];
const mixkey = core.getInput("mixkey");
const prefix = core.getInput("prefix");
const cleanUpCache = parseBooleanInput(core.getInput("clean"));
if (cleanUpCache) return;
if (prefix) {
process.chdir(prefix);
core.debug(`Changed working directory to: ${prefix}`);
}
let keyString = mixkey ? `${mixkey}-cache-openwrt` : "cache-openwrt";
const cacheToolchain = parseBooleanInput(core.getInput("toolchain"), true);
const skipBuildingToolchain = parseBooleanInput(core.getInput("skip"), 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*")
);
} else {
core.debug("Skipping toolchain processing");
}
const cacheCcache = parseBooleanInput(core.getInput("ccache"));
if (cacheCcache) {
const timestamp = execSync("date +%s").toString().trim();
restoreKeys.unshift(keyString);
keyString += `-${timestamp}`;
paths.push(".ccache");
}
core.debug(`Cache paths: ${paths.join(", ")}`);
console.log(keyString, restoreKeys);
const cacheFetchingResult = await cache.restoreCache(paths, keyString, restoreKeys);
if (cacheFetchingResult) {
core.info(`${cacheFetchingResult} cache fetched!`);
core.setOutput("hit", "1");
core.saveState("CACHE_STATE", "hit");
if (cacheToolchain && skipBuildingToolchain) {
execSync("sed -i 's/ $(tool.*\\/stamp-compile)//;' Makefile");
execSync("sed -i 's/ $(tool.*\\/stamp-install)//;' Makefile");
core.info("Toolchain building skipped");
}
}
} catch (error) {
core.setFailed(error.message);
process.exit(1);
}
}
fetchCache();