Skip to content

Commit c3a546f

Browse files
authored
Test action on windows (#267)
1 parent cf8f6d9 commit c3a546f

2 files changed

Lines changed: 50 additions & 23 deletions

File tree

.github/workflows/ci.action.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
include:
4747
- os: ubuntu-latest
4848
container: debian:buster-slim
49+
- os: windows-latest
4950
container: ${{ matrix.container }}
5051
steps:
5152
- uses: actions/checkout@v4
@@ -58,14 +59,22 @@ jobs:
5859
- uses: ./
5960
with:
6061
PKGX_DIR: ${{ matrix.prefix }}
61-
+: node@18 deno.land
62+
+: node@18 curl.se
63+
if: ${{ runner.os != 'Windows' }}
6264

63-
- run: test -f '${{ matrix.prefix }}/deno.land/v*/bin/deno'
65+
- uses: ./
66+
with:
67+
PKGX_DIR: ${{ matrix.prefix }}
68+
+: cmake.org^3 curl.se
69+
if: ${{ runner.os == 'Windows' }}
70+
71+
- run: test -f '${{ matrix.prefix }}/curl.se/v*/bin/curl'
6472
if: ${{ matrix.prefix }}
6573

6674
- run: pkgx --version
6775
- run: if [[ "$(node --version)" != v18.* ]]; then exit 1; fi
68-
- run: deno --version
76+
if: ${{ runner.os != 'Windows' }}
77+
- run: curl --version
6978

7079
multiple-apply-is-ok:
7180
runs-on: ubuntu-latest

action.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ const dstdir = (() => {
1111
fs.accessSync('/usr/local/bin', fs.constants.W_OK);
1212
return '/usr/local/bin';
1313
} catch (err) {
14-
return path.join(process.env.INPUT_PKGX_DIR || path.join(process.env.HOME, '.pkgx'), 'bin');
14+
return path.join(process.env.INPUT_PKGX_DIR || path.join(os.homedir(), '.pkgx'), 'bin');
1515
}
1616
})();
1717

1818
fs.writeFileSync(process.env["GITHUB_PATH"], `${dstdir}\n`);
1919

2020
function platform_key() {
21-
const platform = os.platform(); // 'darwin', 'linux', 'win32', etc.
21+
let platform = os.platform(); // 'darwin', 'linux', 'win32', etc.
22+
if (platform == 'win32') platform = 'windows';
2223
let arch = os.arch(); // 'x64', 'arm64', etc.
2324
if (arch == 'x64') arch = 'x86-64';
2425
if (arch == 'arm64') arch = 'aarch64';
2526
return `${platform}/${arch}`;
2627
}
2728

28-
function downloadAndExtract(url, destination) {
29+
function downloadAndExtract(url, destination, strip) {
2930
return new Promise((resolve, reject) => {
3031
https.get(url, (response) => {
3132
if (response.statusCode !== 200) {
@@ -35,7 +36,7 @@ function downloadAndExtract(url, destination) {
3536

3637
console.log(`extracting tarball…`);
3738

38-
const tar_stream = tar.x({ cwd: destination, strip: 3 });
39+
const tar_stream = tar.x({ cwd: destination, strip });
3940

4041
response
4142
.pipe(tar_stream) // Extract directly to destination
@@ -86,34 +87,47 @@ function parse_pkgx_output(output) {
8687
}
8788

8889
async function install_pkgx() {
89-
let url = `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/versions.txt`;
90+
let strip = 3;
9091

91-
console.log(`::group::installing ${dstdir}/pkgx`);
92-
console.log(`fetching ${url}`);
92+
async function get_url() {
93+
if (platform_key().startsWith('windows')) {
94+
// not yet versioned
95+
strip = 0;
96+
return 'https://pkgx.sh/Windows/x86_64.tgz';
97+
}
98+
99+
let url = `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/versions.txt`;
100+
101+
console.log(`fetching ${url}`);
93102

94-
const rsp = await fetch(url);
95-
const txt = await rsp.text();
103+
const rsp = await fetch(url);
104+
const txt = await rsp.text();
96105

97-
const versions = txt.split('\n');
98-
const version = process.env.INPUT_VERSION
99-
? semver.maxSatisfying(versions, process.env.INPUT_VERSION)
100-
: versions.slice(-1)[0];
106+
const versions = txt.split('\n');
107+
const version = process.env.INPUT_VERSION
108+
? semver.maxSatisfying(versions, process.env.INPUT_VERSION)
109+
: versions.slice(-1)[0];
101110

102-
if (!version) {
103-
throw new Error(`no version found for ${process.env.INPUT_VERSION}`);
111+
if (!version) {
112+
throw new Error(`no version found for ${process.env.INPUT_VERSION}`);
113+
}
114+
115+
console.log(`selected pkgx v${version}`);
116+
117+
return `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/v${version}.tar.gz`;
104118
}
105119

106-
console.log(`selected pkgx v${version}`);
120+
console.log(`::group::installing ${path.join(dstdir, 'pkgx')}`);
107121

108-
url = `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/v${version}.tar.gz`;
122+
const url = await get_url();
109123

110124
console.log(`fetching ${url}`);
111125

112126
if (!fs.existsSync(dstdir)) {
113127
fs.mkdirSync(dstdir, {recursive: true});
114128
}
115129

116-
await downloadAndExtract(url, dstdir);
130+
await downloadAndExtract(url, dstdir, strip);
117131

118132
console.log(`::endgroup::`);
119133
}
@@ -134,8 +148,12 @@ async function install_pkgx() {
134148

135149
if (process.env['INPUT_+']) {
136150
console.log(`::group::installing pkgx input packages`);
137-
const args = process.env['INPUT_+'].split(' ');
138-
const cmd = `${dstdir}/pkgx ${args.map(x => `+${x}`).join(' ')}`;
151+
let args = process.env['INPUT_+'].split(' ');
152+
if (os.platform() == 'win32') {
153+
// cmd.exe uses ^ as an escape character
154+
args = args.map(x => x.replace('^', '^^'));
155+
}
156+
const cmd = `${path.join(dstdir, 'pkgx')} ${args.map(x => `+${x}`).join(' ')}`;
139157
console.log(`running: \`${cmd}\``);
140158
let env = undefined;
141159
if (process.env.INPUT_PKGX_DIR) {

0 commit comments

Comments
 (0)