Skip to content

Commit 676f04d

Browse files
committed
Refactor to support Windows
1 parent 88311e0 commit 676f04d

File tree

5 files changed

+77
-44
lines changed

5 files changed

+77
-44
lines changed

Diff for: .github/workflows/test.yml

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
name: Tests
22

3-
on: [ push, pull_request ]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
defaults:
10+
run:
11+
shell: bash
412

513
jobs:
614
test:
715
name: Test
816
runs-on: ${{ matrix.os }}
917
strategy:
1018
matrix:
11-
os: [macos-latest, windows-latest, windows-2016, ubuntu-18.04]
19+
os: [macos-latest, windows-latest, ubuntu-latest]
1220
version: [1.1.0, 1.0.0]
1321
steps:
1422
- name: Checkout
@@ -19,4 +27,19 @@ jobs:
1927
with:
2028
version: ${{ matrix.version }}
2129

22-
- run: gh --version
30+
- name: Capture gh version installed
31+
run: |
32+
export GH_VERSION=$( gh --version )
33+
echo 'GH_VERSION_INSTALLED<<EOF' >> $GITHUB_ENV
34+
gh --version >> $GITHUB_ENV
35+
echo 'EOF' >> $GITHUB_ENV
36+
37+
- name: Verify
38+
shell: python
39+
env:
40+
GH_VERSION_EXPECTED: ${{ matrix.version }}
41+
run: |
42+
import sys, os
43+
sys.exit(
44+
int(not os.environ["GH_VERSION_EXPECTED"] in os.environ["GH_VERSION_INSTALLED"])
45+
)

Diff for: dist/index.js

+25-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: index.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
const path = require('path');
22
const core = require('@actions/core');
33
const tc = require('@actions/tool-cache');
4-
const { getDownloadURL } = require('./lib/utils');
4+
const { getDownloadObject } = require('./lib/utils');
55

66
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');
910

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);
1314

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);
1618

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+
}
1924
}
2025

2126
module.exports = setup
2227

2328
if (require.main === module) {
24-
try {
25-
setup();
26-
} catch (e) {
27-
core.error(e);
28-
}
29+
setup();
2930
}

Diff for: lib/utils.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const os = require('os');
2+
const path = require('path');
23

34
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
45
// return value in [amd64, 386, arm]
@@ -20,13 +21,16 @@ function mapOS(os) {
2021
return mappings[os] || os;
2122
}
2223

23-
function getDownloadURL(version) {
24-
const filename = `gh_${ version }_${ mapOS(os.platform()) }_${ mapArch(os.arch()) }`;
25-
const url = `https://github.com/cli/cli/releases/download/v${ version }/${ filename }.tar.gz`;
24+
function getDownloadObject(version) {
25+
const platform = os.platform();
26+
const filename = `gh_${ version }_${ mapOS(platform) }_${ mapArch(os.arch()) }`;
27+
const extension = platform === 'win32' ? 'zip' : 'tar.gz';
28+
const binPath = platform === 'win32' ? 'bin' : path.join(filename, 'bin');
29+
const url = `https://github.com/cli/cli/releases/download/v${ version }/${ filename }.${ extension }`;
2630
return {
2731
url,
28-
filename
32+
binPath
2933
};
3034
}
3135

32-
module.exports = { getDownloadURL }
36+
module.exports = { getDownloadObject }

0 commit comments

Comments
 (0)