Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to default to .nvmrc #1

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 133 additions & 136 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Test
on:
push:
branches:
- master
pull_request:
branches:
- master

env:
NVM_NODE_VERSION: v18.17.0

jobs:
linux-lts:
runs-on: ubuntu-latest
Expand All @@ -18,35 +21,35 @@ jobs:
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-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:
Expand All @@ -58,128 +61,122 @@ jobs:
node -v
which npm
npm -v
if [ $(node -v) != "v12.9.0" ]; then
if [ $(node -v) != "$NVM_NODE_VERSION" ]; 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:
# 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-canary:
# 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
# if [ $(node -v) != "$NVM_NODE_VERSION" ]; then
# exit 1;
# fi
# 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
# if [ $(node -v) != "$NVM_NODE_VERSION" ]; then
# exit 1;
# fi
# 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
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 .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.9.0
18.17.0
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ The node.js mirror to use, e.g. `https://nodejs.org/download/v8-canary/` for nod
## Example usage:

```yaml
uses: dcodeIO/setup-node-nvm@master
uses: irby/setup-node-nvm@master
with:
node-version: lts/*
```

```yaml
uses: dcodeIO/setup-node-nvm@master
uses: irby/setup-node-nvm@master
```

```yaml
uses: irby/setup-node-nvm@master
with:
node-version: node
node-mirror: https://nodejs.org/download/v8-canary/
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Set up node using nvm
description: Sets up a specific node.js version using nvm
author: dcodeIO
author: irby
inputs:
node-version:
description: The node.js version to use according to nvm. Uses the version specified in .nvmrc if omitted.
Expand All @@ -12,5 +12,5 @@ branding:
icon: download
color: green
runs:
using: node16
using: node20
main: index.js
27 changes: 16 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ const path = require("path");
const core = require("@actions/core");
const semver = require("semver");
const nv = require("@pkgjs/nv");
const { promises: fs } = require("fs");

// 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;
let query = version;
switch (query) {
case "node": { query = "current"; break; }
case "lts/*": { query = "lts_latest"; break; }
case "latest": { query = "all"; break; }
default: {
query = await fs.readFile(".nvmrc", "utf8").catch(err => {
console.error("Failed to read .nvmrc file", err);
throw err;
});
}
}
const versions = await nv(query, { mirror });
if (versions.length) {
versions.sort((a, b) => semver.rcompare(a.version, b.version));
return versions[0].version;
}
return version;
}

Expand Down
Loading