-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
60 lines (52 loc) · 1.4 KB
/
index.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
const cache = require('@actions/cache');
const core = require('@actions/core');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec)
async function latestCacheKey()
{
return (await exec(String.raw`bash -c "curl https://jwakely.github.io/pkg-gcc-latest/ | grep gcc-latest_ | sed 's/.*>\(gcc-latest_.*\).deb<.*/\1/'"`)).stdout.trim();
}
const paths = ['/opt/gcc-latest/'];
async function restoreCache()
{
const key = await latestCacheKey();
return [ (await cache.restoreCache(paths, key, Array()) !== undefined), key ];
}
async function setUpPackage()
{
exec('bash -c "wget http://kayari.org/gcc-latest/gcc-latest.deb && sudo dpkg -i gcc-latest.deb && rm gcc-latest.deb"',
{ cwd: process.env.RUNNER_TEMP });
}
function saveCache(key)
{
cache.saveCache(paths, key);
}
function setUpEnvironment()
{
core.addPath('/opt/gcc-latest/bin');
core.exportVariable('LD_RUN_PATH', '/opt/gcc-latest/lib64');
}
async function run()
{
try {
if (core.getInput('cache'))
{
const [ restored, key ] = await restoreCache();
if (!restored)
{
await setUpPackage();
saveCache(key);
}
}
else
{
await setUpPackage();
}
setUpEnvironment();
}
catch (error)
{
core.setFailed(error.message);
}
}
run();