This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
54 lines (44 loc) · 1.45 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
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
const os = require("os");
const path = require("path");
const fs = require("fs-extra");
const fetch = require("node-fetch");
async function setup() {
const version = core.getInput("version");
const apiKey = core.getInput("baselime-api-key");
// Download the specific version of the tool, e.g. as a tarball
const { url } = getDownloadURL(version || (await getLatestCLIVersion()));
const pathToTarball = await tc.downloadTool(url);
// Extract the tarball onto the runner
const pathToCLI = await tc.extractTar(pathToTarball);
// Expose the tool by adding it to the PATH
core.addPath(pathToCLI);
await fs.outputJson(getPath(), { apiKey });
}
function getDownloadURL(version) {
const filename = "baselime";
const url = `https://github.com/Baselime/cli/releases/download/v${version}/${filename}-${os.platform()}-x64-v${version}.tar.gz`;
return {
url,
};
}
function getPath() {
return path.join(os.homedir(), ".config", "baselime", `default.json`);
}
async function getLatestCLIVersion() {
try {
const res = await (
await fetch("https://api.github.com/repos/baselime/cli/releases/latest")
).json();
return res.tag_name.replace("v", "");
} catch (error) {
core.setFailed(
`There was an error getting the latest version of the Baselime CLI ${error}`
);
}
}
module.exports = setup;
if (require.main === module) {
setup();
}