generated from actions/hello-world-javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathfetch.js
55 lines (50 loc) · 1.73 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
const core = require('@actions/core');
const github = require('@actions/github');
const execSync = require('child_process').execSync;
try {
var paths = new Array();
var keyString = '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*');
paths.push('build_dir/host*');
paths.push('build_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');
if ( skiptoolchain == 'true' ){
console.log('skiped');
//execSync('sed -i \'s/ $(tool.*\\/stamp-compile)//;\' 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);
}