Skip to content

Commit 3ced26d

Browse files
committed
Generate download URL dynamically
1 parent c00010d commit 3ced26d

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

dist/index.js

Lines changed: 20 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
const os = require('os');
22

3-
const core = require('@actions/core');
3+
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
4+
// return value in [amd64, 386, arm]
5+
function mapArch(arch) {
6+
const mappings = {
7+
x32: '386',
8+
x64: 'amd64'
9+
};
10+
return mappings[arch] || arch;
11+
}
412

5-
function getDownloadURL(version) {
6-
core.debug(`platform: ${ os.platform() }`);
7-
core.debug(`arch: ${ os.arch() }`);
8-
core.debug(version);
13+
// os in [darwin, linux, win32...] (https://nodejs.org/api/os.html#os_os_platform)
14+
// return value in [darwin, linux, windows]
15+
function mapOS(os) {
16+
const mappings = {
17+
darwin: 'macOS',
18+
win32: 'windows'
19+
};
20+
return mappings[os] || os;
21+
}
922

10-
// https://github.com/cli/cli/releases/download/v1.1.0/gh_1.1.0_linux_amd64.tar.gz
11-
// https://github.com/cli/cli/releases/download/v1.1.0/gh_1.1.0_macOS_amd64.tar.gz
12-
// https://github.com/cli/cli/releases/download/v1.1.0/gh_1.1.0_windows_amd64.zip
13-
return `https://github.com/cli/cli/releases/download/v${ version }/gh_${ version }_linux_amd64.tar.gz`
23+
function getDownloadURL(version) {
24+
return `https://github.com/cli/cli/releases/download/v${ version }/gh_${ version }_${ mapOS(os.platform()) }_${ mapArch(os.arch()) }.tar.gz`
1425
}
1526

1627
module.exports = { getDownloadURL }

0 commit comments

Comments
 (0)