generated from actions/hello-world-javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 46
/
fetch.js
61 lines (57 loc) · 2.14 KB
/
fetch.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const core = require("@actions/core");
const execSync = require("child_process").execSync;
try {
var paths = new Array();
var mixkey = core.getInput("mixkey");
var keyString = mixkey ? mixkey + "-cache-openwrt" : "cache-openwrt";
var restoreKeys = new Array();
const prefix = core.getInput("prefix");
if (prefix != "") {
process.chdir(prefix);
}
const toolchain = core.getInput("toolchain");
var skiptoolchain = core.getInput("skip");
if (toolchain == "true") {
stdout = execSync('git log --pretty=tformat:"%h" -n1 tools toolchain')
.toString()
.trim();
//restoreKeys.unshift(keyString);
keyString = keyString + "-" + stdout;
paths.push("staging_dir/host*");
paths.push("staging_dir/tool*");
} else {
skiptoolchain = false;
}
const ccache = core.getInput("ccache");
if (ccache == "true") {
stdout = execSync("date +%s").toString().trim();
restoreKeys.unshift(keyString);
keyString = keyString + "-" + stdout;
paths.push(".ccache");
}
const cache = require("@actions/cache");
const clean = core.getInput("clean");
if (clean == "true") return;
console.log(keyString, restoreKeys);
const cacheKey = cache
.restoreCache(paths, keyString, restoreKeys)
.then((res) => {
if (typeof res !== "undefined" && res) {
console.log(res, " cache fetched!");
core.setOutput("hit", "1");
core.saveState("CACHE_STATE", "hit");
if (skiptoolchain == "true") {
console.log("skiped");
execSync(
"sed -i 's/ $(tool.*\\/stamp-compile)//;' Makefile"
);
execSync(
"sed -i 's/ $(tool.*\\/stamp-install)//;' Makefile"
);
//execSync('bash -c \'find build_dir\/{host*,toolchain-*} -name .built\\* -exec touch {} \\;; touch staging_dir\/{host*,toolchain-*}\/stamp\/.*\'');
}
}
});
} catch (error) {
core.setFailed(error.message);
}