From 0635b31a614371b70fa13371ebeb26f3770f8d14 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:14:10 -0500 Subject: [PATCH 01/25] feat: add readme for architecture Co-Authored-By: Tyler Ang-Wanek --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 0bd60db7..a63f70c3 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,28 @@ jobs: - run: npm test ``` +Architecture: +The architecture can be selected using `node-arch`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms). +```yaml +jobs: + build: + runs-on: windows-latest + strategy: + matrix: + node: [ '10', '12' ] + arch: ['x86', 'x64'] + name: Node ${{ matrix.node }} on ${{ matrix.arch }} + steps: + - uses: actions/checkout@v2 + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + node-arch: ${{ matrix.arch }} + - run: npm install + - run: npm test +``` + Publish to npmjs and GPR with npm: ```yaml steps: From 2d8887128dabf6fe00c3cfd2f5a07b645d015765 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:15:06 -0500 Subject: [PATCH 02/25] feat: node-arch in action.yml Co-Authored-By: Tyler Ang-Wanek --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index e5b901fc..734f651f 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,8 @@ inputs: default: 'false' node-version: description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0' + node-arch: + description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.' check-latest: description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec' default: false From 42d59fbc367157620a6caada6fba63fffbf60dbc Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:40:40 -0500 Subject: [PATCH 03/25] feat: add arch to run --- src/main.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 328db0d2..b1a33dfe 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ import * as installer from './installer'; import * as auth from './authutil'; import * as path from 'path'; import {URL} from 'url'; +import os = require('os'); export async function run() { try { @@ -15,13 +16,18 @@ export async function run() { version = core.getInput('version'); } + let arch = core.getInput('node-arch'); + if (!arch) { + arch = os.arch(); + } + if (version) { let token = core.getInput('token'); let auth = !token || isGhes() ? undefined : `token ${token}`; let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; - await installer.getNode(version, stable, checkLatest, auth); + await installer.getNode(version, stable, checkLatest, auth, arch); } const registryUrl: string = core.getInput('registry-url'); From f27ebaf08bdd5244f493c0e7a2a2fc241b7d6a04 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:19:43 -0500 Subject: [PATCH 04/25] feat: add arch to getNode Co-Authored-By: Tyler Ang-Wanek --- src/installer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index feb8349c..5d533f90 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -27,10 +27,11 @@ export async function getNode( versionSpec: string, stable: boolean, checkLatest: boolean, - auth: string | undefined + auth: string | undefined, + arch: string = os.arch() ) { let osPlat: string = os.platform(); - let osArch: string = translateArchToDistUrl(os.arch()); + let osArch: string = translateArchToDistUrl(arch); if (checkLatest) { core.info('Attempt to resolve the latest version from manifest...'); From 6668516d2adf4adf48b9cb8700ab83d53b4bd865 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:35:58 -0500 Subject: [PATCH 05/25] feat: add arch to resolveVersionFromManifest --- src/installer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 5d533f90..a9cd3b00 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -38,7 +38,8 @@ export async function getNode( const resolvedVersion = await resolveVersionFromManifest( versionSpec, stable, - auth + auth, + osArch ); if (resolvedVersion) { versionSpec = resolvedVersion; @@ -215,7 +216,8 @@ async function getInfoFromDist( async function resolveVersionFromManifest( versionSpec: string, stable: boolean, - auth: string | undefined + auth: string | undefined, + osArch: string = translateArchToDistUrl(os.arch()) ): Promise { try { const info = await getInfoFromManifest(versionSpec, stable, auth); From 3e84c3523b95abf147c5bad9941685beff5edeb9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:29:40 -0500 Subject: [PATCH 06/25] feat: add arch to INodeVersionInfo --- src/installer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/installer.ts b/src/installer.ts index a9cd3b00..22c8953a 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -20,6 +20,7 @@ export interface INodeVersion { interface INodeVersionInfo { downloadUrl: string; resolvedVersion: string; + arch: string; fileName: string; } From 6afbfca452be9589ed60a1b9ee0e914b8534679c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:34:03 -0500 Subject: [PATCH 07/25] feat: add arch to getInfoFromManifest --- src/installer.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 22c8953a..1f2731ce 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -66,7 +66,7 @@ export async function getNode( // Try download from internal distribution (popular versions only) // try { - info = await getInfoFromManifest(versionSpec, stable, auth); + info = await getInfoFromManifest(versionSpec, stable, auth, osArch); if (info) { core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth); @@ -161,7 +161,8 @@ export async function getNode( async function getInfoFromManifest( versionSpec: string, stable: boolean, - auth: string | undefined + auth: string | undefined, + osArch: string = translateArchToDistUrl(os.arch()) ): Promise { let info: INodeVersionInfo | null = null; const releases = await tc.getManifestFromRepo( @@ -170,11 +171,12 @@ async function getInfoFromManifest( auth, 'main' ); - const rel = await tc.findFromManifest(versionSpec, stable, releases); + const rel = await tc.findFromManifest(versionSpec, stable, releases, osArch); if (rel && rel.files.length > 0) { info = {}; info.resolvedVersion = rel.version; + info.arch = rel.files[0].arch; info.downloadUrl = rel.files[0].download_url; info.fileName = rel.files[0].filename; } @@ -221,7 +223,7 @@ async function resolveVersionFromManifest( osArch: string = translateArchToDistUrl(os.arch()) ): Promise { try { - const info = await getInfoFromManifest(versionSpec, stable, auth); + const info = await getInfoFromManifest(versionSpec, stable, auth, osArch); return info?.resolvedVersion; } catch (err) { core.info('Unable to resolve version from manifest...'); From bf47decdc210253204f0b3f54941635c55116f7d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:20:04 -0500 Subject: [PATCH 08/25] feat: add arch to tc.find Co-Authored-By: Tyler Ang-Wanek --- src/installer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer.ts b/src/installer.ts index 1f2731ce..8d0f3d7e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -52,7 +52,7 @@ export async function getNode( // check cache let toolPath: string; - toolPath = tc.find('node', versionSpec); + toolPath = tc.find('node', versionSpec, osArch); // If not found in cache, download if (toolPath) { From 3eb4bc9d685415820bbce79073db385b2ce8279a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:24:52 -0500 Subject: [PATCH 09/25] feat: add arch to acquireNodeFromFallbackLocation --- src/installer.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 8d0f3d7e..310d79f0 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -107,7 +107,10 @@ export async function getNode( downloadPath = await tc.downloadTool(info.downloadUrl); } catch (err) { if (err instanceof tc.HTTPError && err.httpStatusCode == 404) { - return await acquireNodeFromFallbackLocation(info.resolvedVersion); + return await acquireNodeFromFallbackLocation( + info.resolvedVersion, + info.arch + ); } throw err; @@ -317,10 +320,11 @@ export async function getVersionsFromDist(): Promise { // Note also that the files are normally zipped but in this case they are just an exe // and lib file in a folder, not zipped. async function acquireNodeFromFallbackLocation( - version: string + version: string, + arch: string = os.arch() ): Promise { let osPlat: string = os.platform(); - let osArch: string = translateArchToDistUrl(os.arch()); + let osArch: string = translateArchToDistUrl(arch); // Create temporary folder to download in to const tempDownloadFolder: string = From c7e4d385413777209720679cc2cc8e8dd388c3ca Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:50:29 -0500 Subject: [PATCH 10/25] feat: add arch to downloading message --- __tests__/installer.test.ts | 4 ++-- src/installer.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 6f3a411e..b1e3cb0c 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -248,7 +248,7 @@ describe('setup-node', () => { expect(dlSpy).toHaveBeenCalled(); expect(exSpy).toHaveBeenCalled(); expect(logSpy).toHaveBeenCalledWith( - `Acquiring ${resolvedVersion} from ${expectedUrl}` + `Acquiring ${resolvedVersion} - ${os.arch} from ${expectedUrl}` ); expect(logSpy).toHaveBeenCalledWith( `Attempting to download ${versionSpec}...` @@ -399,7 +399,7 @@ describe('setup-node', () => { ); expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'"); expect(logSpy).toHaveBeenCalledWith( - `Acquiring 12.16.2 from ${expectedUrl}` + `Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}` ); expect(logSpy).toHaveBeenCalledWith('Extracting ...'); }); diff --git a/src/installer.ts b/src/installer.ts index 310d79f0..4553ece9 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -68,7 +68,9 @@ export async function getNode( try { info = await getInfoFromManifest(versionSpec, stable, auth, osArch); if (info) { - core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); + core.info( + `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}` + ); downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth); } else { core.info( @@ -102,7 +104,9 @@ export async function getNode( ); } - core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); + core.info( + `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}` + ); try { downloadPath = await tc.downloadTool(info.downloadUrl); } catch (err) { From 2e40994c28e2faa662d15fea703fec55ffb771da Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:54:48 -0500 Subject: [PATCH 11/25] feat: add arch to getInfoFromDist --- src/installer.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 4553ece9..b109a58e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -97,7 +97,7 @@ export async function getNode( // Download from nodejs.org // if (!downloadPath) { - info = await getInfoFromDist(versionSpec); + info = await getInfoFromDist(versionSpec, arch); if (!info) { throw new Error( `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` @@ -192,10 +192,11 @@ async function getInfoFromManifest( } async function getInfoFromDist( - versionSpec: string + versionSpec: string, + arch: string = os.arch() ): Promise { let osPlat: string = os.platform(); - let osArch: string = translateArchToDistUrl(os.arch()); + let osArch: string = translateArchToDistUrl(arch); let version: string; @@ -219,6 +220,7 @@ async function getInfoFromDist( return { downloadUrl: url, resolvedVersion: version, + arch: osArch, fileName: fileName }; } From 82271389a67b2caff50e06cdbb6710735465c09f Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 07:58:24 -0500 Subject: [PATCH 12/25] feat: add arch to cacheDir --- src/installer.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index b109a58e..a2c4d6a1 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -147,7 +147,12 @@ export async function getNode( // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded // core.info('Adding to the cache ...'); - toolPath = await tc.cacheDir(extPath, 'node', info.resolvedVersion); + toolPath = await tc.cacheDir( + extPath, + 'node', + info.resolvedVersion, + info.arch + ); core.info('Done'); } @@ -364,7 +369,7 @@ async function acquireNodeFromFallbackLocation( throw err; } } - let toolPath = await tc.cacheDir(tempDir, 'node', version); + let toolPath = await tc.cacheDir(tempDir, 'node', version, arch); core.addPath(toolPath); return toolPath; } From 66f3e9f7cee35d1cfc652f5f63777f2ef427029b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 08:49:37 -0500 Subject: [PATCH 13/25] feat: add arch to queryDistForMatch --- src/installer.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index a2c4d6a1..a2fcffa7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -205,7 +205,7 @@ async function getInfoFromDist( let version: string; - version = await queryDistForMatch(versionSpec); + version = await queryDistForMatch(versionSpec, arch); if (!version) { return null; } @@ -273,9 +273,12 @@ function evaluateVersions(versions: string[], versionSpec: string): string { return version; } -async function queryDistForMatch(versionSpec: string): Promise { +async function queryDistForMatch( + versionSpec: string, + arch: string = os.arch() +): Promise { let osPlat: string = os.platform(); - let osArch: string = translateArchToDistUrl(os.arch()); + let osArch: string = translateArchToDistUrl(arch); // node offers a json list of versions let dataFileName: string; From 7a3669aa8ae68a57ad9dfab3ea5293570132ad5a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 08:47:25 -0500 Subject: [PATCH 14/25] test: add arch tests Co-Authored-By: Tyler Ang-Wanek feat: add nock Co-Authored-By: Tyler Ang-Wanek --- .../mock-node-v12.18.3-linux-x64.tar.gz | Bin 0 -> 205 bytes .../mock-node-v12.18.3-linux-x86.tar.gz | Bin 0 -> 205 bytes .../mock-node-v12.18.3-win-x64.7z | Bin 0 -> 210 bytes .../mock-node-v12.18.3-win-x86.7z | Bin 0 -> 209 bytes __tests__/installer.test.ts | 47 ++++++++++++++++++ package-lock.json | 35 +++++++++++++ package.json | 1 + 7 files changed, 83 insertions(+) create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-linux-x86.tar.gz create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-win-x86.7z diff --git a/__tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz b/__tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..50c8dd35e5e4461cd7af5255b6936650b2a27537 GIT binary patch literal 205 zcmV;;05bm{iwFpe{ZL;70B&z&Wi56wGA=PVE;B7`X>N6REqFFGE_7jX0PWJ<3c?^1 z!0~h4Q}_Z~o)2fQvz5?bIA|{R__-jWiw1#s(flDCK`(^Ae!RHqj#T5R=4$Buyi`jg zM@UF((bn2HpFZYmk8Fg+n1%>6q9FlgAcJ`d?G54!_UT*yuJ_6Qzz_Y!%G#gEHl=?K zTm9EFNI;|B?$7k@Z#dp(6b6;0$N6REqFLKE_7jX0PWI23d0}} zK+#$E6kZ_djH5BvNm`+SV4yL@7s#xxJY~mBj`f-y6I}G2g#b+nyYbeOQ=HI zoFO4Zg~pgTU%uvhPplOyts5x;i8Lb!4H+!6@9q#^a7@4Y_k&CJ2ma` H01N;CUO`&6 literal 0 HcmV?d00001 diff --git a/__tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z b/__tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z new file mode 100644 index 0000000000000000000000000000000000000000..f5ecfd4d27762e53124841feb8573bf3c5e414e6 GIT binary patch literal 210 zcmXr7+Ou9=hJodcb&|+L1_)4u(sM7dc{4IdmSkiWD*#bmeu+Y2o59? zaH-Z2-nqJO?rt|d^Tz76?uny4NAef{ewy_`Ue9Z~!_!3W3okpj)SkTZ)c%_5_Kz(Q z&77z2I@n**sJVQu-HYuh+h=h$IY!Q626k>n21aFOMn=|H1_1^Jo`!u~jFuVYbu+1_)4u(%y?dX)`iNmSkiWD*#bmeu+Y2o59? zaH-Z2-nqJO?rt|d^Tz76?uny4NAef{ewz0v=Iz_ZY0_TP%UnZ)O17`P`|-q0zG8O! zvJ8X8bG$fZ){5x+FY-5hC(b6v$XUd|&dtccsLagB$QsKaz`(%Mu#byT?%u^|3=9DO C literal 0 HcmV?d00001 diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index b1e3cb0c..8007952a 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -9,6 +9,7 @@ import * as main from '../src/main'; import * as im from '../src/installer'; import * as auth from '../src/authutil'; import {context} from '@actions/github'; +import nock = require('nock'); let nodeTestManifest = require('./data/versions-manifest.json'); let nodeTestDist = require('./data/node-dist-index.json'); @@ -337,6 +338,52 @@ describe('setup-node', () => { expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); }); + it('Acquires specified x64 or x86 version of node if no matching version is installed', async () => { + const toolDir = path.join( + __dirname, + 'runner', + path.join( + Math.random() + .toString(36) + .substring(7) + ), + 'tools' + ); + + os.platform = process.platform; + const IS_WINDOWS = os.platform === 'win32'; + for (const {arch, version} of [ + {arch: 'x64', version: '12.18.3'}, + {arch: 'x86', version: '12.18.3'} + ]) { + nock.cleanAll(); + const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz'; + const platform = { + linux: 'linux', + darwin: 'darwin', + win32: 'win' + }[process.platform]; + const fileName = `node-v${version}-${platform}-${arch}.${fileExtension}`; + const pathOnNodeJs = `/dist/v${version}/${fileName}`; + const scope = nock('nodejs.org') + .get(pathOnNodeJs) + .replyWithFile( + 200, + path.join(__dirname, '__fixtures__', `mock-${fileName}`) + ); + await im.getNode(version, true, true, undefined, arch); + const nodeDir = path.join(toolDir, 'node', version, arch); + + expect(scope.isDone()).toBe(true); + expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true); + if (IS_WINDOWS) { + expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); + } else { + expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true); + } + } + }, 100000); + describe('check-latest flag', () => { it('use local version and dont check manifest if check-latest is not specified', async () => { os.platform = 'linux'; diff --git a/package-lock.json b/package-lock.json index be7fec2d..4f5279b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6577,6 +6577,35 @@ "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, + "nock": { + "version": "13.0.4", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.0.4.tgz", + "integrity": "sha512-alqTV8Qt7TUbc74x1pKRLSENzfjp4nywovcJgi/1aXDiUxXdt7TkruSTF5MDWPP7UoPVgea4F9ghVdmX0xxnSA==", + "dev": true, + "requires": { + "debug": "^4.1.0", + "json-stringify-safe": "^5.0.1", + "lodash.set": "^4.3.2", + "propagate": "^2.0.0" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -6945,6 +6974,12 @@ "sisteransi": "^1.0.4" } }, + "propagate": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", + "integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==", + "dev": true + }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", diff --git a/package.json b/package.json index 9a3f1c57..c80fa0c7 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^24.9.0", "jest-circus": "^24.7.1", + "nock": "^13.0.4", "prettier": "^1.19.1", "ts-jest": "^24.3.0", "typescript": "^3.8.3" From 922f2f946810f648b0143b9e99b089fec7f43d0b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 12:33:11 -0500 Subject: [PATCH 15/25] test: revert using nock and fixtures --- .../mock-node-v12.18.3-linux-x64.tar.gz | Bin 205 -> 0 bytes .../mock-node-v12.18.3-linux-x86.tar.gz | Bin 205 -> 0 bytes .../mock-node-v12.18.3-win-x64.7z | Bin 210 -> 0 bytes .../mock-node-v12.18.3-win-x86.7z | Bin 209 -> 0 bytes __tests__/installer.test.ts | 1 - package-lock.json | 35 ------------------ package.json | 1 - 7 files changed, 37 deletions(-) delete mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz delete mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-linux-x86.tar.gz delete mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z delete mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-win-x86.7z diff --git a/__tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz b/__tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz deleted file mode 100644 index 50c8dd35e5e4461cd7af5255b6936650b2a27537..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 205 zcmV;;05bm{iwFpe{ZL;70B&z&Wi56wGA=PVE;B7`X>N6REqFFGE_7jX0PWJ<3c?^1 z!0~h4Q}_Z~o)2fQvz5?bIA|{R__-jWiw1#s(flDCK`(^Ae!RHqj#T5R=4$Buyi`jg zM@UF((bn2HpFZYmk8Fg+n1%>6q9FlgAcJ`d?G54!_UT*yuJ_6Qzz_Y!%G#gEHl=?K zTm9EFNI;|B?$7k@Z#dp(6b6;0$N6REqFLKE_7jX0PWI23d0}} zK+#$E6kZ_djH5BvNm`+SV4yL@7s#xxJY~mBj`f-y6I}G2g#b+nyYbeOQ=HI zoFO4Zg~pgTU%uvhPplOyts5x;i8Lb!4H+!6@9q#^a7@4Y_k&CJ2ma` H01N;CUO`&6 diff --git a/__tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z b/__tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z deleted file mode 100644 index f5ecfd4d27762e53124841feb8573bf3c5e414e6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 210 zcmXr7+Ou9=hJodcb&|+L1_)4u(sM7dc{4IdmSkiWD*#bmeu+Y2o59? zaH-Z2-nqJO?rt|d^Tz76?uny4NAef{ewy_`Ue9Z~!_!3W3okpj)SkTZ)c%_5_Kz(Q z&77z2I@n**sJVQu-HYuh+h=h$IY!Q626k>n21aFOMn=|H1_1^Jo`!u~jFuVYbu+1_)4u(%y?dX)`iNmSkiWD*#bmeu+Y2o59? zaH-Z2-nqJO?rt|d^Tz76?uny4NAef{ewz0v=Iz_ZY0_TP%UnZ)O17`P`|-q0zG8O! zvJ8X8bG$fZ){5x+FY-5hC(b6v$XUd|&dtccsLagB$QsKaz`(%Mu#byT?%u^|3=9DO C diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 8007952a..d36fc018 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -9,7 +9,6 @@ import * as main from '../src/main'; import * as im from '../src/installer'; import * as auth from '../src/authutil'; import {context} from '@actions/github'; -import nock = require('nock'); let nodeTestManifest = require('./data/versions-manifest.json'); let nodeTestDist = require('./data/node-dist-index.json'); diff --git a/package-lock.json b/package-lock.json index 4f5279b2..be7fec2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6577,35 +6577,6 @@ "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, - "nock": { - "version": "13.0.4", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.0.4.tgz", - "integrity": "sha512-alqTV8Qt7TUbc74x1pKRLSENzfjp4nywovcJgi/1aXDiUxXdt7TkruSTF5MDWPP7UoPVgea4F9ghVdmX0xxnSA==", - "dev": true, - "requires": { - "debug": "^4.1.0", - "json-stringify-safe": "^5.0.1", - "lodash.set": "^4.3.2", - "propagate": "^2.0.0" - }, - "dependencies": { - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, - "requires": { - "ms": "^2.1.1" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - } - } - }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -6974,12 +6945,6 @@ "sisteransi": "^1.0.4" } }, - "propagate": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", - "integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==", - "dev": true - }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", diff --git a/package.json b/package.json index c80fa0c7..9a3f1c57 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "@zeit/ncc": "^0.21.0", "jest": "^24.9.0", "jest-circus": "^24.7.1", - "nock": "^13.0.4", "prettier": "^1.19.1", "ts-jest": "^24.3.0", "typescript": "^3.8.3" From a83bf5112944474c1472889a4ffc5fe703759a10 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 10:15:28 -0500 Subject: [PATCH 16/25] test: test using main.run and spying --- __tests__/installer.test.ts | 68 +++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index d36fc018..100b444e 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -337,49 +337,43 @@ describe('setup-node', () => { expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); }); - it('Acquires specified x64 or x86 version of node if no matching version is installed', async () => { - const toolDir = path.join( - __dirname, - 'runner', - path.join( - Math.random() - .toString(36) - .substring(7) - ), - 'tools' - ); - - os.platform = process.platform; - const IS_WINDOWS = os.platform === 'win32'; - for (const {arch, version} of [ - {arch: 'x64', version: '12.18.3'}, - {arch: 'x86', version: '12.18.3'} + it('Acquires specified architecture of node', async () => { + for (const {arch, version, osSpec} of [ + {arch: 'x86', version: '12.16.2', osSpec: 'win32'}, + {arch: 'x86', version: '14.0.0', osSpec: 'win32'} ]) { - nock.cleanAll(); - const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz'; + os.platform = osSpec; + os.arch = arch; + const fileExtension = os.platform === 'win32' ? '7z' : 'tar.gz'; const platform = { linux: 'linux', darwin: 'darwin', win32: 'win' - }[process.platform]; - const fileName = `node-v${version}-${platform}-${arch}.${fileExtension}`; - const pathOnNodeJs = `/dist/v${version}/${fileName}`; - const scope = nock('nodejs.org') - .get(pathOnNodeJs) - .replyWithFile( - 200, - path.join(__dirname, '__fixtures__', `mock-${fileName}`) - ); - await im.getNode(version, true, true, undefined, arch); - const nodeDir = path.join(toolDir, 'node', version, arch); + }[os.platform]; - expect(scope.isDone()).toBe(true); - expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true); - if (IS_WINDOWS) { - expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); - } else { - expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true); - } + inputs['node-version'] = version; + inputs['node-arch'] = arch; + inputs['always-auth'] = false; + inputs['token'] = 'faketoken'; + + let expectedUrl = + arch === 'x64' + ? `https://github.com/actions/node-versions/releases/download/${version}/node-${version}-${platform}-${arch}.zip` + : `https://nodejs.org/dist/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; + + // ... but not in the local cache + findSpy.mockImplementation(() => ''); + + dlSpy.mockImplementation(async () => '/some/temp/path'); + let toolPath = path.normalize(`/cache/node/${version}/${arch}`); + exSpy.mockImplementation(async () => '/some/other/temp/path'); + cacheSpy.mockImplementation(async () => toolPath); + + await main.run(); + expect(dlSpy).toHaveBeenCalled(); + expect(logSpy).toHaveBeenCalledWith( + `Acquiring ${version} - ${arch} from ${expectedUrl}` + ); } }, 100000); From 63fffe44114fe96a5a9c2905d46804c7c3c68808 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 13:50:50 -0500 Subject: [PATCH 17/25] chore: add line-ending to gitattribute --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..e305bda1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Set default behavior to automatically normalize line endings, and force everything to be LF, except for Windows batch files that require CRLF, so that if a repo is accessed in Unix via a file share from Windows, the scripts will work. +* text=auto eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf \ No newline at end of file From 0a161fe2f941d460add1e34f9043f3c141065209 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 5 Sep 2020 06:57:59 -0500 Subject: [PATCH 18/25] fix: use arch instead of osArch in INodeVersionInfo --- src/installer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer.ts b/src/installer.ts index a2fcffa7..cc45e224 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -225,7 +225,7 @@ async function getInfoFromDist( return { downloadUrl: url, resolvedVersion: version, - arch: osArch, + arch: arch, fileName: fileName }; } From 2801f51f909b6e0d6b7e101cc223c6c9a9759a38 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 5 Sep 2020 06:59:22 -0500 Subject: [PATCH 19/25] chore: build git clean -ffdx && npm ci && npm run pre-checkin --- dist/index.js | 53 +++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/dist/index.js b/dist/index.js index 481183ea..45da787b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4632,6 +4632,7 @@ const installer = __importStar(__webpack_require__(749)); const auth = __importStar(__webpack_require__(202)); const path = __importStar(__webpack_require__(622)); const url_1 = __webpack_require__(835); +const os = __webpack_require__(87); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -4643,12 +4644,16 @@ function run() { if (!version) { version = core.getInput('version'); } + let arch = core.getInput('node-arch'); + if (!arch) { + arch = os.arch(); + } if (version) { let token = core.getInput('token'); let auth = !token || isGhes() ? undefined : `token ${token}`; let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; - yield installer.getNode(version, stable, checkLatest, auth); + yield installer.getNode(version, stable, checkLatest, auth, arch); } const registryUrl = core.getInput('registry-url'); const alwaysAuth = core.getInput('always-auth'); @@ -12994,13 +12999,13 @@ const tc = __importStar(__webpack_require__(533)); const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(280)); const fs = __webpack_require__(747); -function getNode(versionSpec, stable, checkLatest, auth) { +function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); - let osArch = translateArchToDistUrl(os.arch()); + let osArch = translateArchToDistUrl(arch); if (checkLatest) { core.info('Attempt to resolve the latest version from manifest...'); - const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth); + const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch); if (resolvedVersion) { versionSpec = resolvedVersion; core.info(`Resolved as '${versionSpec}'`); @@ -13011,7 +13016,7 @@ function getNode(versionSpec, stable, checkLatest, auth) { } // check cache let toolPath; - toolPath = tc.find('node', versionSpec); + toolPath = tc.find('node', versionSpec, osArch); // If not found in cache, download if (toolPath) { core.info(`Found in cache @ ${toolPath}`); @@ -13024,9 +13029,9 @@ function getNode(versionSpec, stable, checkLatest, auth) { // Try download from internal distribution (popular versions only) // try { - info = yield getInfoFromManifest(versionSpec, stable, auth); + info = yield getInfoFromManifest(versionSpec, stable, auth, osArch); if (info) { - core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); + core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`); downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth); } else { @@ -13049,17 +13054,17 @@ function getNode(versionSpec, stable, checkLatest, auth) { // Download from nodejs.org // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec); + info = yield getInfoFromDist(versionSpec, arch); if (!info) { throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); } - core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); + core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`); try { downloadPath = yield tc.downloadTool(info.downloadUrl); } catch (err) { if (err instanceof tc.HTTPError && err.httpStatusCode == 404) { - return yield acquireNodeFromFallbackLocation(info.resolvedVersion); + return yield acquireNodeFromFallbackLocation(info.resolvedVersion, info.arch); } throw err; } @@ -13090,7 +13095,7 @@ function getNode(versionSpec, stable, checkLatest, auth) { // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded // core.info('Adding to the cache ...'); - toolPath = yield tc.cacheDir(extPath, 'node', info.resolvedVersion); + toolPath = yield tc.cacheDir(extPath, 'node', info.resolvedVersion, info.arch); core.info('Done'); } // @@ -13107,26 +13112,27 @@ function getNode(versionSpec, stable, checkLatest, auth) { }); } exports.getNode = getNode; -function getInfoFromManifest(versionSpec, stable, auth) { +function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) { return __awaiter(this, void 0, void 0, function* () { let info = null; const releases = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main'); - const rel = yield tc.findFromManifest(versionSpec, stable, releases); + const rel = yield tc.findFromManifest(versionSpec, stable, releases, osArch); if (rel && rel.files.length > 0) { info = {}; info.resolvedVersion = rel.version; + info.arch = rel.files[0].arch; info.downloadUrl = rel.files[0].download_url; info.fileName = rel.files[0].filename; } return info; }); } -function getInfoFromDist(versionSpec) { +function getInfoFromDist(versionSpec, arch = os.arch()) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); - let osArch = translateArchToDistUrl(os.arch()); + let osArch = translateArchToDistUrl(arch); let version; - version = yield queryDistForMatch(versionSpec); + version = yield queryDistForMatch(versionSpec, arch); if (!version) { return null; } @@ -13142,14 +13148,15 @@ function getInfoFromDist(versionSpec) { return { downloadUrl: url, resolvedVersion: version, + arch: arch, fileName: fileName }; }); } -function resolveVersionFromManifest(versionSpec, stable, auth) { +function resolveVersionFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) { return __awaiter(this, void 0, void 0, function* () { try { - const info = yield getInfoFromManifest(versionSpec, stable, auth); + const info = yield getInfoFromManifest(versionSpec, stable, auth, osArch); return info === null || info === void 0 ? void 0 : info.resolvedVersion; } catch (err) { @@ -13184,10 +13191,10 @@ function evaluateVersions(versions, versionSpec) { } return version; } -function queryDistForMatch(versionSpec) { +function queryDistForMatch(versionSpec, arch = os.arch()) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); - let osArch = translateArchToDistUrl(os.arch()); + let osArch = translateArchToDistUrl(arch); // node offers a json list of versions let dataFileName; switch (osPlat) { @@ -13240,10 +13247,10 @@ exports.getVersionsFromDist = getVersionsFromDist; // This method attempts to download and cache the resources from these alternative locations. // Note also that the files are normally zipped but in this case they are just an exe // and lib file in a folder, not zipped. -function acquireNodeFromFallbackLocation(version) { +function acquireNodeFromFallbackLocation(version, arch = os.arch()) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); - let osArch = translateArchToDistUrl(os.arch()); + let osArch = translateArchToDistUrl(arch); // Create temporary folder to download in to const tempDownloadFolder = 'temp_' + Math.floor(Math.random() * 2000000000); const tempDirectory = process.env['RUNNER_TEMP'] || ''; @@ -13274,7 +13281,7 @@ function acquireNodeFromFallbackLocation(version) { throw err; } } - let toolPath = yield tc.cacheDir(tempDir, 'node', version); + let toolPath = yield tc.cacheDir(tempDir, 'node', version, arch); core.addPath(toolPath); return toolPath; }); From 2a5c060ce28fea5df265375fde1fa37b767a310b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 6 Sep 2020 11:09:41 -0500 Subject: [PATCH 20/25] fix: add warning for when arch is supplied but version is missing --- dist/index.js | 5 +++++ src/main.ts | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/dist/index.js b/dist/index.js index 45da787b..ee4c75af 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4645,6 +4645,11 @@ function run() { version = core.getInput('version'); } let arch = core.getInput('node-arch'); + // if node-arch supplied but node-version is not + // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant. + if (arch && !version) { + core.warning('`node-arch` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `node-arch` in combination with `node-version`'); + } if (!arch) { arch = os.arch(); } diff --git a/src/main.ts b/src/main.ts index b1a33dfe..0d3eb77a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,6 +17,15 @@ export async function run() { } let arch = core.getInput('node-arch'); + + // if node-arch supplied but node-version is not + // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant. + if (arch && !version) { + core.warning( + '`node-arch` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `node-arch` in combination with `node-version`' + ); + } + if (!arch) { arch = os.arch(); } From 99d584aa06f947eb56f0dd38ca328bb7e0e9b0ff Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 6 Sep 2020 11:32:03 -0500 Subject: [PATCH 21/25] docs: enhance the readme example to include multiple os, version, and archs --- README.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a63f70c3..0f5de87f 100644 --- a/README.md +++ b/README.md @@ -74,24 +74,38 @@ jobs: - run: npm test ``` -Architecture: -The architecture can be selected using `node-arch`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms). +Operating Systems and Architecture: + +You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners). The architecture can be selected using `node-arch`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms). ```yaml jobs: build: - runs-on: windows-latest + runs-on: ${{ matrix.os }} strategy: matrix: - node: [ '10', '12' ] - arch: ['x86', 'x64'] - name: Node ${{ matrix.node }} on ${{ matrix.arch }} + os: + - ubuntu-latest + - macos-latest + - windows-latest + node_version: + - 10 + - 12 + - 14 + node_arch: + - x64 + # an extra windows-x86 run: + include: + - os: windows-2016 + node_version: 12 + node_arch: x86 + name: Node ${{ matrix.node_version }} - ${{ matrix.node_arch }} on ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node }} - node-arch: ${{ matrix.arch }} + node-version: ${{ matrix.node_version }} + node-arch: ${{ matrix.node_arch }} - run: npm install - run: npm test ``` From 5984462aaa1ebbfd6105de1f5d30f9c6b9b3ba77 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 8 Dec 2020 16:15:38 -0600 Subject: [PATCH 22/25] Rename node-arch to architecture --- README.md | 8 ++++---- __tests__/installer.test.ts | 2 +- action.yml | 2 +- dist/index.js | 6 +++--- src/main.ts | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a2a99c30..7d1bc7b3 100644 --- a/README.md +++ b/README.md @@ -91,21 +91,21 @@ jobs: - 10 - 12 - 14 - node_arch: + architecture: - x64 # an extra windows-x86 run: include: - os: windows-2016 node_version: 12 - node_arch: x86 - name: Node ${{ matrix.node_version }} - ${{ matrix.node_arch }} on ${{ matrix.os }} + architecture: x86 + name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v1 with: node-version: ${{ matrix.node_version }} - node-arch: ${{ matrix.node_arch }} + architecture: ${{ matrix.architecture }} - run: npm install - run: npm test ``` diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 6e39ad86..22ac3d68 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -356,7 +356,7 @@ describe('setup-node', () => { }[os.platform]; inputs['node-version'] = version; - inputs['node-arch'] = arch; + inputs['architecture'] = arch; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; diff --git a/action.yml b/action.yml index 734f651f..4b524c45 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: default: 'false' node-version: description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0' - node-arch: + architecture: description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.' check-latest: description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec' diff --git a/dist/index.js b/dist/index.js index bd722687..4f786414 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4706,11 +4706,11 @@ function run() { if (!version) { version = core.getInput('version'); } - let arch = core.getInput('node-arch'); - // if node-arch supplied but node-version is not + let arch = core.getInput('architecture'); + // if architecture supplied but node-version is not // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant. if (arch && !version) { - core.warning('`node-arch` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `node-arch` in combination with `node-version`'); + core.warning('`architecture` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `architecture` in combination with `node-version`'); } if (!arch) { arch = os.arch(); diff --git a/src/main.ts b/src/main.ts index 0d3eb77a..b0ae3de4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,13 +16,13 @@ export async function run() { version = core.getInput('version'); } - let arch = core.getInput('node-arch'); + let arch = core.getInput('architecture'); - // if node-arch supplied but node-version is not + // if architecture supplied but node-version is not // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant. if (arch && !version) { core.warning( - '`node-arch` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `node-arch` in combination with `node-version`' + '`architecture` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `architecture` in combination with `node-version`' ); } From 2bbfc7698af074e7e964a29681caaf32f753b06b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 8 Dec 2020 16:47:34 -0600 Subject: [PATCH 23/25] Add Architecture only example --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d1bc7b3..911fbbec 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,28 @@ jobs: - run: npm test ``` -Operating Systems and Architecture: +Architecture: + +You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms). + +When using `architecture`, `node-version` must be provided as well. +```yaml +jobs: + build: + runs-on: windows-latest + name: Node sample + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12' + architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default + - run: npm install + - run: npm test +``` + +Multiple Operating Systems and Architectures: -You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners). The architecture can be selected using `node-arch`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms). ```yaml jobs: build: From d6fea3c137a52740107025d7995836b7b4889bbd Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 9 Dec 2020 11:27:02 -0600 Subject: [PATCH 24/25] update message to be more general This considers self-hosted runners --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4f786414..c959e0a7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4710,7 +4710,7 @@ function run() { // if architecture supplied but node-version is not // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant. if (arch && !version) { - core.warning('`architecture` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `architecture` in combination with `node-version`'); + core.warning('`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`'); } if (!arch) { arch = os.arch(); diff --git a/src/main.ts b/src/main.ts index b0ae3de4..34332765 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,7 +22,7 @@ export async function run() { // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant. if (arch && !version) { core.warning( - '`architecture` is provided but `node-version` is missing. This results in using an already installed x64 node which is not probably what you meant. To fix this, provide `architecture` in combination with `node-version`' + '`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`' ); } From 05e7d6cc2329fe14126c109b585e0d7924e3abb1 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 9 Dec 2020 13:28:47 -0600 Subject: [PATCH 25/25] Add e2e arch test --- .github/workflows/versions.yml | 13 +++++++++++++ __tests__/verify-arch.sh | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 __tests__/verify-arch.sh diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 3beb1f71..4727b4c8 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -96,4 +96,17 @@ jobs: node-version: 0.12.18 - name: Verify node run: __tests__/verify-node.sh 0.12.18 SKIP_NPM + shell: bash + + arch: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Setup node 12 x86 from dist + uses: ./ + with: + node-version: '12' + architecture: 'x86' + - name: Verify node + run: __tests__/verify-arch.sh "ia32" shell: bash \ No newline at end of file diff --git a/__tests__/verify-arch.sh b/__tests__/verify-arch.sh new file mode 100644 index 00000000..7d4ebcbb --- /dev/null +++ b/__tests__/verify-arch.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ -n "$1" ]; then + architecture="$(node -e 'console.log(process.arch)')" + if [ -z "$(echo $architecture | grep --fixed-strings $1)" ]; then + echo "Unexpected architecture" + exit 1 + fi +else + echo "Skip testing architecture" +fi \ No newline at end of file