From 8b8f16a705ecc59479114415df27d85c97c0d2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Tue, 10 Nov 2020 12:15:20 +0100 Subject: [PATCH 1/5] Added support to indicate node.js architecture on Windows (dcodeIO#8) --- .github/workflows/test.yml | 15 +++++++++++++++ action.yml | 5 ++++- index.js | 8 +++++--- install.ps1 | 6 +++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a4c6ea..4f9f7fa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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)' + npm -v + # windows-nvmrc: # runs-on: windows-latest # steps: diff --git a/action.yml b/action.yml index c6ec2f4..af3be76 100644 --- a/action.yml +++ b/action.yml @@ -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 64 bit if omitted. + default: "" branding: icon: download color: green diff --git a/index.js b/index.js index ee55278..1a44ead 100644 --- a/index.js +++ b/index.js @@ -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); } 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); diff --git a/install.ps1 b/install.ps1 index eb9b416..6a0207c 100644 --- a/install.ps1 +++ b/install.ps1 @@ -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" From 7358d3c3b11b9e3fbb4f78b989991f9444629dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Tue, 10 Nov 2020 12:44:20 +0100 Subject: [PATCH 2/5] Updated README.md (dcodeIO#8) --- README.md | 4 ++++ action.yml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7953793..d1c59bc 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index af3be76..f627769 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,7 @@ inputs: 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 64 bit if omitted. + description: The architecture of node.js to use (Only supported by nvm-windows). Defaults to system arch if omitted. default: "" branding: icon: download From 4aa073e40593e1d35c42126748a60c6710aa72d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Tue, 10 Nov 2020 15:54:47 +0100 Subject: [PATCH 3/5] Addressed review comments (dcodeIO#8) --- .github/workflows/test.yml | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f9f7fa..7245337 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -120,8 +120,8 @@ jobs: - name: Check run: | node -v - node -e 'console.log(process.arch)' npm -v + if ((node -e 'console.log(process.arch)') -ne 'ia32') { exit 1 } # windows-nvmrc: # runs-on: windows-latest diff --git a/index.js b/index.js index 1a44ead..e1ef50f 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ 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") { - let arch = core.getInput("node-arch") || null; + let arch = core.getInput("node-arch") || ""; runScript("powershell", ".\\install.ps1", version, mirror, arch); } else { runScript("bash", "install.sh", version, mirror); From 67539e193ee24beb33ac1ca1d24bd95dfa7bab53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Mon, 23 Nov 2020 19:34:52 +0100 Subject: [PATCH 4/5] Throwing if node-arch is provided on linux and macos (dcodeIO#8) --- README.md | 1 + index.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d1c59bc..6499d31 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ The node.js mirror to use, e.g. `https://nodejs.org/download/v8-canary/` for nod ### 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). +Note that the action will reject to run on both GNU/Linux and macOS if node-arch is provided. ## Example usage: diff --git a/index.js b/index.js index e1ef50f..bee5ec5 100644 --- a/index.js +++ b/index.js @@ -25,15 +25,16 @@ async function resolveVersion(version, mirror) { (async () => { let mirror = core.getInput("node-mirror") || "https://nodejs.org/dist/"; let version = await resolveVersion(core.getInput("node-version"), mirror); + let arch = core.getInput("node-arch") || ""; if (process.platform == "win32") { - let arch = core.getInput("node-arch") || ""; runScript("powershell", ".\\install.ps1", version, mirror, arch); } else { + if (arch) throw Error("Invalid input parameter: node-arch"); runScript("bash", "install.sh", version, mirror); } })(); -// arch only applies to Windows platform, so it's a no-op on GNU/Linux and macOS +// arch only applies to Windows platform, so it will throw on both GNU/Linux and macOS when provided function runScript(shell, script, version, mirror, arch) { const child = child_process.spawn(shell, [ script, version, mirror, arch ], { cwd: __dirname }); const stdout = []; From c4c8d5b555372c974e904aef25718e86cd7031e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Tue, 24 Nov 2020 02:04:50 +0100 Subject: [PATCH 5/5] Catch the errors and fail for real when node-arch is provided (dcodeIO#8) --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bee5ec5..3f896e8 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,9 @@ async function resolveVersion(version, mirror) { if (arch) throw Error("Invalid input parameter: node-arch"); runScript("bash", "install.sh", version, mirror); } -})(); +})().catch (error => { + core.setFailed(error.message); +}); // arch only applies to Windows platform, so it will throw on both GNU/Linux and macOS when provided function runScript(shell, script, version, mirror, arch) {