diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a4c6ea..7245337 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 + npm -v + if ((node -e 'console.log(process.arch)') -ne 'ia32') { exit 1 } + # windows-nvmrc: # runs-on: windows-latest # steps: diff --git a/README.md b/README.md index 7953793..6499d31 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ 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). +Note that the action will reject to run on both GNU/Linux and macOS if node-arch is provided. + ## Example usage: ```yaml diff --git a/action.yml b/action.yml index c6ec2f4..f627769 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 system arch if omitted. + default: "" branding: icon: download color: green diff --git a/index.js b/index.js index ee55278..3f896e8 100644 --- a/index.js +++ b/index.js @@ -25,15 +25,20 @@ 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") { - runScript("powershell", ".\\install.ps1", version, mirror); + runScript("powershell", ".\\install.ps1", version, mirror, arch); } else { + if (arch) throw Error("Invalid input parameter: node-arch"); runScript("bash", "install.sh", version, mirror); } -})(); +})().catch (error => { + core.setFailed(error.message); +}); -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 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 = []; 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"