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

Added support to indicate node.js architecture on Windows (dcodeIO#8) #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ jobs:
run: |
node -v
npm -v
windows-with-arch:
runs-on: windows-latest
steps:
- uses: actions/checkout@master
- uses: ./
with:
node-version: "10.0.0"
node-mirror: https://nodejs.org/download/release/
node-arch: "32"
- name: Check
run: |
node -v
node -e 'console.log(process.arch)'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this an equality check so the step fails if the value doesn't match the expectation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, let me know if you prefer a different approach ;)

npm -v

# windows-nvmrc:
# runs-on: windows-latest
# steps:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ The node.js version to install and use, according to nvm. Uses the version speci

The node.js mirror to use, e.g. `https://nodejs.org/download/v8-canary/` for node on V8 lkgr.

### node-arch (Windows only)

The architecture of node.js to use. Defaults to system arch if omitted. More info about nvm-windows arch modifier [here](https://github.com/coreybutler/nvm-windows#usage).

## Example usage:

```yaml
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ inputs:
description: The node.js version to use according to nvm. Uses the version specified in .nvmrc if omitted.
default: ""
node-mirror:
description: The node.js mirror to use
description: The node.js mirror to use.
default: https://nodejs.org/dist/
node-arch:
description: The architecture of node.js to use (Only supported by nvm-windows). Defaults to system arch if omitted.
default: ""
branding:
icon: download
color: green
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ async function resolveVersion(version, mirror) {
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);
let arch = core.getInput("node-arch") || null;
runScript("powershell", ".\\install.ps1", version, mirror, arch);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this pass the string "null" on the command line? Perhaps just ""?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So true, I just updated it.

} else {
runScript("bash", "install.sh", version, mirror);
}
})();

function runScript(shell, script, version, mirror) {
const child = child_process.spawn(shell, [ script, version, mirror ], { cwd: __dirname });
// arch only applies to Windows platform, so it's a no-op on GNU/Linux and macOS
function runScript(shell, script, version, mirror, arch) {
const child = child_process.spawn(shell, [ script, version, mirror, arch ], { cwd: __dirname });
const stdout = [];
child.stdout.on("data", out => {
stdout.push(out);
Expand Down
6 changes: 3 additions & 3 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ $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
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]
nvm.exe install $args[0] $args[2]
nvm.exe use $args[0] $args[2]
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"