From 25184c4485a7b08d05f0d0a07d714e3611e40d38 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 26 Apr 2022 15:11:03 +0000 Subject: [PATCH 01/16] Update README.md (#475) * Update README.md * Update README.md --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1460e240..4c6ff06e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This action provides the following functionality for GitHub Actions users: - Registering problem matchers for error output - Configuring authentication for GPR or npm -# Usage +## Usage See [action.yml](action.yml) @@ -22,7 +22,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: '14' + node-version: 14 - run: npm install - run: npm test ``` @@ -33,7 +33,7 @@ The action will first check the local cache for a semver match. If unable to fin For information regarding locally cached versions of Node.js on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments). -#### Supported version syntax +### Supported version syntax The `node-version` input supports the following syntax: @@ -49,7 +49,7 @@ The action defaults to search for the dependency file (`package-lock.json` or `y **Note:** The action does not cache `node_modules` -See the examples of using cache for `yarn` / `pnpm` and `cache-dependency-path` input in the [Advanced usage](docs/advanced-usage.md#caching-packages-data) guide. +See the examples of using cache for `yarn`/`pnpm` and `cache-dependency-path` input in the [Advanced usage](docs/advanced-usage.md#caching-packages-data) guide. **Caching npm dependencies:** @@ -58,7 +58,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: '14' + node-version: 14 cache: 'npm' - run: npm install - run: npm test @@ -71,14 +71,14 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: '14' + node-version: 14 cache: 'npm' cache-dependency-path: subdir/package-lock.json - run: npm install - run: npm test ``` -## Matrix Testing: +## Matrix Testing ```yaml jobs: @@ -86,7 +86,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [ '12', '14', '16' ] + node: [ 12, 14, 16 ] name: Node ${{ matrix.node }} sample steps: - uses: actions/checkout@v3 @@ -109,14 +109,14 @@ jobs: 7. [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn) 8. [Using private packages](docs/advanced-usage.md#use-private-packages) -# License +## License The scripts and documentation in this project are released under the [MIT License](LICENSE) -# Contributions +## Contributions -Contributions are welcome! See [Contributor's Guide](docs/contributors.md) +Contributions are welcome! See [Contributor's Guide](docs/contributors.md) ## Code of Conduct -:wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md) +:wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md) From 0bd06765ef0b51db720effb3b27b09a604b36300 Mon Sep 17 00:00:00 2001 From: Matthias Christoph Munder Date: Sun, 1 May 2022 16:59:15 +0200 Subject: [PATCH 02/16] Improve advanced usage docs (#472) --- docs/advanced-usage.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 9f2f5c88..3fed348e 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -82,9 +82,9 @@ steps: steps: - uses: actions/checkout@v3 -- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2 +- uses: pnpm/action-setup@v2 with: - version: 6.10.0 + version: 6.32.9 - uses: actions/setup-node@v3 with: node-version: '14' From b067f78ed37e8b6503efbf8c2b320b7f1e48369a Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Thu, 5 May 2022 16:16:51 +0200 Subject: [PATCH 03/16] Use CI friendly commands in documentation (#326) --- README.md | 12 ++++++--- docs/advanced-usage.md | 58 +++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4c6ff06e..8e8be6ef 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ steps: - uses: actions/setup-node@v3 with: node-version: 14 -- run: npm install +- run: npm ci - run: npm test ``` @@ -41,6 +41,10 @@ major versions: `12`, `14`, `16` more specific versions: `10.15`, `14.2.0`, `16.3.0` nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*` +### Checking in lockfiles + +It's **always** recommended to commit the lockfile of your package manager for security and performance reasons. For more information consult the "Working with lockfiles" section of the [Advanced usage](docs/advanced-usage.md#working-with-lockfiles) guide. + ## Caching global packages data The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional, and caching is turned off by default. @@ -60,7 +64,7 @@ steps: with: node-version: 14 cache: 'npm' -- run: npm install +- run: npm ci - run: npm test ``` @@ -74,7 +78,7 @@ steps: node-version: 14 cache: 'npm' cache-dependency-path: subdir/package-lock.json -- run: npm install +- run: npm ci - run: npm test ``` @@ -94,7 +98,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - - run: npm install + - run: npm ci - run: npm test ``` diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 3fed348e..e49ea6e2 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -1,4 +1,38 @@ -# Advanced usage +## Working with lockfiles + +All supported package managers recommend that you **always** commit the lockfile, although implementations vary doing so generally provides the following benefits: + +- Enables faster installation for CI and production environments, due to being able to skip package resolution. +- Describes a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies. +- Provides a facility for users to "time-travel" to previous states of `node_modules` without having to commit the directory itself. +- Facilitates greater visibility of tree changes through readable source control diffs. + +In order to get the most out of using your lockfile on continuous integration follow the conventions outlined below for your respective package manager. + +### NPM + +Ensure that `package-lock.json` is always committed, use `npm ci` instead of `npm install` when installing packages. + +**See also:** +- [Documentation of `package-lock.json`](https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json) +- [Documentation of `npm ci`](https://docs.npmjs.com/cli/v8/commands/npm-ci) + +### Yarn + +Ensure that `yarn.lock` is always committed, pass `--frozen-lockfile` to `yarn install` when installing packages. + +**See also:** +- [Documentation of `yarn.lock`](https://classic.yarnpkg.com/en/docs/yarn-lock) +- [Documentation of `--frozen-lockfile` option](https://classic.yarnpkg.com/en/docs/cli/install#toc-yarn-install-frozen-lockfile) +- [QA - Should lockfiles be committed to the repoistory?](https://yarnpkg.com/getting-started/qa/#should-lockfiles-be-committed-to-the-repository) + +### PNPM + +Ensure that `pnpm-lock.yaml` is always committed, when on CI pass `--frozen-lockfile` to `pnpm install` when installing packages. + +**See also:** +- [Working with Git - Lockfiles](https://pnpm.io/git#lockfiles) +- [Documentation of `--frozen-lockfile` option](https://pnpm.io/cli/install#--frozen-lockfile) ## Check latest version @@ -15,7 +49,7 @@ steps: with: node-version: '14' check-latest: true -- run: npm install +- run: npm ci - run: npm test ``` @@ -31,7 +65,7 @@ steps: - uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' -- run: npm install +- run: npm ci - run: npm test ``` @@ -51,7 +85,7 @@ jobs: with: node-version: '14' architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default - - run: npm install + - run: npm ci - run: npm test ``` @@ -67,7 +101,7 @@ steps: with: node-version: '14' cache: 'yarn' -- run: yarn install +- run: yarn install --frozen-lockfile - run: yarn test ``` @@ -89,7 +123,7 @@ steps: with: node-version: '14' cache: 'pnpm' -- run: pnpm install +- run: pnpm install --frozen-lockfile - run: pnpm test ``` @@ -102,7 +136,7 @@ steps: node-version: '14' cache: 'npm' cache-dependency-path: '**/package-lock.json' -- run: npm install +- run: npm ci - run: npm test ``` @@ -117,7 +151,7 @@ steps: cache-dependency-path: | server/app/package-lock.json frontend/app/package-lock.json -- run: npm install +- run: npm ci - run: npm test ``` @@ -152,7 +186,7 @@ jobs: with: node-version: ${{ matrix.node_version }} architecture: ${{ matrix.architecture }} - - run: npm install + - run: npm ci - run: npm test ``` @@ -164,7 +198,7 @@ steps: with: node-version: '14.x' registry-url: 'https://registry.npmjs.org' -- run: npm install +- run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -184,7 +218,7 @@ steps: with: node-version: '14.x' registry-url: -- run: yarn install +- run: yarn install --frozen-lockfile - run: yarn publish env: NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }} @@ -206,7 +240,7 @@ steps: registry-url: 'https://registry.npmjs.org' # Skip post-install scripts here, as a malicious # script could steal NODE_AUTH_TOKEN. -- run: npm install --ignore-scripts +- run: npm ci --ignore-scripts env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # `npm rebuild` will run all those post-install scripts for us. From 17f8bd926464a1afa4c6a11669539e9c1ba77048 Mon Sep 17 00:00:00 2001 From: Milos Pantic <101411245+panticmilos@users.noreply.github.com> Date: Thu, 12 May 2022 17:26:02 +0200 Subject: [PATCH 04/16] Expand current syntax to support aliases for latest version (current/latest/node) (#483) --- .github/workflows/versions.yml | 31 +++++++++++++++++++++++++++++++ README.md | 3 +++ __tests__/installer.test.ts | 26 ++++++++++++++++++++++++++ dist/setup/index.js | 6 ++++++ src/installer.ts | 9 +++++++++ 5 files changed, 75 insertions(+) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index d13fe402..3d8067bc 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -139,3 +139,34 @@ jobs: - name: Verify node run: __tests__/verify-arch.sh "ia32" shell: bash + + node-latest-aliases: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node-version: [current, latest, node] + steps: + - name: Get node version + run: | + latestNodeVersion=$(curl https://nodejs.org/dist/index.json | jq -r '. [0].version') + echo "::set-output name=LATEST_NODE_VERSION::$latestNodeVersion" + id: version + shell: bash + - uses: actions/checkout@v3 + - name: Setup Node + uses: ./ + with: + node-version: ${{ matrix.node-version }} + - name: Retrieve version after install + run: | + updatedVersion=$(echo $(node --version)) + echo "::set-output name=NODE_VERSION_UPDATED::$updatedVersion" + id: updatedVersion + shell: bash + - name: Compare versions + if: ${{ steps.version.outputs.LATEST_NODE_VERSION != steps.updatedVersion.outputs.NODE_VERSION_UPDATED}} + run: | + echo "Latest node version failed to download." + exit 1 diff --git a/README.md b/README.md index 8e8be6ef..20e2418d 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ The `node-version` input supports the following syntax: major versions: `12`, `14`, `16` more specific versions: `10.15`, `14.2.0`, `16.3.0` nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*` +latest release: `latest`/`current`/`node` + +**Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist ### Checking in lockfiles diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 19692cf2..bf2b7bf2 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -909,4 +909,30 @@ describe('setup-node', () => { ); }); }); + + describe('latest alias syntax', () => { + it.each(['latest', 'current', 'node'])( + 'download the %s version if alias is provided', + async inputVersion => { + // Arrange + inputs['node-version'] = inputVersion; + + os.platform = 'darwin'; + os.arch = 'x64'; + + findSpy.mockImplementation(() => ''); + getManifestSpy.mockImplementation(() => { + throw new Error('Unable to download manifest'); + }); + + // Act + await main.run(); + + // assert + expect(logSpy).toHaveBeenCalledWith('Unable to download manifest'); + + expect(logSpy).toHaveBeenCalledWith('getting latest node version...'); + } + ); + }); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index d05c5006..ecf99914 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62587,6 +62587,12 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { } let versions = []; let nodeVersions = yield getVersionsFromDist(); + if (versionSpec === 'current' || + versionSpec === 'latest' || + versionSpec === 'node') { + core.info(`getting latest node version...`); + return nodeVersions[0].version; + } nodeVersions.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { diff --git a/src/installer.ts b/src/installer.ts index a9baae0a..5b87d29a 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -373,6 +373,15 @@ async function queryDistForMatch( let versions: string[] = []; let nodeVersions = await getVersionsFromDist(); + if ( + versionSpec === 'current' || + versionSpec === 'latest' || + versionSpec === 'node' + ) { + core.info(`getting latest node version...`); + return nodeVersions[0].version; + } + nodeVersions.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { From 4d62fafc0520a0d3f338c446b2f3034199fcab44 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Wed, 18 May 2022 00:50:05 -0700 Subject: [PATCH 05/16] Add test for node-version * (#491) --- __tests__/installer.test.ts | 66 +++++++++++++------------------------ 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index bf2b7bf2..004362d0 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -135,50 +135,28 @@ describe('setup-node', () => { expect(versions?.length).toBe(23); }); - it('can find 12.16.2 from manifest on osx', async () => { - os.platform = 'darwin'; - os.arch = 'x64'; - let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo( - 'actions', - 'node-versions', - 'mocktoken' - ); - expect(versions).toBeDefined(); - let match = await tc.findFromManifest('12.16.2', true, versions); - expect(match).toBeDefined(); - expect(match?.version).toBe('12.16.2'); - expect((match as any).lts).toBe('Erbium'); - }); - - it('can find 12 from manifest on linux', async () => { - os.platform = 'linux'; - os.arch = 'x64'; - let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo( - 'actions', - 'node-versions', - 'mocktoken' - ); - expect(versions).toBeDefined(); - let match = await tc.findFromManifest('12.16.2', true, versions); - expect(match).toBeDefined(); - expect(match?.version).toBe('12.16.2'); - expect((match as any).lts).toBe('Erbium'); - }); - - it('can find 10 from manifest on windows', async () => { - os.platform = 'win32'; - os.arch = 'x64'; - let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo( - 'actions', - 'node-versions', - 'mocktoken' - ); - expect(versions).toBeDefined(); - let match = await tc.findFromManifest('10', true, versions); - expect(match).toBeDefined(); - expect(match?.version).toBe('10.20.1'); - expect((match as any).lts).toBe('Dubnium'); - }); + it.each([ + ['12.16.2', 'darwin', '12.16.2', 'Erbium'], + ['12', 'linux', '12.16.2', 'Erbium'], + ['10', 'win32', '10.20.1', 'Dubnium'], + ['*', 'linux', '14.0.0', 'Fermium'] + ])( + 'can find %s from manifest on %s', + async (versionSpec, platform, expectedVersion, expectedLts) => { + os.platform = platform; + os.arch = 'x64'; + let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo( + 'actions', + 'node-versions', + 'mocktoken' + ); + expect(versions).toBeDefined(); + let match = await tc.findFromManifest(versionSpec, true, versions); + expect(match).toBeDefined(); + expect(match?.version).toBe(expectedVersion); + expect((match as any).lts).toBe(expectedLts); + } + ); //-------------------------------------------------- // Found in cache tests From 3601f2a33e3de4e7724647d6a5b3f84c345b0d26 Mon Sep 17 00:00:00 2001 From: tooomm Date: Wed, 18 May 2022 09:50:55 +0200 Subject: [PATCH 06/16] improve version syntax presentation (#493) --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 20e2418d..f920ee1e 100644 --- a/README.md +++ b/README.md @@ -35,12 +35,12 @@ For information regarding locally cached versions of Node.js on GitHub hosted ru ### Supported version syntax -The `node-version` input supports the following syntax: +The `node-version` input supports the following values: -major versions: `12`, `14`, `16` -more specific versions: `10.15`, `14.2.0`, `16.3.0` -nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*` -latest release: `latest`/`current`/`node` + - Major versions: `12`, `14`, `16` + - More specific versions: `10.15`, `14.2.0`, `16.3.0` + - NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*` + - Latest release: `latest`/`current`/`node` **Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist From 8c66f89aefe59190295a477c99b61493eb25cd8b Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 16:48:16 +0200 Subject: [PATCH 07/16] improve latest version syntax --- dist/setup/index.js | 10 ++++------ package-lock.json | 2 +- package.json | 2 +- src/installer.ts | 14 +++++--------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ecf99914..23e5d16c 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62362,6 +62362,10 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info(`Failed to resolve version ${versionSpec} from manifest`); } } + if (['current', 'latest', 'node'].includes(versionSpec)) { + versionSpec = yield queryDistForMatch(versionSpec, arch); + core.info(`getting latest node version...`); + } // check cache let toolPath; toolPath = tc.find('node', versionSpec, osArch); @@ -62587,12 +62591,6 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { } let versions = []; let nodeVersions = yield getVersionsFromDist(); - if (versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node') { - core.info(`getting latest node version...`); - return nodeVersions[0].version; - } nodeVersions.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { diff --git a/package-lock.json b/package-lock.json index 87480e4a..dbadde06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "^1.19.1", + "prettier": "1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } diff --git a/package.json b/package.json index 63b36edd..df56518d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "^1.19.1", + "prettier": "1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } diff --git a/src/installer.ts b/src/installer.ts index 5b87d29a..fb35d73f 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -66,6 +66,11 @@ export async function getNode( } } + if (['current', 'latest', 'node'].includes(versionSpec)) { + versionSpec = await queryDistForMatch(versionSpec, arch); + core.info(`getting latest node version...`); + } + // check cache let toolPath: string; toolPath = tc.find('node', versionSpec, osArch); @@ -373,15 +378,6 @@ async function queryDistForMatch( let versions: string[] = []; let nodeVersions = await getVersionsFromDist(); - if ( - versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node' - ) { - core.info(`getting latest node version...`); - return nodeVersions[0].version; - } - nodeVersions.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { From 45e544a71a30e9753c47c60ffa6894206879eca6 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:02:08 +0200 Subject: [PATCH 08/16] fix versionSpec required error --- src/installer.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index fb35d73f..4029b596 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -66,8 +66,8 @@ export async function getNode( } } - if (['current', 'latest', 'node'].includes(versionSpec)) { - versionSpec = await queryDistForMatch(versionSpec, arch); + if(['current', 'latest', 'node'].includes(versionSpec)) { + versionSpec = await queryDistForMatch(versionSpec, arch); core.info(`getting latest node version...`); } @@ -378,6 +378,15 @@ async function queryDistForMatch( let versions: string[] = []; let nodeVersions = await getVersionsFromDist(); + if ( + versionSpec === 'current' || + versionSpec === 'latest' || + versionSpec === 'node' + ) { + core.info(`getting latest node version...`); + return nodeVersions[0].version; + } + nodeVersions.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { From 9a03ebd9cc165b5097a085f36b4bf1479b417142 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:06:51 +0200 Subject: [PATCH 09/16] run build --- dist/setup/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 23e5d16c..6740015e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62591,6 +62591,12 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { } let versions = []; let nodeVersions = yield getVersionsFromDist(); + if (versionSpec === 'current' || + versionSpec === 'latest' || + versionSpec === 'node') { + core.info(`getting latest node version...`); + return nodeVersions[0].version; + } nodeVersions.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { From fd1b409bc3adb8a843e511763a0160bfa08e1aea Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:33:13 +0200 Subject: [PATCH 10/16] unit tests --- __tests__/installer.test.ts | 27 +++++++++++++++++++++++++++ dist/setup/index.js | 12 +++++++----- src/installer.ts | 17 +++++++++-------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 004362d0..f3eb8db9 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -913,4 +913,31 @@ describe('setup-node', () => { } ); }); + + describe('latest alias syntax from cache', () => { + it.each(['latest', 'current', 'node'])( + 'download the %s version if alias is provided', + async inputVersion => { + // Arrange + inputs['node-version'] = inputVersion; + const expectedVersion = nodeTestDist[0]; + + os.platform = 'darwin'; + os.arch = 'x64'; + + const toolPath = path.normalize( + `/cache/node/${expectedVersion.version}/x64` + ); + findSpy.mockReturnValue(toolPath); + + // Act + await main.run(); + + // assert + expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); + + expect(logSpy).toHaveBeenCalledWith('getting latest node version...'); + } + ); + }); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 6740015e..0a513f92 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62339,6 +62339,7 @@ const tc = __importStar(__webpack_require__(533)); const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(280)); const fs = __webpack_require__(747); +const installer = __importStar(__webpack_require__(923)); function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { return __awaiter(this, void 0, void 0, function* () { // Store manifest data to avoid multiple calls @@ -62362,7 +62363,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info(`Failed to resolve version ${versionSpec} from manifest`); } } - if (['current', 'latest', 'node'].includes(versionSpec)) { + if (isLatestSyntax(versionSpec)) { versionSpec = yield queryDistForMatch(versionSpec, arch); core.info(`getting latest node version...`); } @@ -62590,10 +62591,8 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { throw new Error(`Unexpected OS '${osPlat}'`); } let versions = []; - let nodeVersions = yield getVersionsFromDist(); - if (versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node') { + let nodeVersions = yield installer.getVersionsFromDist(); + if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); return nodeVersions[0].version; } @@ -62692,6 +62691,9 @@ function parseNodeVersionFile(contents) { return nodeVersion; } exports.parseNodeVersionFile = parseNodeVersionFile; +function isLatestSyntax(versionSpec) { + return ['current', 'latest', 'node'].includes(versionSpec); +} /***/ }), diff --git a/src/installer.ts b/src/installer.ts index 4029b596..4f7603ae 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,6 +7,7 @@ import * as tc from '@actions/tool-cache'; import * as path from 'path'; import * as semver from 'semver'; import fs = require('fs'); +import * as installer from './installer'; // // Node versions interface @@ -66,8 +67,8 @@ export async function getNode( } } - if(['current', 'latest', 'node'].includes(versionSpec)) { - versionSpec = await queryDistForMatch(versionSpec, arch); + if (isLatestSyntax(versionSpec)) { + versionSpec = await queryDistForMatch(versionSpec, arch); core.info(`getting latest node version...`); } @@ -376,13 +377,9 @@ async function queryDistForMatch( } let versions: string[] = []; - let nodeVersions = await getVersionsFromDist(); + let nodeVersions = await installer.getVersionsFromDist(); - if ( - versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node' - ) { + if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); return nodeVersions[0].version; } @@ -487,3 +484,7 @@ export function parseNodeVersionFile(contents: string): string { } return nodeVersion; } + +function isLatestSyntax(versionSpec): boolean { + return ['current', 'latest', 'node'].includes(versionSpec); +} From 808c8f917fea369038867811c092cb7843514fbb Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:38:21 +0200 Subject: [PATCH 11/16] remove bumping deps --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index dbadde06..87480e4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "1.19.1", + "prettier": "^1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } diff --git a/package.json b/package.json index df56518d..63b36edd 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "1.19.1", + "prettier": "^1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } From 141334fcd1248aba82bae2a0682d9f5a5e06cf84 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 18:21:03 +0200 Subject: [PATCH 12/16] remove unnecessary dist call --- dist/setup/index.js | 11 +++++++---- src/installer.ts | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0a513f92..4adfa5c2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62346,6 +62346,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { let manifest; let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); + let latestVersionResolved = false; if (isLtsAlias(versionSpec)) { core.info('Attempt to resolve LTS alias from manifest...'); // No try-catch since it's not possible to resolve LTS alias without manifest @@ -62365,6 +62366,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { } if (isLatestSyntax(versionSpec)) { versionSpec = yield queryDistForMatch(versionSpec, arch); + latestVersionResolved = true; core.info(`getting latest node version...`); } // check cache @@ -62407,7 +62409,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { // Download from nodejs.org // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec, arch); + info = yield getInfoFromDist(versionSpec, arch, latestVersionResolved); if (!info) { throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); } @@ -62507,12 +62509,13 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo return info; }); } -function getInfoFromDist(versionSpec, arch = os.arch()) { +function getInfoFromDist(versionSpec, arch = os.arch(), latestVersionResolved) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let version; - version = yield queryDistForMatch(versionSpec, arch); + let version = latestVersionResolved + ? versionSpec + : yield queryDistForMatch(versionSpec, arch); if (!version) { return null; } diff --git a/src/installer.ts b/src/installer.ts index 4f7603ae..cfd69458 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -40,6 +40,7 @@ export async function getNode( let manifest: INodeRelease[] | undefined; let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); + let latestVersionResolved: boolean = false; if (isLtsAlias(versionSpec)) { core.info('Attempt to resolve LTS alias from manifest...'); @@ -69,6 +70,7 @@ export async function getNode( if (isLatestSyntax(versionSpec)) { versionSpec = await queryDistForMatch(versionSpec, arch); + latestVersionResolved = true; core.info(`getting latest node version...`); } @@ -125,7 +127,7 @@ export async function getNode( // Download from nodejs.org // if (!downloadPath) { - info = await getInfoFromDist(versionSpec, arch); + info = await getInfoFromDist(versionSpec, arch, latestVersionResolved); if (!info) { throw new Error( `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` @@ -271,14 +273,16 @@ async function getInfoFromManifest( async function getInfoFromDist( versionSpec: string, - arch: string = os.arch() + arch: string = os.arch(), + latestVersionResolved?: boolean ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); - let version: string; + let version: string = latestVersionResolved + ? versionSpec + : await queryDistForMatch(versionSpec, arch); - version = await queryDistForMatch(versionSpec, arch); if (!version) { return null; } From ea3459bb459f783f186dcfc5229793d2c6f40b25 Mon Sep 17 00:00:00 2001 From: _XiaoTian Date: Fri, 20 May 2022 01:32:26 +0800 Subject: [PATCH 13/16] docs: Update advanced-usage.md (#495) * Update advanced-usage.md * Update advanced-usage.md * Update advanced-usage.md * Update docs/advanced-usage.md Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> --- docs/advanced-usage.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index e49ea6e2..36c1ec8b 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -19,12 +19,13 @@ Ensure that `package-lock.json` is always committed, use `npm ci` instead of `np ### Yarn -Ensure that `yarn.lock` is always committed, pass `--frozen-lockfile` to `yarn install` when installing packages. +To ensure that `yarn.lock` is always committed, use `yarn install --immutable` when installing packages. **See also:** - [Documentation of `yarn.lock`](https://classic.yarnpkg.com/en/docs/yarn-lock) - [Documentation of `--frozen-lockfile` option](https://classic.yarnpkg.com/en/docs/cli/install#toc-yarn-install-frozen-lockfile) - [QA - Should lockfiles be committed to the repoistory?](https://yarnpkg.com/getting-started/qa/#should-lockfiles-be-committed-to-the-repository) +- [Documentation of `yarn install`](https://yarnpkg.com/cli/install) ### PNPM @@ -101,7 +102,7 @@ steps: with: node-version: '14' cache: 'yarn' -- run: yarn install --frozen-lockfile +- run: yarn install --frozen-lockfile # optional, --immutable - run: yarn test ``` From b20a2561b99d471cbfe1222b16de377c5ccc78dc Mon Sep 17 00:00:00 2001 From: panticmilos Date: Fri, 20 May 2022 13:45:28 +0200 Subject: [PATCH 14/16] get manifest once --- dist/setup/index.js | 32 ++++++++++++++++---------------- src/installer.ts | 39 +++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4adfa5c2..e8cdb8cc 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62339,20 +62339,24 @@ const tc = __importStar(__webpack_require__(533)); const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(280)); const fs = __webpack_require__(747); -const installer = __importStar(__webpack_require__(923)); function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { return __awaiter(this, void 0, void 0, function* () { // Store manifest data to avoid multiple calls let manifest; + let distManifest; let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let latestVersionResolved = false; if (isLtsAlias(versionSpec)) { core.info('Attempt to resolve LTS alias from manifest...'); // No try-catch since it's not possible to resolve LTS alias without manifest manifest = yield getManifest(auth); versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } + if (isLatestSyntax(versionSpec)) { + distManifest = yield getVersionsFromDist(); + versionSpec = yield queryDistForMatch(versionSpec, arch, distManifest); + core.info(`getting latest node version...`); + } if (checkLatest) { core.info('Attempt to resolve the latest version from manifest...'); const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest); @@ -62364,11 +62368,6 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info(`Failed to resolve version ${versionSpec} from manifest`); } } - if (isLatestSyntax(versionSpec)) { - versionSpec = yield queryDistForMatch(versionSpec, arch); - latestVersionResolved = true; - core.info(`getting latest node version...`); - } // check cache let toolPath; toolPath = tc.find('node', versionSpec, osArch); @@ -62409,7 +62408,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { // Download from nodejs.org // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec, arch, latestVersionResolved); + info = yield getInfoFromDist(versionSpec, arch, distManifest); if (!info) { throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); } @@ -62509,13 +62508,11 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo return info; }); } -function getInfoFromDist(versionSpec, arch = os.arch(), latestVersionResolved) { +function getInfoFromDist(versionSpec, arch = os.arch(), distManifest) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let version = latestVersionResolved - ? versionSpec - : yield queryDistForMatch(versionSpec, arch); + let version = yield queryDistForMatch(versionSpec, arch, distManifest); if (!version) { return null; } @@ -62574,7 +62571,7 @@ function evaluateVersions(versions, versionSpec) { } return version; } -function queryDistForMatch(versionSpec, arch = os.arch()) { +function queryDistForMatch(versionSpec, arch = os.arch(), distManifest) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); @@ -62593,13 +62590,16 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { default: throw new Error(`Unexpected OS '${osPlat}'`); } + if (!distManifest) { + core.debug('No dist manifest cached'); + distManifest = yield getVersionsFromDist(); + } let versions = []; - let nodeVersions = yield installer.getVersionsFromDist(); if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return nodeVersions[0].version; + return distManifest[0].version; } - nodeVersions.forEach((nodeVersion) => { + distManifest.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { versions.push(nodeVersion.version); diff --git a/src/installer.ts b/src/installer.ts index cfd69458..2956226e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -38,9 +38,9 @@ export async function getNode( ) { // Store manifest data to avoid multiple calls let manifest: INodeRelease[] | undefined; + let distManifest: INodeVersion[] | undefined; let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); - let latestVersionResolved: boolean = false; if (isLtsAlias(versionSpec)) { core.info('Attempt to resolve LTS alias from manifest...'); @@ -51,6 +51,12 @@ export async function getNode( versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } + if (isLatestSyntax(versionSpec)) { + distManifest = await getVersionsFromDist(); + versionSpec = await queryDistForMatch(versionSpec, arch, distManifest); + core.info(`getting latest node version...`); + } + if (checkLatest) { core.info('Attempt to resolve the latest version from manifest...'); const resolvedVersion = await resolveVersionFromManifest( @@ -68,12 +74,6 @@ export async function getNode( } } - if (isLatestSyntax(versionSpec)) { - versionSpec = await queryDistForMatch(versionSpec, arch); - latestVersionResolved = true; - core.info(`getting latest node version...`); - } - // check cache let toolPath: string; toolPath = tc.find('node', versionSpec, osArch); @@ -127,7 +127,7 @@ export async function getNode( // Download from nodejs.org // if (!downloadPath) { - info = await getInfoFromDist(versionSpec, arch, latestVersionResolved); + info = await getInfoFromDist(versionSpec, arch, distManifest); if (!info) { throw new Error( `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` @@ -274,14 +274,16 @@ async function getInfoFromManifest( async function getInfoFromDist( versionSpec: string, arch: string = os.arch(), - latestVersionResolved?: boolean + distManifest?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); - let version: string = latestVersionResolved - ? versionSpec - : await queryDistForMatch(versionSpec, arch); + let version: string = await queryDistForMatch( + versionSpec, + arch, + distManifest + ); if (!version) { return null; @@ -359,7 +361,8 @@ function evaluateVersions(versions: string[], versionSpec: string): string { async function queryDistForMatch( versionSpec: string, - arch: string = os.arch() + arch: string = os.arch(), + distManifest?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -380,15 +383,19 @@ async function queryDistForMatch( throw new Error(`Unexpected OS '${osPlat}'`); } + if (!distManifest) { + core.debug('No dist manifest cached'); + distManifest = await getVersionsFromDist(); + } + let versions: string[] = []; - let nodeVersions = await installer.getVersionsFromDist(); if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return nodeVersions[0].version; + return distManifest[0].version; } - nodeVersions.forEach((nodeVersion: INodeVersion) => { + distManifest.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { versions.push(nodeVersion.version); From 7569de03e709e75afc4815ae1688120e2c5bc068 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Fri, 20 May 2022 16:32:52 +0200 Subject: [PATCH 15/16] rename dist manifest to node versions --- dist/setup/index.js | 22 +++++++++++----------- src/installer.ts | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index e8cdb8cc..8a4d83b5 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62343,7 +62343,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { return __awaiter(this, void 0, void 0, function* () { // Store manifest data to avoid multiple calls let manifest; - let distManifest; + let nodeVersions; let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); if (isLtsAlias(versionSpec)) { @@ -62353,8 +62353,8 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } if (isLatestSyntax(versionSpec)) { - distManifest = yield getVersionsFromDist(); - versionSpec = yield queryDistForMatch(versionSpec, arch, distManifest); + nodeVersions = yield getVersionsFromDist(); + versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions); core.info(`getting latest node version...`); } if (checkLatest) { @@ -62408,7 +62408,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { // Download from nodejs.org // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec, arch, distManifest); + info = yield getInfoFromDist(versionSpec, arch, nodeVersions); if (!info) { throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); } @@ -62508,11 +62508,11 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo return info; }); } -function getInfoFromDist(versionSpec, arch = os.arch(), distManifest) { +function getInfoFromDist(versionSpec, arch = os.arch(), nodeVersions) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let version = yield queryDistForMatch(versionSpec, arch, distManifest); + let version = yield queryDistForMatch(versionSpec, arch, nodeVersions); if (!version) { return null; } @@ -62571,7 +62571,7 @@ function evaluateVersions(versions, versionSpec) { } return version; } -function queryDistForMatch(versionSpec, arch = os.arch(), distManifest) { +function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); @@ -62590,16 +62590,16 @@ function queryDistForMatch(versionSpec, arch = os.arch(), distManifest) { default: throw new Error(`Unexpected OS '${osPlat}'`); } - if (!distManifest) { + if (!nodeVersions) { core.debug('No dist manifest cached'); - distManifest = yield getVersionsFromDist(); + nodeVersions = yield getVersionsFromDist(); } let versions = []; if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return distManifest[0].version; + return nodeVersions[0].version; } - distManifest.forEach((nodeVersion) => { + nodeVersions.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { versions.push(nodeVersion.version); diff --git a/src/installer.ts b/src/installer.ts index 2956226e..6e79132d 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -38,7 +38,7 @@ export async function getNode( ) { // Store manifest data to avoid multiple calls let manifest: INodeRelease[] | undefined; - let distManifest: INodeVersion[] | undefined; + let nodeVersions: INodeVersion[] | undefined; let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -52,8 +52,8 @@ export async function getNode( } if (isLatestSyntax(versionSpec)) { - distManifest = await getVersionsFromDist(); - versionSpec = await queryDistForMatch(versionSpec, arch, distManifest); + nodeVersions = await getVersionsFromDist(); + versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions); core.info(`getting latest node version...`); } @@ -127,7 +127,7 @@ export async function getNode( // Download from nodejs.org // if (!downloadPath) { - info = await getInfoFromDist(versionSpec, arch, distManifest); + info = await getInfoFromDist(versionSpec, arch, nodeVersions); if (!info) { throw new Error( `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` @@ -274,7 +274,7 @@ async function getInfoFromManifest( async function getInfoFromDist( versionSpec: string, arch: string = os.arch(), - distManifest?: INodeVersion[] + nodeVersions?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -282,7 +282,7 @@ async function getInfoFromDist( let version: string = await queryDistForMatch( versionSpec, arch, - distManifest + nodeVersions ); if (!version) { @@ -362,7 +362,7 @@ function evaluateVersions(versions: string[], versionSpec: string): string { async function queryDistForMatch( versionSpec: string, arch: string = os.arch(), - distManifest?: INodeVersion[] + nodeVersions?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -383,19 +383,19 @@ async function queryDistForMatch( throw new Error(`Unexpected OS '${osPlat}'`); } - if (!distManifest) { + if (!nodeVersions) { core.debug('No dist manifest cached'); - distManifest = await getVersionsFromDist(); + nodeVersions = await getVersionsFromDist(); } let versions: string[] = []; if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return distManifest[0].version; + return nodeVersions[0].version; } - distManifest.forEach((nodeVersion: INodeVersion) => { + nodeVersions.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { versions.push(nodeVersion.version); From b14573ddb960b7d615cb82f84704679a2ffbdf2c Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 23 May 2022 12:53:31 +0200 Subject: [PATCH 16/16] remove installer import --- src/installer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/installer.ts b/src/installer.ts index 6e79132d..cd4619ea 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,7 +7,6 @@ import * as tc from '@actions/tool-cache'; import * as path from 'path'; import * as semver from 'semver'; import fs = require('fs'); -import * as installer from './installer'; // // Node versions interface