|
1 | 1 | const path = require('path'); |
2 | 2 | const core = require('@actions/core'); |
3 | 3 | const tc = require('@actions/tool-cache'); |
4 | | -const { getDownloadURL } = require('./lib/utils'); |
| 4 | +const { getDownloadObject } = require('./lib/utils'); |
5 | 5 |
|
6 | 6 | async function setup() { |
7 | | - // Get version of tool to be installed |
8 | | - const version = core.getInput('version'); |
| 7 | + try { |
| 8 | + // Get version of tool to be installed |
| 9 | + const version = core.getInput('version'); |
9 | 10 |
|
10 | | - // Download the specific version of the tool, e.g. as a tarball |
11 | | - const downloadURL = getDownloadURL(version); |
12 | | - const pathToTarball = await tc.downloadTool(downloadURL.url); |
| 11 | + // Download the specific version of the tool, e.g. as a tarball/zipball |
| 12 | + const download = getDownloadObject(version); |
| 13 | + const pathToTarball = await tc.downloadTool(download.url); |
13 | 14 |
|
14 | | - // Extract the tarball onto host runner |
15 | | - const pathToCLI = await tc.extractTar(pathToTarball); |
| 15 | + // Extract the tarball/zipball onto host runner |
| 16 | + const extract = download.url.endsWith('.zip') ? tc.extractZip : tc.extractTar; |
| 17 | + const pathToCLI = await extract(pathToTarball); |
16 | 18 |
|
17 | | - // Expose the tool by adding it to the PATH |
18 | | - core.addPath(path.join(pathToCLI, downloadURL.filename, 'bin')); |
| 19 | + // Expose the tool by adding it to the PATH |
| 20 | + core.addPath(path.join(pathToCLI, download.binPath)); |
| 21 | + } catch (e) { |
| 22 | + core.setFailed(e); |
| 23 | + } |
19 | 24 | } |
20 | 25 |
|
21 | 26 | module.exports = setup |
22 | 27 |
|
23 | 28 | if (require.main === module) { |
24 | | - try { |
25 | | - setup(); |
26 | | - } catch (e) { |
27 | | - core.error(e); |
28 | | - } |
| 29 | + setup(); |
29 | 30 | } |
0 commit comments