-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.17 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
const core = require('@actions/core');
const io = require('@actions/io');
const tc = require('@actions/tool-cache');
const workspace = process.env.GITHUB_WORKSPACE;
const binDir = `${workspace}/bin`;
main().catch(error => {
core.setFailed(error)
})
async function main() {
switch (process.platform) {
case 'win32':
await installExecutable(binDir)
break;
case 'linux':
await installZip(binDir, process.platform)
break;
case 'darwin':
await installZip(binDir, 'mac')
break;
default:
break;
}
await core.addPath(binDir)
}
async function downloadTool(platform) {
const spectralDsn = core.getInput('spectral-dsn')
const url = `${spectralDsn}/latest/dl/${platform}`
return await tc.downloadTool(url);
}
async function installZip(path, platform) {
await io.mkdirP(path);
const downloadPath = await downloadTool(platform)
await tc.extractTar(downloadPath, path)
}
async function installExecutable(path) {
await io.mkdirP(path);
const downloadPath = await downloadTool('exe')
await io.mv(downloadPath, `${path}/spectral.exe`)
}