-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (51 loc) · 1.67 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
const core = require('@actions/core');
const io = require('@actions/io');
const tc = require('@actions/tool-cache');
const exec = require("@actions/exec").exec;
const workspace = process.env.GITHUB_WORKSPACE;
const spectralDsn = core.getInput('spectral-dsn')
const binDir = `${workspace}/bin`;
// Provide SPECTRAL_DSN to spectral binary through env
core.exportVariable('SPECTRAL_DSN', spectralDsn);
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:
throw new Error(`Platform: ${process.platform} is not supported`);
}
await core.addPath(binDir)
await runSpectral()
}
async function downloadTool(platform) {
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`)
}
async function runSpectral() {
const scanCommand = getScanCommand()
await exec(scanCommand)
}
function getScanCommand() {
const spectralArgs = core.getInput('spectral-args')
return `${process.platform === 'win32' ? 'spectral.exe' : 'spectral'} ${spectralArgs}`
}