This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
76 lines (63 loc) · 3.09 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const core = require('@actions/core');
const cache = require('@actions/cache');
const exec = require('@actions/exec');
const tc = require('@actions/tool-cache');
const io = require('@actions/io');
const ioUtil = require('@actions/io/lib/io-util.js');
const { getConfig } = require("./config");
async function setupCompiler(version, elmHome) {
try {
elmHome = elmHome === ''
? (process.env.ELM_HOME || `${process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']}/elm_home`)
: elmHome;
let elmCompiler = await io.which('elm', false);
if (core.getInput('cache')) {
core.info('Trying to restore cached ELM config');
const { paths, key, restoreKeys } = getConfig(elmHome);
await cache.restoreCache(paths, key, restoreKeys)
}
if (elmCompiler === '') {
elmCompiler = tc.find(`elm-${process.platform}`, version, 'x64');
}
if (await ioUtil.exists(`${elmHome}/elm`)) {
elmCompiler = `${elmHome}/elm`;
}
if (elmCompiler === '') {
core.info(`Downloading Elm ${version} for ${process.platform} ...`);
let elmDownloadPath = '';
if (process.platform === 'win32') {
elmDownloadPath = await tc.downloadTool(`https://github.com/elm/compiler/releases/download/${version}/binary-for-windows-64-bit.gz`);
} else if (process.platform === 'linux') {
elmDownloadPath = await tc.downloadTool(`https://github.com/elm/compiler/releases/download/${version}/binary-for-linux-64-bit.gz`);
} else if (process.platform === 'darwin') {
elmDownloadPath = await tc.downloadTool(`https://github.com/elm/compiler/releases/download/${version}/binary-for-mac-64-bit.gz`);
} else {
core.setFailed(`There is no elm for "${process.platform}"`);
}
const newPath =
process.platform === 'win32'
? elmDownloadPath.replace(/\\[^\\]+$/, "\\elm.gz")
: elmDownloadPath.replace(/\/[^\/]+$/, "/elm.gz");
await ioUtil.rename(elmDownloadPath, newPath);
elmDownloadPath = newPath;
if (process.platform === 'win32') {
await exec.exec(`gzip -df \"${elmDownloadPath}\"`);
} else {
await exec.exec(`gunzip ${elmDownloadPath}`);
}
if (!await ioUtil.exists(`${elmHome}`)) {
await exec.exec(`mkdir ${elmHome}`);
}
elmCompiler = `${elmHome}/elm`;
await exec.exec(`cp ${elmDownloadPath.replace('.gz', '')} ${elmCompiler}`);
await exec.exec(`chmod +x ${elmCompiler}`);
await tc.cacheFile(elmCompiler, 'elm', `elm-${process.platform}`, version);
}
core.addPath(elmCompiler.replace(/elm$/, ''));
core.exportVariable('ELM_HOME', elmHome);
core.setOutput('elm-home', elmHome);
} catch (error) {
core.setFailed(error.message);
}
}
setupCompiler(core.getInput('elm-version'), core.getInput('elm-home'));