Skip to content

Commit

Permalink
Add various compatibility layers (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO authored Apr 10, 2020
1 parent d7969b0 commit 95b79d1
Show file tree
Hide file tree
Showing 70 changed files with 3,392 additions and 114 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/canary.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/lts.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/nvmrc.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/specific.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/stable.yml

This file was deleted.

185 changes: 185 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: Test
on:
push:
branches:
- master
pull_request:
jobs:
linux-lts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: lts/*
- name: Check
run: |
which node
node -v
which npm
npm -v
linux-stable:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: node
- name: Check
run: |
which node
node -v
which npm
npm -v
linux-exact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: "10.0.0"
- name: Check
run: |
which node
node -v
which npm
npm -v
if [ $(node -v) != "v10.0.0" ]; then
exit 1;
fi
linux-nvmrc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: ./
- name: Check
run: |
which node
node -v
which npm
npm -v
if [ $(node -v) != "v12.9.0" ]; then
exit 1;
fi
linux-canary:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: latest
node-mirror: https://nodejs.org/download/v8-canary/
- name: Check
run: |
which node
node -v
which npm
npm -v
windows-lts:
runs-on: windows-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: lts/*
- name: Check
run: |
node -v
npm -v
windows-stable:
runs-on: windows-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: node
- name: Check
run: |
node -v
npm -v
windows-exact:
runs-on: windows-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: "10.0.0"
- name: Check
run: |
node -v
npm -v
# windows-nvmrc:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@master
# - uses: ./
# - name: Check
# run: |
# node -v
# npm -v
# windows-canary:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@master
# - uses: ./
# with:
# node-version: latest
# node-mirror: https://nodejs.org/download/v8-canary/
# - name: Check
# run: |
# node -v
# npm -v
macos-lts:
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: lts/*
- name: Check
run: |
node -v
npm -v
macos-stable:
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: node
- name: Check
run: |
node -v
npm -v
macos-exact:
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: "10.0.0"
- name: Check
run: |
node -v
npm -v
macos-nvmrc:
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: ./
- name: Check
run: |
node -v
npm -v
macos-canary:
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: latest
node-mirror: https://nodejs.org/download/v8-canary/
- name: Check
run: |
node -v
npm -v
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Set up node using nvm

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.
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`.

## Inputs

Expand Down
87 changes: 61 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,65 @@
const child_process = require("child_process");
const path = require("path");
const core = require("@actions/core");
const version = core.getInput("node-version");
const mirror = core.getInput("node-mirror");
const child = child_process.spawn("bash", [ "install.sh", version, mirror ], { cwd: __dirname });
const stdout = [];
child.stdout.on("data", out => {
stdout.push(out);
process.stdout.write(out);
});
child.stderr.on("data", out => {
process.stderr.write(out);
});
child.on("close", code => {
if (code !== 0) throw Error("installation failed with " + code);
const out = Buffer.concat(stdout).toString("utf8");
var nodePath;
var npmPath;
try {
nodePath = /SETUP_NODE_NVM_NODE: ([^\n]+)/.exec(out)[1];
npmPath = /SETUP_NODE_NVM_NPM: ([^\n]+)/.exec(out)[1];
} catch (e) {
throw Error("missing node/npm path in output");
const semver = require("semver");
const nv = require("@pkgjs/nv");

// Utilize @pkgjs/nv to resolve before forwarding to nvm / nvm-windows
async function resolveVersion(version, mirror) {
if (version) {
let query = version;
switch (query) {
case "node": { query = "current"; break; }
case "lts/*": { query = "lts_latest"; break; }
case "latest": { query = "all"; break; }
}
const versions = await nv(query, { mirror });
if (versions.length) {
versions.sort((a, b) => semver.rcompare(a.version, b.version));
return versions[0].version;
}
}
console.log("Using node: " + nodePath);
core.addPath(path.dirname(nodePath));
console.log("Using npm: " + npmPath);
core.addPath(path.dirname(npmPath));
});
return version;
}

(async () => {
let mirror = core.getInput("node-mirror") || "https://nodejs.org/dist/";
let version = await resolveVersion(core.getInput("node-version"), mirror);
if (process.platform == "win32") {
runScript("powershell", ".\\install.ps1", version, mirror);
} else {
runScript("bash", "install.sh", version, mirror);
}
})();

function runScript(shell, script, version, mirror) {
const child = child_process.spawn(shell, [ script, version, mirror ], { cwd: __dirname });
const stdout = [];
child.stdout.on("data", out => {
stdout.push(out);
process.stdout.write(out);
});
child.stderr.on("data", out => {
process.stderr.write(out);
});
child.on("close", code => {
if (code !== 0) throw Error("installation failed with " + code);
const out = Buffer.concat(stdout).toString("utf8");
var nvmPath;
var nodePath;
var npmPath;
try {
nvmPath = /SETUP_NODE_NVM_NVM: ([^\n]+)/.exec(out)[1];
nodePath = /SETUP_NODE_NVM_NODE: ([^\n]+)/.exec(out)[1];
npmPath = /SETUP_NODE_NVM_NPM: ([^\n]+)/.exec(out)[1];
} catch (e) {
throw Error("missing nvm/node/npm path in output");
}
console.log("Using nvm: " + nvmPath);
core.addPath(path.dirname(nvmPath));
console.log("Using node: " + nodePath);
core.addPath(path.dirname(nodePath));
console.log("Using npm: " + npmPath);
core.addPath(path.dirname(npmPath));
});
}
15 changes: 15 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$NVM_HOME="$((Get-Location).Path)\mynvm"
$env:NVM_HOME=$NVM_HOME
$env:NVM_PATH=$NVM_HOME
$env:NVM_SYMLINK="$NVM_HOME\nodejs"
$env:PATH=$env:PATH + ";$NVM_HOME"
Invoke-WebRequest -Uri https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-noinstall.zip -OutFile nvm.zip
Expand-Archive nvm.zip -DestinationPath "$NVM_HOME"
New-Item -Path "$NVM_HOME\settings.txt" -ItemType File
nvm.exe root $NVM_HOME
nvm.exe node_mirror $args[1]
nvm.exe install $args[0]
nvm.exe use $args[0]
echo "SETUP_NODE_NVM_NVM: $NVM_HOME"
echo "SETUP_NODE_NVM_NODE: $NVM_HOME\nodejs\node.exe"
echo "SETUP_NODE_NVM_NPM: $NVM_HOME\nodejs\npm.cmd"
Loading

0 comments on commit 95b79d1

Please sign in to comment.