-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (46 loc) · 1.47 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
const core = require('@actions/core');
const tc = require('@actions/tool-cache');
const isSemver = require('is-semver');
const {
getDownloadObject,
getLatestVersion,
setUpAuth,
} = require('./lib/utils');
async function setup() {
try {
// Get version of tool to be installed
let version = core.getInput('version');
const privateKey = core.getInput('api_private_key');
const publicKey = core.getInput('api_public_key');
if (!version || version === 'latest') {
version = await getLatestVersion();
}
if (!isSemver(version)) {
throw new Error(`Invalid version: ${version}`);
}
// Remove leading 'v' if present
if (version.startsWith('v')) {
version = version.slice(1);
}
// Download the specific version of the tool, e.g. as a tarball/zipball
const download = getDownloadObject(version);
core.info(`Downloading ${download.url}`);
const pathToTarball = await tc.downloadTool(download.url);
core.info(`Downloaded to ${pathToTarball}`);
// Extract the tarball/zipball onto host runner
const extract = download.url.endsWith('.zip')
? tc.extractZip
: tc.extractTar;
const pathToCLI = await extract(pathToTarball);
core.info(`Add ${pathToCLI} to PATH`);
// Expose the tool by adding it to the PATH
core.addPath(pathToCLI);
await setUpAuth(publicKey, privateKey);
} catch (e) {
core.setFailed(e);
}
}
module.exports = setup;
if (require.main === module) {
setup();
}