-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (53 loc) · 1.69 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 core = require('@actions/core');
const tc = require('@actions/tool-cache');
run().catch(error => {
core.setFailed(error.message);
})
async function run() {
const version = core.getInput('version');
const downloadUrlWithVersion = getURLForVersion(version);
const cliArch = getCliArch()
switch (process.platform) {
case "win32": {
const url = `${downloadUrlWithVersion}/workos_cli_Windows_${cliArch}.zip`;
await installZip(url);
break;
}
case "linux":
case "darwin": {
const url = `${downloadUrlWithVersion}/workos_cli_${process.platform}_${cliArch}.tar.gz`;
await installTarball(url);
break;
}
default: {
throw new Error(`Unsupported platform '${process.platform}'`);
}
}
}
function getURLForVersion(version) {
if (version === 'latest') {
return `https://github.com/workos/workos-cli/releases/${version}/download`
} else {
return `https://github.com/workos/workos-cli/releases/download/${version}`
}
}
function getCliArch() {
switch (process.arch) {
case "arm64":
return "arm64";
case "x64":
return "x86_64";
default:
throw new Error(`Unsupported architecture '${process.arch}'`);
}
}
async function installZip(url) {
const downloadPath = await tc.downloadTool(url);
const pathToCLI = await tc.extractZip(downloadPath);
core.addPath(pathToCLI + "/bin");
}
async function installTarball(url) {
const downloadPath = await tc.downloadTool(url);
const pathToCLI = await tc.extractTar(downloadPath);
core.addPath(pathToCLI + "/bin");
}