Skip to content

Commit fc4ece4

Browse files
committed
initial commit
0 parents  commit fc4ece4

6 files changed

Lines changed: 87 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
package-lock.json

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Set up node using nvm
2+
3+
This action sets up a specific node.js version on GitHub Actions using nvm.
4+
5+
## Inputs
6+
7+
### node-version
8+
9+
The node.js version to install and use, according to nvm.
10+
11+
### node-mirror
12+
13+
The node.js mirror to use, e.g. `https://nodejs.org/download/v8-canary/` for canary.
14+
15+
## Example usage:
16+
17+
```yaml
18+
uses: dcodeIO/setup-node-nvm
19+
with:
20+
node-version: lts/*
21+
```
22+
23+
```yaml
24+
uses: dcodeIO/setup-node-nvm
25+
with:
26+
node-version: node
27+
node-mirror: https://nodejs.org/download/v8-canary/
28+
```

action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Set up node
2+
description: Sets up a specific node.js version using nvm
3+
author: dcodeIO
4+
inputs:
5+
node-version:
6+
description: The node.js version to use according to nvm
7+
default: node
8+
node-mirror:
9+
description: The node.js mirror to use
10+
default: https://nodejs.org/dist/
11+
runs:
12+
using: node12
13+
main: index.js

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const child_process = require("child_process");
2+
const core = require("@actions/core");
3+
const version = core.getInput("node-version");
4+
const mirror = core.getInput("node-mirror");
5+
var child = child_process.spawnSync("bash", [ "install.sh", version, mirror ], { stdio: "inherit", encoding: "utf8" });
6+
if (child.status != 0) throw Error("installation failed with " + child.status);
7+
var nodePath;
8+
var npmPath;
9+
try {
10+
nodePath = /SETUP_NODE_NVM_NODE: ([^\n]+)/.exec(child.stdout)[1];
11+
npmPath = /SETUP_NODE_NVM_NPM: ([^\n]+)/.exec(child.stdout)[1];
12+
} catch (e) {
13+
throw Error("missing node/npm path in output");
14+
}
15+
console.log("Using node: " + nodePath);
16+
core.setPath(nodePath);
17+
console.log("Using npm: " + npmPath);
18+
core.setPath(npmPath);

install.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
4+
export NVM_DIR="$HOME/.nvm"
5+
export NVM_NODEJS_ORG_MIRROR="$2"
6+
chmod +x "$NVM_DIR/nvm.sh"
7+
"$NVM_DIR/nvm.sh" --no-use
8+
nvm install $1
9+
nvm use $1
10+
npm -g install npm
11+
echo "SETUP_NODE_NVM_NODE: $(which node)"
12+
echo "SETUP_NODE_NVM_NPM: $(which npm)"

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "setup-node-nvm",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "setup-node-nvm action",
6+
"main": "index.js",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/dcodeIO/setup-node-nvm.git"
10+
},
11+
"dependencies": {
12+
"@actions/core": "^1.1.0"
13+
}
14+
}

0 commit comments

Comments
 (0)