Skip to content

Commit 95b79d1

Browse files
authored
Add various compatibility layers (#5)
1 parent d7969b0 commit 95b79d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3392
-114
lines changed

.github/workflows/canary.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/lts.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/nvmrc.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/specific.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/stable.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
jobs:
8+
linux-lts:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@master
12+
- uses: ./
13+
with:
14+
node-version: lts/*
15+
- name: Check
16+
run: |
17+
which node
18+
node -v
19+
which npm
20+
npm -v
21+
linux-stable:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@master
25+
- uses: ./
26+
with:
27+
node-version: node
28+
- name: Check
29+
run: |
30+
which node
31+
node -v
32+
which npm
33+
npm -v
34+
linux-exact:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@master
38+
- uses: ./
39+
with:
40+
node-version: "10.0.0"
41+
- name: Check
42+
run: |
43+
which node
44+
node -v
45+
which npm
46+
npm -v
47+
if [ $(node -v) != "v10.0.0" ]; then
48+
exit 1;
49+
fi
50+
linux-nvmrc:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@master
54+
- uses: ./
55+
- name: Check
56+
run: |
57+
which node
58+
node -v
59+
which npm
60+
npm -v
61+
if [ $(node -v) != "v12.9.0" ]; then
62+
exit 1;
63+
fi
64+
linux-canary:
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@master
68+
- uses: ./
69+
with:
70+
node-version: latest
71+
node-mirror: https://nodejs.org/download/v8-canary/
72+
- name: Check
73+
run: |
74+
which node
75+
node -v
76+
which npm
77+
npm -v
78+
windows-lts:
79+
runs-on: windows-latest
80+
steps:
81+
- uses: actions/checkout@master
82+
- uses: ./
83+
with:
84+
node-version: lts/*
85+
- name: Check
86+
run: |
87+
node -v
88+
npm -v
89+
windows-stable:
90+
runs-on: windows-latest
91+
steps:
92+
- uses: actions/checkout@master
93+
- uses: ./
94+
with:
95+
node-version: node
96+
- name: Check
97+
run: |
98+
node -v
99+
npm -v
100+
windows-exact:
101+
runs-on: windows-latest
102+
steps:
103+
- uses: actions/checkout@master
104+
- uses: ./
105+
with:
106+
node-version: "10.0.0"
107+
- name: Check
108+
run: |
109+
node -v
110+
npm -v
111+
# windows-nvmrc:
112+
# runs-on: windows-latest
113+
# steps:
114+
# - uses: actions/checkout@master
115+
# - uses: ./
116+
# - name: Check
117+
# run: |
118+
# node -v
119+
# npm -v
120+
# windows-canary:
121+
# runs-on: windows-latest
122+
# steps:
123+
# - uses: actions/checkout@master
124+
# - uses: ./
125+
# with:
126+
# node-version: latest
127+
# node-mirror: https://nodejs.org/download/v8-canary/
128+
# - name: Check
129+
# run: |
130+
# node -v
131+
# npm -v
132+
macos-lts:
133+
runs-on: macos-latest
134+
steps:
135+
- uses: actions/checkout@master
136+
- uses: ./
137+
with:
138+
node-version: lts/*
139+
- name: Check
140+
run: |
141+
node -v
142+
npm -v
143+
macos-stable:
144+
runs-on: macos-latest
145+
steps:
146+
- uses: actions/checkout@master
147+
- uses: ./
148+
with:
149+
node-version: node
150+
- name: Check
151+
run: |
152+
node -v
153+
npm -v
154+
macos-exact:
155+
runs-on: macos-latest
156+
steps:
157+
- uses: actions/checkout@master
158+
- uses: ./
159+
with:
160+
node-version: "10.0.0"
161+
- name: Check
162+
run: |
163+
node -v
164+
npm -v
165+
macos-nvmrc:
166+
runs-on: macos-latest
167+
steps:
168+
- uses: actions/checkout@master
169+
- uses: ./
170+
- name: Check
171+
run: |
172+
node -v
173+
npm -v
174+
macos-canary:
175+
runs-on: macos-latest
176+
steps:
177+
- uses: actions/checkout@master
178+
- uses: ./
179+
with:
180+
node-version: latest
181+
node-mirror: https://nodejs.org/download/v8-canary/
182+
- name: Check
183+
run: |
184+
node -v
185+
npm -v

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Set up node using nvm
22

3-
This action sets up a specific node.js version on GitHub Actions using nvm, very similar to the original [@actions/setup-node](https://github.com/actions/setup-node). Unlike setup-node (at the time of this writing) it does support `lts/*` (latest LTS), `node` (latest stable) and custom mirrors like the one for v8-canary, but does not work on Windows.
3+
This action sets up a specific node.js version on GitHub Actions using [nvm](https://github.com/nvm-sh/nvm), very similar to [@actions/setup-node](https://github.com/actions/setup-node). Unlike setup-node (at the time of this writing) it does support several aliases and custom mirrors like the one for [node-v8](https://github.com/nodejs/node-v8). Note that this is merely intended as a placeholder until setup-node supports [aliases](https://github.com/actions/setup-node/issues/26), which is crucial for rolling testing, and [mirrors](https://github.com/actions/setup-node/issues/65), which is useful for WebAssembly testing. Has some Windows support via [nvm-windows](https://github.com/coreybutler/nvm-windows), but there are issues with versions newer than current and `.nvmrc`.
44

55
## Inputs
66

index.js

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,65 @@
11
const child_process = require("child_process");
22
const path = require("path");
33
const core = require("@actions/core");
4-
const version = core.getInput("node-version");
5-
const mirror = core.getInput("node-mirror");
6-
const child = child_process.spawn("bash", [ "install.sh", version, mirror ], { cwd: __dirname });
7-
const stdout = [];
8-
child.stdout.on("data", out => {
9-
stdout.push(out);
10-
process.stdout.write(out);
11-
});
12-
child.stderr.on("data", out => {
13-
process.stderr.write(out);
14-
});
15-
child.on("close", code => {
16-
if (code !== 0) throw Error("installation failed with " + code);
17-
const out = Buffer.concat(stdout).toString("utf8");
18-
var nodePath;
19-
var npmPath;
20-
try {
21-
nodePath = /SETUP_NODE_NVM_NODE: ([^\n]+)/.exec(out)[1];
22-
npmPath = /SETUP_NODE_NVM_NPM: ([^\n]+)/.exec(out)[1];
23-
} catch (e) {
24-
throw Error("missing node/npm path in output");
4+
const semver = require("semver");
5+
const nv = require("@pkgjs/nv");
6+
7+
// Utilize @pkgjs/nv to resolve before forwarding to nvm / nvm-windows
8+
async function resolveVersion(version, mirror) {
9+
if (version) {
10+
let query = version;
11+
switch (query) {
12+
case "node": { query = "current"; break; }
13+
case "lts/*": { query = "lts_latest"; break; }
14+
case "latest": { query = "all"; break; }
15+
}
16+
const versions = await nv(query, { mirror });
17+
if (versions.length) {
18+
versions.sort((a, b) => semver.rcompare(a.version, b.version));
19+
return versions[0].version;
20+
}
2521
}
26-
console.log("Using node: " + nodePath);
27-
core.addPath(path.dirname(nodePath));
28-
console.log("Using npm: " + npmPath);
29-
core.addPath(path.dirname(npmPath));
30-
});
22+
return version;
23+
}
24+
25+
(async () => {
26+
let mirror = core.getInput("node-mirror") || "https://nodejs.org/dist/";
27+
let version = await resolveVersion(core.getInput("node-version"), mirror);
28+
if (process.platform == "win32") {
29+
runScript("powershell", ".\\install.ps1", version, mirror);
30+
} else {
31+
runScript("bash", "install.sh", version, mirror);
32+
}
33+
})();
34+
35+
function runScript(shell, script, version, mirror) {
36+
const child = child_process.spawn(shell, [ script, version, mirror ], { cwd: __dirname });
37+
const stdout = [];
38+
child.stdout.on("data", out => {
39+
stdout.push(out);
40+
process.stdout.write(out);
41+
});
42+
child.stderr.on("data", out => {
43+
process.stderr.write(out);
44+
});
45+
child.on("close", code => {
46+
if (code !== 0) throw Error("installation failed with " + code);
47+
const out = Buffer.concat(stdout).toString("utf8");
48+
var nvmPath;
49+
var nodePath;
50+
var npmPath;
51+
try {
52+
nvmPath = /SETUP_NODE_NVM_NVM: ([^\n]+)/.exec(out)[1];
53+
nodePath = /SETUP_NODE_NVM_NODE: ([^\n]+)/.exec(out)[1];
54+
npmPath = /SETUP_NODE_NVM_NPM: ([^\n]+)/.exec(out)[1];
55+
} catch (e) {
56+
throw Error("missing nvm/node/npm path in output");
57+
}
58+
console.log("Using nvm: " + nvmPath);
59+
core.addPath(path.dirname(nvmPath));
60+
console.log("Using node: " + nodePath);
61+
core.addPath(path.dirname(nodePath));
62+
console.log("Using npm: " + npmPath);
63+
core.addPath(path.dirname(npmPath));
64+
});
65+
}

install.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$NVM_HOME="$((Get-Location).Path)\mynvm"
2+
$env:NVM_HOME=$NVM_HOME
3+
$env:NVM_PATH=$NVM_HOME
4+
$env:NVM_SYMLINK="$NVM_HOME\nodejs"
5+
$env:PATH=$env:PATH + ";$NVM_HOME"
6+
Invoke-WebRequest -Uri https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-noinstall.zip -OutFile nvm.zip
7+
Expand-Archive nvm.zip -DestinationPath "$NVM_HOME"
8+
New-Item -Path "$NVM_HOME\settings.txt" -ItemType File
9+
nvm.exe root $NVM_HOME
10+
nvm.exe node_mirror $args[1]
11+
nvm.exe install $args[0]
12+
nvm.exe use $args[0]
13+
echo "SETUP_NODE_NVM_NVM: $NVM_HOME"
14+
echo "SETUP_NODE_NVM_NODE: $NVM_HOME\nodejs\node.exe"
15+
echo "SETUP_NODE_NVM_NPM: $NVM_HOME\nodejs\npm.cmd"

0 commit comments

Comments
 (0)