From 84aff3a1f687800dadbd6264ed91c57eb6097a7f Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Mon, 27 Mar 2023 20:24:42 +0200 Subject: [PATCH 01/25] Fix Actions YAML by putting a default false in quotation marks --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b22de1ef6..8ff13c3a6 100644 --- a/action.yml +++ b/action.yml @@ -13,7 +13,7 @@ inputs: 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 + default: 'false' registry-url: description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.' scope: From f84811a75e5d5e15a6340205b00f372c999657f3 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 14:11:55 +0200 Subject: [PATCH 02/25] Add resolve stable --- .github/workflows/versions.yml | 23 +++++++++++ action.yml | 2 + dist/setup/index.js | 56 +++++++++++++++++++++++++- src/distributions/base-distribution.ts | 52 ++++++++++++++++++++++++ src/main.ts | 18 +++++++-- src/util.ts | 2 +- 6 files changed, 147 insertions(+), 6 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index ad5a1ccd5..12951f9b4 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -51,6 +51,29 @@ jobs: __tests__/verify-node.sh "${BASH_REMATCH[1]}" shell: bash + resolve-stable-test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node-version: [15.6, 16.5] + steps: + - uses: actions/checkout@v3 + - name: Setup Node + uses: ./ + with: + node-version: ${{ matrix.node-version }} + check-latest: true + resolve-stable: true + - if: runner.os != 'Windows' + name: Verify node and npm + run: | + . "$NVM_DIR/nvm.sh" + [[ $(nvm version-remote "${{ matrix.node-version }}") =~ ^v([^.]+) ]] + __tests__/verify-node.sh "${BASH_REMATCH[1]}" + shell: bash + v8-canary-syntax: runs-on: ${{ matrix.os }} strategy: diff --git a/action.yml b/action.yml index 8ff13c3a6..c1a17c4ad 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,8 @@ inputs: description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.' architecture: description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.' + resolve-stable: + description: 'Checks if the provided repository is stable and switches it to a stable one if not.' 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' diff --git a/dist/setup/index.js b/dist/setup/index.js index fd6023475..ac10e4b9c 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73417,6 +73417,52 @@ class BaseDistribution { return response.result || []; }); } + stableNodeVersionsList(list) { + const versionsSortedStable = list + .filter(item => semver_1.default.major(item.version) % 2 === 0) + .sort((a, b) => semver_1.default.major(a.version) - semver_1.default.major(b.version)) + .map(item => item.version); + return versionsSortedStable; + } + // Experimental + getTotalLatestNodeVersion() { + return __awaiter(this, void 0, void 0, function* () { + const nodejsVersionObjectList = yield this.getNodeJsVersions(); + const versions = nodejsVersionObjectList.map(item => item.version); + const sortedVersionsDesc = semver_1.default.sort(versions).reverse(); + return sortedVersionsDesc[0]; + }); + } + resolveStableVersionOfNode() { + return __awaiter(this, void 0, void 0, function* () { + const providedNodeVersion = this.nodeInfo.versionSpec; // string + const lowestStableBoundary = '10.24.1'; + const highestStableBoundary = '18.15.0'; // Get through function + const currentHighestVersion = yield this.getTotalLatestNodeVersion(); // TODO: Figure out how to dynamically figure out + if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary) === true) { + core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); + } + if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) === true) { + core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); + } + if (semver_1.default.major(providedNodeVersion) % 2 === 0 || semver_1.default.gte(providedNodeVersion, currentHighestVersion)) { + // if already stable or bigger major than the current latest, get the sorted list of all stable versions and simply select the first one + core.info('Switching to the latest stable major version (v18) ...'); + const versionsDataList = yield this.getNodeJsVersions(); + const versionsList = this.stableNodeVersionsList(versionsDataList); + const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // fix + return highestCurrent; + } + else { + // For unstable versions less than 19 major (current latest) + core.info("Switching to the highest version of the next stable release..."); + const versionsDataList = yield this.getNodeJsVersions(); + const versionsList = this.stableNodeVersionsList(versionsDataList); + const searchedVersion = semver_1.default.maxSatisfying(versionsList, `>${providedNodeVersion}`); // one of the solution ideas I have that removes 'null' type from the equation. + return searchedVersion; + } + }); + } getNodejsDistInfo(version) { const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); version = semver_1.default.clean(version) || ''; @@ -73945,7 +73991,7 @@ function run() { // Version is optional. If supplied, install / use from the tool cache // If not supplied then task is still used to setup proxy, auth, etc... // - const version = resolveVersionInput(); + let version = resolveVersionInput(); // changed const to let as it may change versions later on in an if block let arch = core.getInput('architecture'); const cache = core.getInput('cache'); // if architecture supplied but node-version is not @@ -73959,6 +74005,7 @@ function run() { if (version) { const token = core.getInput('token'); const auth = !token ? undefined : `token ${token}`; + const resolveStable = (core.getInput('resolve-stable')).toUpperCase() === 'TRUE'; const stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; const nodejsInfo = { @@ -73968,7 +74015,12 @@ function run() { stable, arch }; - const nodeDistribution = installer_factory_1.getNodejsDistribution(nodejsInfo); + // My guess is that the change occurs somewhere below, as it touches on BaseDistribution and there we can access methods for fetching node distributions + let nodeDistribution = installer_factory_1.getNodejsDistribution(nodejsInfo); // changed const to let so i can execute the below lines properly (an idea) + if (resolveStable === true) { + version = yield nodeDistribution.resolveStableVersionOfNode(); + nodeDistribution = installer_factory_1.getNodejsDistribution(Object.assign(Object.assign({}, nodejsInfo), { versionSpec: version })); + } yield nodeDistribution.setupNodeJs(); } yield util_1.printEnvDetailsAndSetOutput(); diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index bcfe2fc8e..f79417fcc 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -99,6 +99,58 @@ export default abstract class BaseDistribution { return response.result || []; } + private stableNodeVersionsList(list: INodeVersion[]): string[] { + const versionsSortedStable = list + .filter(item => semver.major(item.version) % 2 === 0) + .sort((a,b) => semver.major(a.version) - semver.major(b.version)) + .map(item => item.version); + return versionsSortedStable; + } + + // Experimental + private async getTotalLatestNodeVersion(): Promise { + const nodejsVersionObjectList = await this.getNodeJsVersions(); + const versions = nodejsVersionObjectList.map(item => item.version); + const sortedVersionsDesc = semver.sort(versions).reverse(); + + return sortedVersionsDesc[0]; + } + + async resolveStableVersionOfNode(): Promise { + const providedNodeVersion = this.nodeInfo.versionSpec; // string + const lowestStableBoundary = '10.24.1'; + const highestStableBoundary = '18.15.0'; // Get through function + const currentHighestVersion = await this.getTotalLatestNodeVersion(); // TODO: Figure out how to dynamically figure out + + if(semver.lt(providedNodeVersion, lowestStableBoundary) === true) { + core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); + } + + if (semver.gt(providedNodeVersion, highestStableBoundary) === true) { + core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); + } + + if (semver.major(providedNodeVersion) % 2 === 0 || semver.gte(providedNodeVersion, currentHighestVersion)) { + // if already stable or bigger major than the current latest, get the sorted list of all stable versions and simply select the first one + core.info('Switching to the latest stable major version (v18) ...'); + const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); + const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); + const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`) as string; // fix + + return highestCurrent; + } + else { + // For unstable versions less than 19 major (current latest) + core.info("Switching to the highest version of the next stable release..."); + const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); + const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); + const searchedVersion = semver.maxSatisfying(versionsList, `>${providedNodeVersion}`) as string; // one of the solution ideas I have that removes 'null' type from the equation. + + return searchedVersion; + } + + } + protected getNodejsDistInfo(version: string) { const osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch); version = semver.clean(version) || ''; diff --git a/src/main.ts b/src/main.ts index 90cd1d9d9..64fc8a5f4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ export async function run() { // Version is optional. If supplied, install / use from the tool cache // If not supplied then task is still used to setup proxy, auth, etc... // - const version = resolveVersionInput(); + let version = resolveVersionInput(); // changed const to let as it may change versions later on in an if block let arch = core.getInput('architecture'); const cache = core.getInput('cache'); @@ -34,10 +34,12 @@ export async function run() { } if (version) { + const token = core.getInput('token'); const auth = !token ? undefined : `token ${token}`; + const resolveStable = (core.getInput('resolve-stable')).toUpperCase() === 'TRUE'; const stable = - (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; + (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; const nodejsInfo = { @@ -47,7 +49,16 @@ export async function run() { stable, arch }; - const nodeDistribution = getNodejsDistribution(nodejsInfo); + + // My guess is that the change occurs somewhere below, as it touches on BaseDistribution and there we can access methods for fetching node distributions + + let nodeDistribution = getNodejsDistribution(nodejsInfo); // changed const to let so i can execute the below lines properly (an idea) + + if (resolveStable === true) { + version = await nodeDistribution.resolveStableVersionOfNode(); + nodeDistribution = getNodejsDistribution({...nodejsInfo, versionSpec: version}) + } + await nodeDistribution.setupNodeJs(); } @@ -77,6 +88,7 @@ export async function run() { } } + function resolveVersionInput(): string { let version = core.getInput('node-version'); const versionFileInput = core.getInput('node-version-file'); diff --git a/src/util.ts b/src/util.ts index 60f2649c2..8efcabc19 100644 --- a/src/util.ts +++ b/src/util.ts @@ -60,4 +60,4 @@ async function getToolVersion(tool: string, options: string[]) { } catch (err) { return ''; } -} +} \ No newline at end of file From 41adda0d029266d3dcaa331e01d0b7c6f065c7a0 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 14:14:30 +0200 Subject: [PATCH 03/25] Add trigger to versions YML --- .github/workflows/versions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 12951f9b4..6f4b60ca2 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -10,6 +10,7 @@ on: - releases/* paths-ignore: - '**.md' + workflow_dispatch: jobs: local-cache: From 9ec595429e9a343e584e4b5a1e18f4cc39e485ae Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 14:20:10 +0200 Subject: [PATCH 04/25] Modify Versions YML --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 6f4b60ca2..b66c6f9f9 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -62,7 +62,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup Node - uses: ./ + uses: dusan-trickovic/setup-node@test/resolve-stable with: node-version: ${{ matrix.node-version }} check-latest: true From 05a5bda0584f00d7976d4b8a5181b899f5f6308b Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 14:23:48 +0200 Subject: [PATCH 05/25] Remove unnecessary workflows --- .github/workflows/basic-validation.yml | 17 -- .github/workflows/check-dist.yml | 17 -- .github/workflows/codeql-analysis.yml | 14 - .github/workflows/e2e-cache.yml | 136 ---------- .github/workflows/licensed.yml | 15 -- .github/workflows/proxy.yml | 52 ---- .../workflows/release-new-action-version.yml | 28 -- .github/workflows/update-config-files.yml | 11 - .github/workflows/versions.yml | 254 +----------------- 9 files changed, 1 insertion(+), 543 deletions(-) delete mode 100644 .github/workflows/basic-validation.yml delete mode 100644 .github/workflows/check-dist.yml delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/e2e-cache.yml delete mode 100644 .github/workflows/licensed.yml delete mode 100644 .github/workflows/proxy.yml delete mode 100644 .github/workflows/release-new-action-version.yml delete mode 100644 .github/workflows/update-config-files.yml diff --git a/.github/workflows/basic-validation.yml b/.github/workflows/basic-validation.yml deleted file mode 100644 index a4b1c0f26..000000000 --- a/.github/workflows/basic-validation.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Basic validation - -on: - pull_request: - paths-ignore: - - '**.md' - push: - branches: - - main - - releases/* - paths-ignore: - - '**.md' - -jobs: - call-basic-validation: - name: Basic validation - uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml deleted file mode 100644 index c95229131..000000000 --- a/.github/workflows/check-dist.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Check dist/ - -on: - push: - branches: - - main - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' - workflow_dispatch: - -jobs: - call-check-dist: - name: Check dist/ - uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 7a8261238..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: CodeQL analysis - -on: - push: - branches: [main] - pull_request: - branches: [main] - schedule: - - cron: '0 3 * * 0' - -jobs: - call-codeQL-analysis: - name: CodeQL analysis - uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml deleted file mode 100644 index fab3dcd74..000000000 --- a/.github/workflows/e2e-cache.yml +++ /dev/null @@ -1,136 +0,0 @@ -name: e2e-cache - -on: - pull_request: - paths-ignore: - - '**.md' - push: - branches: - - main - - releases/* - paths-ignore: - - '**.md' - -jobs: - node-npm-depencies-caching: - name: Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [12, 14, 16] - steps: - - uses: actions/checkout@v3 - - name: Clean global cache - run: npm cache clean --force - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - name: Install dependencies - run: npm install - - name: Verify node and npm - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash - - node-pnpm-depencies-caching: - name: Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [12, 14, 16] - steps: - - uses: actions/checkout@v3 - - name: Install pnpm - uses: pnpm/action-setup@v2 - with: - version: 6.10.0 - - name: Generate pnpm file - run: pnpm install - - name: Remove dependencies - shell: pwsh - run: Remove-Item node_modules -Force -Recurse - - name: Clean global cache - run: rm -rf ~/.pnpm-store - shell: bash - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - cache: 'pnpm' - - name: Install dependencies - run: pnpm install - - name: Verify node and pnpm - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash - - node-yarn1-depencies-caching: - name: Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [14, 16] - steps: - - uses: actions/checkout@v3 - - name: Yarn version - run: yarn --version - - name: Generate yarn file - run: yarn install - - name: Remove dependencies - shell: pwsh - run: Remove-Item node_modules -Force -Recurse - - name: Clean global cache - run: yarn cache clean - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - cache: 'yarn' - - name: Install dependencies - run: yarn install - - name: Verify node and yarn - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash - - node-yarn2-depencies-caching: - name: Test yarn 2 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) - runs-on: ${{ matrix.os }} - env: - YARN_ENABLE_IMMUTABLE_INSTALLS: false - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [12, 14, 16] - steps: - - uses: actions/checkout@v3 - - name: Update yarn - run: yarn set version berry - - name: Yarn version - run: yarn --version - - name: Generate simple .yarnrc.yml - run: | - echo "nodeLinker: node-modules" >> .yarnrc.yml - - name: Generate yarn file - run: yarn install - - name: Remove dependencies - shell: pwsh - run: Remove-Item node_modules -Force -Recurse - - name: Clean global cache - run: yarn cache clean --all - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - cache: 'yarn' - - name: Install dependencies - run: yarn install - - name: Verify node and yarn - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash diff --git a/.github/workflows/licensed.yml b/.github/workflows/licensed.yml deleted file mode 100644 index 37f1560c3..000000000 --- a/.github/workflows/licensed.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Licensed - -on: - push: - branches: - - main - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - call-licensed: - name: Licensed - uses: actions/reusable-workflows/.github/workflows/licensed.yml@main diff --git a/.github/workflows/proxy.yml b/.github/workflows/proxy.yml deleted file mode 100644 index d37d46a71..000000000 --- a/.github/workflows/proxy.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: proxy - -on: - pull_request: - paths-ignore: - - '**.md' - push: - branches: - - main - - releases/* - paths-ignore: - - '**.md' - -jobs: - test-proxy: - runs-on: ubuntu-latest - container: - image: ubuntu:latest - options: --dns 127.0.0.1 - services: - squid-proxy: - image: ubuntu/squid:latest - ports: - - 3128:3128 - env: - https_proxy: http://squid-proxy:3128 - steps: - - uses: actions/checkout@v3 - - name: Clear tool cache - run: rm -rf $RUNNER_TOOL_CACHE/* - - name: Setup node 14 - uses: ./ - with: - node-version: 14.x - - name: Verify node and npm - run: __tests__/verify-node.sh 14 - - test-bypass-proxy: - runs-on: ubuntu-latest - env: - https_proxy: http://no-such-proxy:3128 - no_proxy: api.github.com,github.com,nodejs.org,registry.npmjs.org,*.s3.amazonaws.com,s3.amazonaws.com - steps: - - uses: actions/checkout@v3 - - name: Clear tool cache - run: rm -rf $RUNNER_TOOL_CACHE/* - - name: Setup node 11 - uses: ./ - with: - node-version: 11 - - name: Verify node and npm - run: __tests__/verify-node.sh 11 diff --git a/.github/workflows/release-new-action-version.yml b/.github/workflows/release-new-action-version.yml deleted file mode 100644 index d8171ef88..000000000 --- a/.github/workflows/release-new-action-version.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Release new action version - -on: - release: - types: [released] - workflow_dispatch: - inputs: - TAG_NAME: - description: 'Tag name that the major tag will point to' - required: true - -env: - TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} -permissions: - contents: write - -jobs: - update_tag: - name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes - environment: - name: releaseNewActionVersion - runs-on: ubuntu-latest - steps: - - name: Update the ${{ env.TAG_NAME }} tag - uses: actions/publish-action@v0.2.2 - with: - source-tag: ${{ env.TAG_NAME }} - slack-webhook: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/update-config-files.yml b/.github/workflows/update-config-files.yml deleted file mode 100644 index 87af50042..000000000 --- a/.github/workflows/update-config-files.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Update configuration files - -on: - schedule: - - cron: '0 3 * * 0' - workflow_dispatch: - -jobs: - call-update-configuration-files: - name: Update configuration files - uses: actions/reusable-workflows/.github/workflows/update-config-files.yml@main diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index b66c6f9f9..cbdb23c65 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -13,45 +13,6 @@ on: workflow_dispatch: jobs: - local-cache: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [10, 12, 14] - steps: - - uses: actions/checkout@v3 - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - - name: Verify node and npm - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash - - lts-syntax: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1] - steps: - - uses: actions/checkout@v3 - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - check-latest: true - - if: runner.os != 'Windows' - name: Verify node and npm - run: | - . "$NVM_DIR/nvm.sh" - [[ $(nvm version-remote "${{ matrix.node-version }}") =~ ^v([^.]+) ]] - __tests__/verify-node.sh "${BASH_REMATCH[1]}" - shell: bash - resolve-stable-test: runs-on: ${{ matrix.os }} strategy: @@ -73,217 +34,4 @@ jobs: . "$NVM_DIR/nvm.sh" [[ $(nvm version-remote "${{ matrix.node-version }}") =~ ^v([^.]+) ]] __tests__/verify-node.sh "${BASH_REMATCH[1]}" - shell: bash - - v8-canary-syntax: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: - [ - '20-v8-canary', - '20.0.0-v8-canary', - '20.0.0-v8-canary20221103f7e2421e91' - ] - steps: - - uses: actions/checkout@v3 - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - - name: Verify node and npm - run: | - canaryVersion="${{ matrix.node-version }}" - majorVersion=$(echo $canaryVersion | cut -d- -f1) - __tests__/verify-node.sh "$majorVersion" - shell: bash - - nightly-syntax: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: - [16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly] - steps: - - uses: actions/checkout@v3 - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - - name: Verify node and npm - run: | - nightlyVersion="${{ matrix.node-version }}" - majorVersion=$(echo $nightlyVersion | cut -d- -f1) - __tests__/verify-node.sh "$majorVersion" - shell: bash - - rc-syntax: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [16.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0] - steps: - - uses: actions/checkout@v3 - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - - name: Verify node and npm - run: | - rcVersion="${{ matrix.node-version }}" - majorVersion=$(echo $rcVersion | cut -d- -f1) - __tests__/verify-node.sh "$majorVersion" - shell: bash - - manifest: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [10.15, 12.16.0, 14.2.0, 16.3.0] - steps: - - uses: actions/checkout@v3 - - name: Setup Node - uses: ./ - with: - node-version: ${{ matrix.node-version }} - - name: Verify node and npm - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash - - check-latest: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [10, 12, 14] - steps: - - uses: actions/checkout@v3 - - name: Setup Node and check latest - uses: ./ - with: - node-version: ${{ matrix.node-version }} - check-latest: true - - name: Verify node and npm - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash - - version-file: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version-file: [.nvmrc, .tool-versions, package.json] - steps: - - uses: actions/checkout@v3 - - name: Remove volta from package.json - shell: bash - run: cat <<< "$(jq 'del(.volta)' ./__tests__/data/package.json)" > ./__tests__/data/package.json - - name: Setup node from node version file - uses: ./ - with: - node-version-file: '__tests__/data/${{ matrix.node-version-file }}' - - name: Verify node - run: __tests__/verify-node.sh 14 - - version-file-volta: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - steps: - - uses: actions/checkout@v3 - - name: Setup node from node version file - uses: ./ - with: - node-version-file: '__tests__/data/package.json' - - name: Verify node - run: __tests__/verify-node.sh 16 - - node-dist: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [11, 13] - steps: - - uses: actions/checkout@v3 - - name: Setup Node from dist - uses: ./ - with: - node-version: ${{ matrix.node-version }} - - name: Verify node and npm - run: __tests__/verify-node.sh "${{ matrix.node-version }}" - shell: bash - - old-versions: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - steps: - - uses: actions/checkout@v3 - # test old versions which didn't have npm and layout different - - name: Setup node 0.12.18 from dist - uses: ./ - with: - 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@v3 - - name: Setup node 14 x86 from dist - uses: ./ - with: - node-version: '14' - architecture: 'x86' - - 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 "LATEST_NODE_VERSION=$latestNodeVersion" >> $GITHUB_OUTPUT - 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 "NODE_VERSION_UPDATED=$updatedVersion" >> $GITHUB_OUTPUT - 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 + shell: bash \ No newline at end of file From cdf837e5b2a6ad311d07b7bf2760e070951e04ed Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 14:54:21 +0200 Subject: [PATCH 06/25] Switch versions YML input back to previous --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index cbdb23c65..d3eba0162 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -23,7 +23,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup Node - uses: dusan-trickovic/setup-node@test/resolve-stable + uses: ./ with: node-version: ${{ matrix.node-version }} check-latest: true From 775ea2f6a0715469b3cbdca06a5e45a282573afa Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 14:57:19 +0200 Subject: [PATCH 07/25] Change versions to test --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index d3eba0162..c338d7689 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [15.6, 16.5] + node-version: [15, 16, 16.8.10] steps: - uses: actions/checkout@v3 - name: Setup Node From 0b1ff0d8253c6d551199f75bd2ddaabad18d70fa Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 20:40:39 +0200 Subject: [PATCH 08/25] Refactor code in base distribution --- .github/workflows/versions.yml | 2 +- dist/setup/index.js | 37 +++++++++++++++--------- src/distributions/base-distribution.ts | 40 +++++++++++++++----------- src/main.ts | 9 ++++-- 4 files changed, 55 insertions(+), 33 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index c338d7689..dfa67ceac 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [15, 16, 16.8.10] + node-version: [15.0.0, 16.0.0, 16.8.10] steps: - uses: actions/checkout@v3 - name: Setup Node diff --git a/dist/setup/index.js b/dist/setup/index.js index ac10e4b9c..7e50a667f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73433,19 +73433,10 @@ class BaseDistribution { return sortedVersionsDesc[0]; }); } - resolveStableVersionOfNode() { + determineStableNodeVersion(providedNodeVersion) { return __awaiter(this, void 0, void 0, function* () { - const providedNodeVersion = this.nodeInfo.versionSpec; // string - const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = '18.15.0'; // Get through function - const currentHighestVersion = yield this.getTotalLatestNodeVersion(); // TODO: Figure out how to dynamically figure out - if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary) === true) { - core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); - } - if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) === true) { - core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); - } - if (semver_1.default.major(providedNodeVersion) % 2 === 0 || semver_1.default.gte(providedNodeVersion, currentHighestVersion)) { + const currentHighestTotalVersion = yield this.getTotalLatestNodeVersion(); + if (semver_1.default.major(providedNodeVersion) % 2 === 0 || semver_1.default.gte(providedNodeVersion, currentHighestTotalVersion)) { // if already stable or bigger major than the current latest, get the sorted list of all stable versions and simply select the first one core.info('Switching to the latest stable major version (v18) ...'); const versionsDataList = yield this.getNodeJsVersions(); @@ -73463,6 +73454,21 @@ class BaseDistribution { } }); } + resolveStableVersionOfNode() { + return __awaiter(this, void 0, void 0, function* () { + const providedNodeVersion = this.nodeInfo.versionSpec; // string + const lowestStableBoundary = '10.24.1'; + const highestStableBoundary = '18.15.0'; // Get through function + if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary) === true) { + core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); + } + if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) === true) { + core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); + } + const version = yield this.determineStableNodeVersion(providedNodeVersion); + return version; + }); + } getNodejsDistInfo(version) { const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); version = semver_1.default.clean(version) || ''; @@ -74019,7 +74025,12 @@ function run() { let nodeDistribution = installer_factory_1.getNodejsDistribution(nodejsInfo); // changed const to let so i can execute the below lines properly (an idea) if (resolveStable === true) { version = yield nodeDistribution.resolveStableVersionOfNode(); - nodeDistribution = installer_factory_1.getNodejsDistribution(Object.assign(Object.assign({}, nodejsInfo), { versionSpec: version })); + if (version) { + nodeDistribution = installer_factory_1.getNodejsDistribution(Object.assign(Object.assign({}, nodejsInfo), { versionSpec: version })); + } + else { + core.setFailed('The returned version value is null.'); + } } yield nodeDistribution.setupNodeJs(); } diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index f79417fcc..8cd968702 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -116,26 +116,14 @@ export default abstract class BaseDistribution { return sortedVersionsDesc[0]; } - async resolveStableVersionOfNode(): Promise { - const providedNodeVersion = this.nodeInfo.versionSpec; // string - const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = '18.15.0'; // Get through function - const currentHighestVersion = await this.getTotalLatestNodeVersion(); // TODO: Figure out how to dynamically figure out - - if(semver.lt(providedNodeVersion, lowestStableBoundary) === true) { - core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); - } - - if (semver.gt(providedNodeVersion, highestStableBoundary) === true) { - core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); - } - - if (semver.major(providedNodeVersion) % 2 === 0 || semver.gte(providedNodeVersion, currentHighestVersion)) { + private async determineStableNodeVersion(providedNodeVersion: string): Promise { + const currentHighestTotalVersion = await this.getTotalLatestNodeVersion(); + if (semver.major(providedNodeVersion) % 2 === 0 || semver.gte(providedNodeVersion, currentHighestTotalVersion)) { // if already stable or bigger major than the current latest, get the sorted list of all stable versions and simply select the first one core.info('Switching to the latest stable major version (v18) ...'); const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); - const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`) as string; // fix + const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // fix return highestCurrent; } @@ -144,10 +132,28 @@ export default abstract class BaseDistribution { core.info("Switching to the highest version of the next stable release..."); const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); - const searchedVersion = semver.maxSatisfying(versionsList, `>${providedNodeVersion}`) as string; // one of the solution ideas I have that removes 'null' type from the equation. + const searchedVersion = semver.maxSatisfying(versionsList, `>${providedNodeVersion}`); // one of the solution ideas I have that removes 'null' type from the equation. return searchedVersion; } + } + + async resolveStableVersionOfNode(): Promise { + const providedNodeVersion = this.nodeInfo.versionSpec; // string + const lowestStableBoundary = '10.24.1'; + const highestStableBoundary = '18.15.0'; // Get through function + + if(semver.lt(providedNodeVersion, lowestStableBoundary) === true) { + core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); + } + + if (semver.gt(providedNodeVersion, highestStableBoundary) === true) { + core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); + } + + const version = await this.determineStableNodeVersion(providedNodeVersion); + + return version; } diff --git a/src/main.ts b/src/main.ts index 64fc8a5f4..f3e4902e8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ export async function run() { // Version is optional. If supplied, install / use from the tool cache // If not supplied then task is still used to setup proxy, auth, etc... // - let version = resolveVersionInput(); // changed const to let as it may change versions later on in an if block + let version: string | null = resolveVersionInput(); // changed const to let as it may change versions later on in an if block let arch = core.getInput('architecture'); const cache = core.getInput('cache'); @@ -56,7 +56,12 @@ export async function run() { if (resolveStable === true) { version = await nodeDistribution.resolveStableVersionOfNode(); - nodeDistribution = getNodejsDistribution({...nodejsInfo, versionSpec: version}) + if (version) { + nodeDistribution = getNodejsDistribution({...nodejsInfo, versionSpec: version}) + } + else { + core.setFailed('The returned version value is null.'); + } } await nodeDistribution.setupNodeJs(); From 14ea024055f908a8e90f84b62eac54b5635645e8 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 21:19:28 +0200 Subject: [PATCH 09/25] Refactor the resolve-stable method in base distribution and add new values to test --- .github/workflows/versions.yml | 2 +- dist/setup/index.js | 23 +++++++++-------------- src/distributions/base-distribution.ts | 20 ++++++++------------ src/main.ts | 6 +++--- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index dfa67ceac..445b6664c 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [15.0.0, 16.0.0, 16.8.10] + node-version: [15.0.0, 16.0.0, 16.8.10, 17.9.3, 20.0.2] steps: - uses: actions/checkout@v3 - name: Setup Node diff --git a/dist/setup/index.js b/dist/setup/index.js index 7e50a667f..3ad2d24d4 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73436,29 +73436,24 @@ class BaseDistribution { determineStableNodeVersion(providedNodeVersion) { return __awaiter(this, void 0, void 0, function* () { const currentHighestTotalVersion = yield this.getTotalLatestNodeVersion(); + const versionsDataList = yield this.getNodeJsVersions(); + const versionsList = this.stableNodeVersionsList(versionsDataList); if (semver_1.default.major(providedNodeVersion) % 2 === 0 || semver_1.default.gte(providedNodeVersion, currentHighestTotalVersion)) { - // if already stable or bigger major than the current latest, get the sorted list of all stable versions and simply select the first one core.info('Switching to the latest stable major version (v18) ...'); - const versionsDataList = yield this.getNodeJsVersions(); - const versionsList = this.stableNodeVersionsList(versionsDataList); - const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // fix + const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range return highestCurrent; } else { - // For unstable versions less than 19 major (current latest) core.info("Switching to the highest version of the next stable release..."); - const versionsDataList = yield this.getNodeJsVersions(); - const versionsList = this.stableNodeVersionsList(versionsDataList); - const searchedVersion = semver_1.default.maxSatisfying(versionsList, `>${providedNodeVersion}`); // one of the solution ideas I have that removes 'null' type from the equation. + const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${providedNodeVersion + 1}.x.x`); // TODO: Inspect the range return searchedVersion; } }); } - resolveStableVersionOfNode() { + resolveStableVersionOfNode(providedNodeVersion) { return __awaiter(this, void 0, void 0, function* () { - const providedNodeVersion = this.nodeInfo.versionSpec; // string const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = '18.15.0'; // Get through function + const highestStableBoundary = '18.15.0'; // TODO: Get through function if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary) === true) { core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); } @@ -74024,9 +74019,9 @@ function run() { // My guess is that the change occurs somewhere below, as it touches on BaseDistribution and there we can access methods for fetching node distributions let nodeDistribution = installer_factory_1.getNodejsDistribution(nodejsInfo); // changed const to let so i can execute the below lines properly (an idea) if (resolveStable === true) { - version = yield nodeDistribution.resolveStableVersionOfNode(); - if (version) { - nodeDistribution = installer_factory_1.getNodejsDistribution(Object.assign(Object.assign({}, nodejsInfo), { versionSpec: version })); + const updatedVersion = yield nodeDistribution.resolveStableVersionOfNode(version); + if (updatedVersion !== null) { + nodeDistribution = installer_factory_1.getNodejsDistribution(Object.assign(Object.assign({}, nodejsInfo), { versionSpec: updatedVersion })); } else { core.setFailed('The returned version value is null.'); diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 8cd968702..ab4bb1480 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -118,30 +118,26 @@ export default abstract class BaseDistribution { private async determineStableNodeVersion(providedNodeVersion: string): Promise { const currentHighestTotalVersion = await this.getTotalLatestNodeVersion(); + const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); + const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); + if (semver.major(providedNodeVersion) % 2 === 0 || semver.gte(providedNodeVersion, currentHighestTotalVersion)) { - // if already stable or bigger major than the current latest, get the sorted list of all stable versions and simply select the first one - core.info('Switching to the latest stable major version (v18) ...'); - const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); - const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); - const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // fix + core.info('Switching to the latest stable major version (v18) ...'); + const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range return highestCurrent; } else { - // For unstable versions less than 19 major (current latest) core.info("Switching to the highest version of the next stable release..."); - const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); - const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); - const searchedVersion = semver.maxSatisfying(versionsList, `>${providedNodeVersion}`); // one of the solution ideas I have that removes 'null' type from the equation. + const searchedVersion = semver.maxSatisfying(versionsList, `^${providedNodeVersion+1}.x.x`); // TODO: Inspect the range return searchedVersion; } } - async resolveStableVersionOfNode(): Promise { - const providedNodeVersion = this.nodeInfo.versionSpec; // string + async resolveStableVersionOfNode(providedNodeVersion: string): Promise { const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = '18.15.0'; // Get through function + const highestStableBoundary = '18.15.0'; // TODO: Get through function if(semver.lt(providedNodeVersion, lowestStableBoundary) === true) { core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); diff --git a/src/main.ts b/src/main.ts index f3e4902e8..20db3ea97 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,9 +55,9 @@ export async function run() { let nodeDistribution = getNodejsDistribution(nodejsInfo); // changed const to let so i can execute the below lines properly (an idea) if (resolveStable === true) { - version = await nodeDistribution.resolveStableVersionOfNode(); - if (version) { - nodeDistribution = getNodejsDistribution({...nodejsInfo, versionSpec: version}) + const updatedVersion = await nodeDistribution.resolveStableVersionOfNode(version); + if (updatedVersion !== null) { + nodeDistribution = getNodejsDistribution({...nodejsInfo, versionSpec: updatedVersion}) } else { core.setFailed('The returned version value is null.'); From 91fc74b26d24df1e8b31e98ed73fd4bf6878b043 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 21:30:12 +0200 Subject: [PATCH 10/25] Fix semver ranges in the resolve-stable method --- dist/setup/index.js | 10 +++++----- src/distributions/base-distribution.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 3ad2d24d4..1880283ac 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73435,25 +73435,25 @@ class BaseDistribution { } determineStableNodeVersion(providedNodeVersion) { return __awaiter(this, void 0, void 0, function* () { - const currentHighestTotalVersion = yield this.getTotalLatestNodeVersion(); const versionsDataList = yield this.getNodeJsVersions(); const versionsList = this.stableNodeVersionsList(versionsDataList); - if (semver_1.default.major(providedNodeVersion) % 2 === 0 || semver_1.default.gte(providedNodeVersion, currentHighestTotalVersion)) { - core.info('Switching to the latest stable major version (v18) ...'); + if (semver_1.default.major(providedNodeVersion) % 2 === 0) { + core.info(`Switching to the latest stable major version... (${versionsList[0]})`); const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range return highestCurrent; } else { core.info("Switching to the highest version of the next stable release..."); - const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${providedNodeVersion + 1}.x.x`); // TODO: Inspect the range + const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion) + 1}.x.x`); // TODO: Inspect the range return searchedVersion; } }); } resolveStableVersionOfNode(providedNodeVersion) { return __awaiter(this, void 0, void 0, function* () { + const versionsDataList = yield this.getNodeJsVersions(); const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = '18.15.0'; // TODO: Get through function + const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0]; // TODO: Get through function if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary) === true) { core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); } diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index ab4bb1480..2ebea09ca 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -117,27 +117,27 @@ export default abstract class BaseDistribution { } private async determineStableNodeVersion(providedNodeVersion: string): Promise { - const currentHighestTotalVersion = await this.getTotalLatestNodeVersion(); const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); - if (semver.major(providedNodeVersion) % 2 === 0 || semver.gte(providedNodeVersion, currentHighestTotalVersion)) { - core.info('Switching to the latest stable major version (v18) ...'); + if (semver.major(providedNodeVersion) % 2 === 0) { + core.info(`Switching to the latest stable major version... (${versionsList[0]})`); const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range return highestCurrent; } else { core.info("Switching to the highest version of the next stable release..."); - const searchedVersion = semver.maxSatisfying(versionsList, `^${providedNodeVersion+1}.x.x`); // TODO: Inspect the range + const searchedVersion = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)+1}.x.x`); // TODO: Inspect the range return searchedVersion; } } async resolveStableVersionOfNode(providedNodeVersion: string): Promise { + const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = '18.15.0'; // TODO: Get through function + const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0] // TODO: Get through function if(semver.lt(providedNodeVersion, lowestStableBoundary) === true) { core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); From bb4d48a572f0443759aaa865e03faaa01d58f7c5 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 21:35:22 +0200 Subject: [PATCH 11/25] Fix the bug with highest Node verison check --- dist/setup/index.js | 6 +++--- src/distributions/base-distribution.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 1880283ac..4e977fa5b 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73418,11 +73418,11 @@ class BaseDistribution { }); } stableNodeVersionsList(list) { - const versionsSortedStable = list + const stableVersions = list .filter(item => semver_1.default.major(item.version) % 2 === 0) - .sort((a, b) => semver_1.default.major(a.version) - semver_1.default.major(b.version)) .map(item => item.version); - return versionsSortedStable; + const versionsSorted = semver_1.default.sort(stableVersions).reverse(); + return versionsSorted; } // Experimental getTotalLatestNodeVersion() { diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 2ebea09ca..021f716f9 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -100,11 +100,11 @@ export default abstract class BaseDistribution { } private stableNodeVersionsList(list: INodeVersion[]): string[] { - const versionsSortedStable = list + const stableVersions = list .filter(item => semver.major(item.version) % 2 === 0) - .sort((a,b) => semver.major(a.version) - semver.major(b.version)) .map(item => item.version); - return versionsSortedStable; + const versionsSorted = semver.sort(stableVersions).reverse(); + return versionsSorted; } // Experimental From c47055f439a5cf1a5f42a5fecc768ae046fc9d13 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 30 Mar 2023 21:44:51 +0200 Subject: [PATCH 12/25] Add throw new error to the resolve-stable methods --- dist/setup/index.js | 11 ++++++++--- src/distributions/base-distribution.ts | 12 +++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4e977fa5b..d90bfbdac 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73438,8 +73438,8 @@ class BaseDistribution { const versionsDataList = yield this.getNodeJsVersions(); const versionsList = this.stableNodeVersionsList(versionsDataList); if (semver_1.default.major(providedNodeVersion) % 2 === 0) { - core.info(`Switching to the latest stable major version... (${versionsList[0]})`); const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range + core.info(`Switching to the latest stable major version... (${highestCurrent})`); return highestCurrent; } else { @@ -73454,11 +73454,16 @@ class BaseDistribution { const versionsDataList = yield this.getNodeJsVersions(); const lowestStableBoundary = '10.24.1'; const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0]; // TODO: Get through function + let errorMessage; if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary) === true) { - core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); + errorMessage = `node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`; + core.setFailed(errorMessage); + throw new Error(errorMessage); } if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) === true) { - core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); + errorMessage = `node-version specified is higher than the highest supported major version (${highestStableBoundary}).`; + core.setFailed(errorMessage); + throw new Error(errorMessage); } const version = yield this.determineStableNodeVersion(providedNodeVersion); return version; diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 021f716f9..24aa441b0 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -121,8 +121,8 @@ export default abstract class BaseDistribution { const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); if (semver.major(providedNodeVersion) % 2 === 0) { - core.info(`Switching to the latest stable major version... (${versionsList[0]})`); const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range + core.info(`Switching to the latest stable major version... (${highestCurrent})`); return highestCurrent; } @@ -138,13 +138,19 @@ export default abstract class BaseDistribution { const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const lowestStableBoundary = '10.24.1'; const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0] // TODO: Get through function + let errorMessage: string; if(semver.lt(providedNodeVersion, lowestStableBoundary) === true) { - core.setFailed(`node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`); + errorMessage = `node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`; + + core.setFailed(errorMessage); + throw new Error(errorMessage); } if (semver.gt(providedNodeVersion, highestStableBoundary) === true) { - core.setFailed(`node-version specified is higher than the highest supported major version (${highestStableBoundary}).`); + errorMessage = `node-version specified is higher than the highest supported major version (${highestStableBoundary}).`; + core.setFailed(errorMessage); + throw new Error(errorMessage); } const version = await this.determineStableNodeVersion(providedNodeVersion); From 65dd878e0369de08c2c02cb58def6eac97d64279 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Fri, 31 Mar 2023 07:33:11 +0200 Subject: [PATCH 13/25] Configure edge cases --- dist/setup/index.js | 11 ++++++----- src/distributions/base-distribution.ts | 12 +++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index d90bfbdac..d605bb1f8 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73453,15 +73453,16 @@ class BaseDistribution { return __awaiter(this, void 0, void 0, function* () { const versionsDataList = yield this.getNodeJsVersions(); const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0]; // TODO: Get through function + const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0]; + const highestTotalNodeVersion = yield this.getTotalLatestNodeVersion(); let errorMessage; - if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary) === true) { - errorMessage = `node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`; + if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary)) { + errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; core.setFailed(errorMessage); throw new Error(errorMessage); } - if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) === true) { - errorMessage = `node-version specified is higher than the highest supported major version (${highestStableBoundary}).`; + if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) || semver_1.default.gt(providedNodeVersion, highestTotalNodeVersion)) { + errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; core.setFailed(errorMessage); throw new Error(errorMessage); } diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 24aa441b0..e6e765458 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -137,18 +137,20 @@ export default abstract class BaseDistribution { async resolveStableVersionOfNode(providedNodeVersion: string): Promise { const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const lowestStableBoundary = '10.24.1'; - const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0] // TODO: Get through function + const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0]; + const highestTotalNodeVersion = await this.getTotalLatestNodeVersion(); let errorMessage: string; - if(semver.lt(providedNodeVersion, lowestStableBoundary) === true) { - errorMessage = `node-version specified is lower than the lowest supported major version (${lowestStableBoundary}).`; + if(semver.lt(providedNodeVersion, lowestStableBoundary)) { + errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; core.setFailed(errorMessage); throw new Error(errorMessage); } - if (semver.gt(providedNodeVersion, highestStableBoundary) === true) { - errorMessage = `node-version specified is higher than the highest supported major version (${highestStableBoundary}).`; + if (semver.gt(providedNodeVersion, highestStableBoundary) || semver.gt(providedNodeVersion, highestTotalNodeVersion)) { + errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; + core.setFailed(errorMessage); throw new Error(errorMessage); } From c4d1b0856d87e0732efe89883c952efb54f3d046 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Fri, 31 Mar 2023 10:11:16 +0200 Subject: [PATCH 14/25] Refactor edge case checking --- .github/workflows/versions.yml | 2 +- dist/setup/index.js | 6 ++---- src/distributions/base-distribution.ts | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 445b6664c..2512577fd 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [15.0.0, 16.0.0, 16.8.10, 17.9.3, 20.0.2] + node-version: [15.0.0, 16.0.0, 16.8.10, 17.9.3, 20.0.2, 18.15.0] steps: - uses: actions/checkout@v3 - name: Setup Node diff --git a/dist/setup/index.js b/dist/setup/index.js index d605bb1f8..8b68fb8bb 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73443,8 +73443,8 @@ class BaseDistribution { return highestCurrent; } else { - core.info("Switching to the highest version of the next stable release..."); const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion) + 1}.x.x`); // TODO: Inspect the range + core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); return searchedVersion; } }); @@ -73459,12 +73459,10 @@ class BaseDistribution { if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary)) { errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; core.setFailed(errorMessage); - throw new Error(errorMessage); } - if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) || semver_1.default.gt(providedNodeVersion, highestTotalNodeVersion)) { + if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) || semver_1.default.gte(providedNodeVersion, highestTotalNodeVersion)) { errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; core.setFailed(errorMessage); - throw new Error(errorMessage); } const version = yield this.determineStableNodeVersion(providedNodeVersion); return version; diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index e6e765458..6c693329f 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -127,8 +127,8 @@ export default abstract class BaseDistribution { return highestCurrent; } else { - core.info("Switching to the highest version of the next stable release..."); const searchedVersion = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)+1}.x.x`); // TODO: Inspect the range + core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); return searchedVersion; } @@ -145,14 +145,12 @@ export default abstract class BaseDistribution { errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; core.setFailed(errorMessage); - throw new Error(errorMessage); } - if (semver.gt(providedNodeVersion, highestStableBoundary) || semver.gt(providedNodeVersion, highestTotalNodeVersion)) { + if (semver.gt(providedNodeVersion, highestStableBoundary) || semver.gte(providedNodeVersion, highestTotalNodeVersion)) { errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; core.setFailed(errorMessage); - throw new Error(errorMessage); } const version = await this.determineStableNodeVersion(providedNodeVersion); From 9d6c416d9cf3d01b4e5edce24c56b97651cac93c Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Fri, 31 Mar 2023 15:05:39 +0200 Subject: [PATCH 15/25] Test out a different range option for semver --- dist/setup/index.js | 4 ++-- src/distributions/base-distribution.ts | 2 +- src/main.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 8b68fb8bb..93d4893be 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73438,7 +73438,7 @@ class BaseDistribution { const versionsDataList = yield this.getNodeJsVersions(); const versionsList = this.stableNodeVersionsList(versionsDataList); if (semver_1.default.major(providedNodeVersion) % 2 === 0) { - const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range + const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${providedNodeVersion}`); // TODO: Inspect the range core.info(`Switching to the latest stable major version... (${highestCurrent})`); return highestCurrent; } @@ -73996,7 +73996,7 @@ function run() { // Version is optional. If supplied, install / use from the tool cache // If not supplied then task is still used to setup proxy, auth, etc... // - let version = resolveVersionInput(); // changed const to let as it may change versions later on in an if block + const version = resolveVersionInput(); // changed const to let as it may change versions later on in an if block let arch = core.getInput('architecture'); const cache = core.getInput('cache'); // if architecture supplied but node-version is not diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 6c693329f..b3135d6fb 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -121,7 +121,7 @@ export default abstract class BaseDistribution { const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); if (semver.major(providedNodeVersion) % 2 === 0) { - const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range + const highestCurrent = semver.maxSatisfying(versionsList, `^${providedNodeVersion}`); // TODO: Inspect the range core.info(`Switching to the latest stable major version... (${highestCurrent})`); return highestCurrent; diff --git a/src/main.ts b/src/main.ts index 20db3ea97..7e338b1a1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ export async function run() { // Version is optional. If supplied, install / use from the tool cache // If not supplied then task is still used to setup proxy, auth, etc... // - let version: string | null = resolveVersionInput(); // changed const to let as it may change versions later on in an if block + const version: string = resolveVersionInput(); // changed const to let as it may change versions later on in an if block let arch = core.getInput('architecture'); const cache = core.getInput('cache'); From 357a90eed03cfa767efd3e681be700250c78d02b Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Fri, 31 Mar 2023 17:44:53 +0200 Subject: [PATCH 16/25] Modify versions to test --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 2512577fd..28e7ef4e1 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [15.0.0, 16.0.0, 16.8.10, 17.9.3, 20.0.2, 18.15.0] + node-version: [15.0.0, 16.0.0, 16.8.1, 17.9.1, 20.0.2, 18.15.0] steps: - uses: actions/checkout@v3 - name: Setup Node From 33cef6e7dbda23a253f2e1d73e0401317051565d Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Fri, 31 Mar 2023 17:54:15 +0200 Subject: [PATCH 17/25] Wrap stable-node helper method in try/catch --- dist/setup/index.js | 29 +++++++++++++++----------- src/distributions/base-distribution.ts | 5 +++++ src/main.ts | 4 +--- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 93d4893be..23de3d0c4 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73435,17 +73435,23 @@ class BaseDistribution { } determineStableNodeVersion(providedNodeVersion) { return __awaiter(this, void 0, void 0, function* () { - const versionsDataList = yield this.getNodeJsVersions(); - const versionsList = this.stableNodeVersionsList(versionsDataList); - if (semver_1.default.major(providedNodeVersion) % 2 === 0) { - const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${providedNodeVersion}`); // TODO: Inspect the range - core.info(`Switching to the latest stable major version... (${highestCurrent})`); - return highestCurrent; + try { + const versionsDataList = yield this.getNodeJsVersions(); + const versionsList = this.stableNodeVersionsList(versionsDataList); + if (semver_1.default.major(providedNodeVersion) % 2 === 0) { + const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${providedNodeVersion}`); // TODO: Inspect the range + core.info(`Switching to the latest stable major version... (${highestCurrent})`); + return highestCurrent; + } + else { + const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion) + 1}.x.x`); // TODO: Inspect the range + core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); + return searchedVersion; + } } - else { - const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion) + 1}.x.x`); // TODO: Inspect the range - core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); - return searchedVersion; + catch (err) { + core.error(err.message); + throw new Error(err.message); } }); } @@ -74020,8 +74026,7 @@ function run() { stable, arch }; - // My guess is that the change occurs somewhere below, as it touches on BaseDistribution and there we can access methods for fetching node distributions - let nodeDistribution = installer_factory_1.getNodejsDistribution(nodejsInfo); // changed const to let so i can execute the below lines properly (an idea) + let nodeDistribution = installer_factory_1.getNodejsDistribution(nodejsInfo); if (resolveStable === true) { const updatedVersion = yield nodeDistribution.resolveStableVersionOfNode(version); if (updatedVersion !== null) { diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index b3135d6fb..d6e7f7f9b 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -117,6 +117,7 @@ export default abstract class BaseDistribution { } private async determineStableNodeVersion(providedNodeVersion: string): Promise { + try { const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); @@ -132,6 +133,10 @@ export default abstract class BaseDistribution { return searchedVersion; } + } catch (err) { + core.error(err.message); + throw new Error(err.message); + } } async resolveStableVersionOfNode(providedNodeVersion: string): Promise { diff --git a/src/main.ts b/src/main.ts index 7e338b1a1..7dbac6bd6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,9 +50,7 @@ export async function run() { arch }; - // My guess is that the change occurs somewhere below, as it touches on BaseDistribution and there we can access methods for fetching node distributions - - let nodeDistribution = getNodejsDistribution(nodejsInfo); // changed const to let so i can execute the below lines properly (an idea) + let nodeDistribution = getNodejsDistribution(nodejsInfo); if (resolveStable === true) { const updatedVersion = await nodeDistribution.resolveStableVersionOfNode(version); From fc8bc1ae6d80af2bc3de545beb0fba0435ebbdcf Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Fri, 31 Mar 2023 18:03:38 +0200 Subject: [PATCH 18/25] Modify semver range --- dist/setup/index.js | 2 +- src/distributions/base-distribution.ts | 30 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 23de3d0c4..20f1535ba 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73439,7 +73439,7 @@ class BaseDistribution { const versionsDataList = yield this.getNodeJsVersions(); const versionsList = this.stableNodeVersionsList(versionsDataList); if (semver_1.default.major(providedNodeVersion) % 2 === 0) { - const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${providedNodeVersion}`); // TODO: Inspect the range + const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range core.info(`Switching to the latest stable major version... (${highestCurrent})`); return highestCurrent; } diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index d6e7f7f9b..1d7ef7d1d 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -118,25 +118,25 @@ export default abstract class BaseDistribution { private async determineStableNodeVersion(providedNodeVersion: string): Promise { try { - const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); - const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); + const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); + const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); - if (semver.major(providedNodeVersion) % 2 === 0) { - const highestCurrent = semver.maxSatisfying(versionsList, `^${providedNodeVersion}`); // TODO: Inspect the range - core.info(`Switching to the latest stable major version... (${highestCurrent})`); + if (semver.major(providedNodeVersion) % 2 === 0) { + const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range + core.info(`Switching to the latest stable major version... (${highestCurrent})`); - return highestCurrent; - } - else { - const searchedVersion = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)+1}.x.x`); // TODO: Inspect the range - core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); + return highestCurrent; + } + else { + const searchedVersion = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)+1}.x.x`); // TODO: Inspect the range + core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); - return searchedVersion; + return searchedVersion; + } + } catch (err) { + core.error(err.message); + throw new Error(err.message); } - } catch (err) { - core.error(err.message); - throw new Error(err.message); - } } async resolveStableVersionOfNode(providedNodeVersion: string): Promise { From d1708b1c431f0dab35302fbbb7ef8bcbfc7bb96d Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Fri, 31 Mar 2023 19:02:52 +0200 Subject: [PATCH 19/25] Modify versions yml --- .github/workflows/versions.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 28e7ef4e1..c83454603 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -27,11 +27,4 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: true - resolve-stable: true - - if: runner.os != 'Windows' - name: Verify node and npm - run: | - . "$NVM_DIR/nvm.sh" - [[ $(nvm version-remote "${{ matrix.node-version }}") =~ ^v([^.]+) ]] - __tests__/verify-node.sh "${BASH_REMATCH[1]}" - shell: bash \ No newline at end of file + resolve-stable: true \ No newline at end of file From d850f86ba225d71871995295c4adcfc5f215c089 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Mon, 3 Apr 2023 11:24:23 +0200 Subject: [PATCH 20/25] Refactor and rewrite some parts of the resolve-stable methods --- dist/setup/index.js | 53 +++++++++++++------------- src/distributions/base-distribution.ts | 38 +++++++++--------- src/main.ts | 4 +- 3 files changed, 48 insertions(+), 47 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 20f1535ba..ff14d7912 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73435,23 +73435,17 @@ class BaseDistribution { } determineStableNodeVersion(providedNodeVersion) { return __awaiter(this, void 0, void 0, function* () { - try { - const versionsDataList = yield this.getNodeJsVersions(); - const versionsList = this.stableNodeVersionsList(versionsDataList); - if (semver_1.default.major(providedNodeVersion) % 2 === 0) { - const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range - core.info(`Switching to the latest stable major version... (${highestCurrent})`); - return highestCurrent; - } - else { - const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion) + 1}.x.x`); // TODO: Inspect the range - core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); - return searchedVersion; - } + const versionsDataList = yield this.getNodeJsVersions(); + const versionsList = this.stableNodeVersionsList(versionsDataList); + if (semver_1.default.major(providedNodeVersion) % 2 === 0) { + const highestCurrent = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion)}.x.x`); + core.info(`Switching to the latest stable major version... (${highestCurrent})`); + return highestCurrent; } - catch (err) { - core.error(err.message); - throw new Error(err.message); + else { + const searchedVersion = semver_1.default.maxSatisfying(versionsList, `^${semver_1.default.major(providedNodeVersion) + 1}.x.x`); + core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); + return searchedVersion; } }); } @@ -73462,16 +73456,21 @@ class BaseDistribution { const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0]; const highestTotalNodeVersion = yield this.getTotalLatestNodeVersion(); let errorMessage; - if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary)) { - errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; - core.setFailed(errorMessage); - } - if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) || semver_1.default.gte(providedNodeVersion, highestTotalNodeVersion)) { - errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; - core.setFailed(errorMessage); + if (providedNodeVersion) { + if (semver_1.default.lt(providedNodeVersion, lowestStableBoundary)) { + errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; + core.setFailed(errorMessage); + } + if (semver_1.default.gt(providedNodeVersion, highestStableBoundary) || semver_1.default.gte(providedNodeVersion, highestTotalNodeVersion)) { + errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; + core.setFailed(errorMessage); + } + const version = yield this.determineStableNodeVersion(providedNodeVersion); + return version; } - const version = yield this.determineStableNodeVersion(providedNodeVersion); - return version; + errorMessage = 'No Node version provided'; + core.setFailed(errorMessage); + throw new Error(errorMessage); }); } getNodejsDistInfo(version) { @@ -74029,11 +74028,11 @@ function run() { let nodeDistribution = installer_factory_1.getNodejsDistribution(nodejsInfo); if (resolveStable === true) { const updatedVersion = yield nodeDistribution.resolveStableVersionOfNode(version); - if (updatedVersion !== null) { + if (updatedVersion) { nodeDistribution = installer_factory_1.getNodejsDistribution(Object.assign(Object.assign({}, nodejsInfo), { versionSpec: updatedVersion })); } else { - core.setFailed('The returned version value is null.'); + core.setFailed('The returned version value is undefined.'); } } yield nodeDistribution.setupNodeJs(); diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 1d7ef7d1d..d6509d2ce 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -117,50 +117,52 @@ export default abstract class BaseDistribution { } private async determineStableNodeVersion(providedNodeVersion: string): Promise { - try { const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const versionsList: string[] = this.stableNodeVersionsList(versionsDataList); if (semver.major(providedNodeVersion) % 2 === 0) { - const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); // TODO: Inspect the range + const highestCurrent = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)}.x.x`); core.info(`Switching to the latest stable major version... (${highestCurrent})`); return highestCurrent; } else { - const searchedVersion = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)+1}.x.x`); // TODO: Inspect the range + const searchedVersion = semver.maxSatisfying(versionsList, `^${semver.major(providedNodeVersion)+1}.x.x`); core.info(`Switching to the highest version of the next stable release... (${searchedVersion})`); return searchedVersion; } - } catch (err) { - core.error(err.message); - throw new Error(err.message); - } } + async resolveStableVersionOfNode(providedNodeVersion: string): Promise { const versionsDataList: INodeVersion[] = await this.getNodeJsVersions(); const lowestStableBoundary = '10.24.1'; const highestStableBoundary = this.stableNodeVersionsList(versionsDataList)[0]; const highestTotalNodeVersion = await this.getTotalLatestNodeVersion(); let errorMessage: string; - - if(semver.lt(providedNodeVersion, lowestStableBoundary)) { - errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; - core.setFailed(errorMessage); - } + if (providedNodeVersion) { + + if (semver.lt(providedNodeVersion, lowestStableBoundary)) { + errorMessage = `node-version specified is lower than the lowest supported stable version (${lowestStableBoundary}).`; + core.setFailed(errorMessage); + } + + if (semver.gt(providedNodeVersion, highestStableBoundary) || semver.gte(providedNodeVersion, highestTotalNodeVersion)) { + errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; + core.setFailed(errorMessage); + } - if (semver.gt(providedNodeVersion, highestStableBoundary) || semver.gte(providedNodeVersion, highestTotalNodeVersion)) { - errorMessage = `node-version specified is higher than the highest supported stable version (${highestStableBoundary}) or total version (${highestTotalNodeVersion}).`; + const version = await this.determineStableNodeVersion(providedNodeVersion); + return version; - core.setFailed(errorMessage); } - - const version = await this.determineStableNodeVersion(providedNodeVersion); - return version; + errorMessage = 'No Node version provided'; + + core.setFailed(errorMessage); + throw new Error(errorMessage); } diff --git a/src/main.ts b/src/main.ts index 7dbac6bd6..f9d05498f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,11 +54,11 @@ export async function run() { if (resolveStable === true) { const updatedVersion = await nodeDistribution.resolveStableVersionOfNode(version); - if (updatedVersion !== null) { + if (updatedVersion) { nodeDistribution = getNodejsDistribution({...nodejsInfo, versionSpec: updatedVersion}) } else { - core.setFailed('The returned version value is null.'); + core.setFailed('The returned version value is undefined.'); } } From 9a618d86185ab6df68fd109fabb95ecd80c3d09a Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Mon, 3 Apr 2023 11:26:23 +0200 Subject: [PATCH 21/25] Fix versions yml so that all jobs are passing --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index c83454603..93cb9751b 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [15.0.0, 16.0.0, 16.8.1, 17.9.1, 20.0.2, 18.15.0] + node-version: [15.0.0, 16.0.0, 16.8.1, 17.9.1, 18.15.0] steps: - uses: actions/checkout@v3 - name: Setup Node From e684a245212e05dd95530d4c5486eb4108af838c Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Wed, 5 Apr 2023 09:12:33 +0200 Subject: [PATCH 22/25] Fix unit tests to support resolve-stable --- __tests__/canary-installer.test.ts | 11 +++++++++++ __tests__/main.test.ts | 3 +++ __tests__/nightly-installer.test.ts | 11 +++++++++++ __tests__/official-installer.test.ts | 21 +++++++++++++++++++++ __tests__/rc-installer.test.ts | 11 +++++++++++ 5 files changed, 57 insertions(+) diff --git a/__tests__/canary-installer.test.ts b/__tests__/canary-installer.test.ts index 6d141fc3c..8915c16f6 100644 --- a/__tests__/canary-installer.test.ts +++ b/__tests__/canary-installer.test.ts @@ -151,6 +151,7 @@ describe('setup-node', () => { it('finds version in cache with stable true', async () => { inputs['node-version'] = '20-v8-canary'; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; inputs.stable = 'true'; @@ -176,6 +177,7 @@ describe('setup-node', () => { it('finds version in cache and adds it to the path', async () => { inputs['node-version'] = '20-v8-canary'; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; inSpy.mockImplementation(name => inputs[name]); @@ -200,6 +202,7 @@ describe('setup-node', () => { os.platform = 'linux'; const errMsg = 'unhandled error message'; inputs['node-version'] = '20.0.0-v8-canary20221103f7e2421e91'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => { throw new Error(errMsg); @@ -229,6 +232,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -259,6 +263,7 @@ describe('setup-node', () => { const versionSpec = '23.0.0-v8-canary20221103f7e2421e91'; inputs['node-version'] = versionSpec; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); findAllVersionsSpy.mockImplementation(() => [ @@ -285,6 +290,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); findAllVersionsSpy.mockImplementation(() => [ @@ -326,6 +332,7 @@ describe('setup-node', () => { inputs['architecture'] = arch; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; const expectedUrl = `https://nodejs.org/download/v8-canary/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; @@ -385,6 +392,7 @@ describe('setup-node', () => { cacheSpy.mockImplementation(async () => toolPath); inputs['node-version'] = input; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; // act @@ -422,6 +430,7 @@ describe('setup-node', () => { ]); inputs['node-version'] = input; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; @@ -470,6 +479,7 @@ describe('setup-node', () => { inputs['node-version'] = input; inputs['check-latest'] = 'true'; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; @@ -507,6 +517,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; os.platform = 'linux'; os.arch = 'x64'; diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b57248757..116c452e9 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -240,6 +240,7 @@ describe('main tests', () => { const versionFile = '.nvmrc'; const versionFilePath = path.join(__dirname, '..', versionFile); inputs['node-version-file'] = versionFile; + inputs['resolve-stable'] = 'false'; inSpy.mockImplementation(name => inputs[name]); existsSpy.mockImplementationOnce( @@ -262,6 +263,7 @@ describe('main tests', () => { describe('cache on GHES', () => { it('Should throw an error, because cache is not supported', async () => { inputs['node-version'] = '12'; + inputs['resolve-stable'] = 'false'; inputs['cache'] = 'npm'; inSpy.mockImplementation(name => inputs[name]); @@ -282,6 +284,7 @@ describe('main tests', () => { it('Should throw an internal error', async () => { inputs['node-version'] = '12'; + inputs['resolve-stable'] = 'false'; inputs['cache'] = 'npm'; inSpy.mockImplementation(name => inputs[name]); diff --git a/__tests__/nightly-installer.test.ts b/__tests__/nightly-installer.test.ts index d88f5093c..5953ddb01 100644 --- a/__tests__/nightly-installer.test.ts +++ b/__tests__/nightly-installer.test.ts @@ -143,6 +143,7 @@ describe('setup-node', () => { it('finds version in cache with stable true', async () => { inputs['node-version'] = '16-nightly'; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; inputs.stable = 'true'; @@ -170,6 +171,7 @@ describe('setup-node', () => { it('finds version in cache with stable false', async () => { inputs['node-version'] = '16.0.0-nightly20210415c3a5e15ebe'; os['arch'] = 'x64'; + inputs['resolve-stable'] = 'false'; inputs.stable = 'false'; const toolPath = path.normalize( @@ -195,6 +197,7 @@ describe('setup-node', () => { it('finds version in cache and adds it to the path', async () => { inputs['node-version'] = '16-nightly'; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; inSpy.mockImplementation(name => inputs[name]); @@ -225,6 +228,7 @@ describe('setup-node', () => { it('handles unhandled find error and reports error', async () => { const errMsg = 'unhandled error message'; inputs['node-version'] = '16.0.0-nightly20210417bc31dc0e0f'; + inputs['resolve-stable'] = 'false'; findAllVersionsSpy.mockImplementation(() => [ '12.0.1', @@ -252,6 +256,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -279,6 +284,7 @@ describe('setup-node', () => { const versionSpec = '10.13.1-nightly20200415947ddec091'; inputs['node-version'] = versionSpec; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); findAllVersionsSpy.mockImplementation(() => []); @@ -299,6 +305,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; + inputs['resolve-stable'] = 'false'; inputs['token'] = 'faketoken'; findSpy.mockImplementation(() => ''); @@ -338,6 +345,7 @@ describe('setup-node', () => { inputs['architecture'] = arch; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; const expectedUrl = `https://nodejs.org/download/nightly/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; @@ -397,6 +405,7 @@ describe('setup-node', () => { cacheSpy.mockImplementation(async () => toolPath); inputs['node-version'] = input; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; // act @@ -431,6 +440,7 @@ describe('setup-node', () => { ]); inputs['node-version'] = input; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; @@ -485,6 +495,7 @@ describe('setup-node', () => { inputs['node-version'] = input; inputs['check-latest'] = 'true'; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; diff --git a/__tests__/official-installer.test.ts b/__tests__/official-installer.test.ts index 474fb5b98..86ea5a6af 100644 --- a/__tests__/official-installer.test.ts +++ b/__tests__/official-installer.test.ts @@ -175,6 +175,7 @@ describe('setup-node', () => { it('finds version in cache with stable true', async () => { inputs['node-version'] = '12'; + inputs['resolve-stable'] = 'false'; inputs.stable = 'true'; const toolPath = path.normalize('/cache/node/12.16.1/x64'); @@ -186,6 +187,7 @@ describe('setup-node', () => { it('finds version in cache with stable not supplied', async () => { inputs['node-version'] = '12'; + inputs['resolve-stable'] = 'false'; inSpy.mockImplementation(name => inputs[name]); @@ -198,6 +200,7 @@ describe('setup-node', () => { it('finds version in cache and adds it to the path', async () => { inputs['node-version'] = '12'; + inputs['resolve-stable'] = 'false'; inSpy.mockImplementation(name => inputs[name]); @@ -212,6 +215,7 @@ describe('setup-node', () => { it('handles unhandled find error and reports error', async () => { const errMsg = 'unhandled error message'; inputs['node-version'] = '12'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => { throw new Error(errMsg); @@ -237,6 +241,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; const expectedUrl = 'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz'; @@ -289,6 +294,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -320,6 +326,7 @@ describe('setup-node', () => { const versionSpec = '9.99.9'; inputs['node-version'] = versionSpec; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); await main.run(); @@ -347,6 +354,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(() => { @@ -375,6 +383,7 @@ describe('setup-node', () => { inputs['architecture'] = arch; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; const expectedUrl = arch === 'x64' @@ -404,6 +413,7 @@ describe('setup-node', () => { inputs['node-version'] = '12'; inputs['check-latest'] = 'false'; + inputs['resolve-stable'] = 'false'; const toolPath = path.normalize('/cache/node/12.16.1/x64'); findSpy.mockReturnValue(toolPath); @@ -425,6 +435,7 @@ describe('setup-node', () => { inputs['node-version'] = '12'; inputs['check-latest'] = 'true'; + inputs['resolve-stable'] = 'false'; const toolPath = path.normalize('/cache/node/12.16.2/x64'); findSpy.mockReturnValue(toolPath); @@ -451,6 +462,7 @@ describe('setup-node', () => { inputs['node-version'] = '12'; inputs['check-latest'] = 'true'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); @@ -487,6 +499,7 @@ describe('setup-node', () => { inputs['check-latest'] = 'true'; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -529,6 +542,7 @@ describe('setup-node', () => { inputs['check-latest'] = 'true'; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -579,6 +593,7 @@ describe('setup-node', () => { async (lts, expectedVersion) => { // arrange inputs['node-version'] = `lts/${lts}`; + inputs['resolve-stable'] = 'false'; const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); findSpy.mockReturnValue(toolPath); @@ -628,6 +643,7 @@ describe('setup-node', () => { async (lts, expectedVersion, expectedUrl) => { // arrange inputs['node-version'] = `lts/${lts}`; + inputs['resolve-stable'] = 'false'; const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); findSpy.mockImplementation(() => ''); @@ -670,6 +686,7 @@ describe('setup-node', () => { it('fail with unable to parse LTS alias (lts/)', async () => { // arrange inputs['node-version'] = 'lts/'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); @@ -691,6 +708,7 @@ describe('setup-node', () => { it('fail to find LTS version (lts/unknown)', async () => { // arrange inputs['node-version'] = 'lts/unknown'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); @@ -715,6 +733,7 @@ describe('setup-node', () => { it('fail if manifest is not available', async () => { // arrange inputs['node-version'] = 'lts/erbium'; + inputs['resolve-stable'] = 'false'; // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -744,6 +763,7 @@ describe('setup-node', () => { async inputVersion => { // Arrange inputs['node-version'] = inputVersion; + inputs['resolve-stable'] = 'false'; os.platform = 'darwin'; os.arch = 'x64'; @@ -770,6 +790,7 @@ describe('setup-node', () => { async inputVersion => { // Arrange inputs['node-version'] = inputVersion; + inputs['resolve-stable'] = 'false'; const expectedVersion = nodeTestDist[0]; os.platform = 'darwin'; diff --git a/__tests__/rc-installer.test.ts b/__tests__/rc-installer.test.ts index 736260a4d..e79f6ad41 100644 --- a/__tests__/rc-installer.test.ts +++ b/__tests__/rc-installer.test.ts @@ -140,6 +140,7 @@ describe('setup-node', () => { it('finds version in cache with stable true', async () => { inputs['node-version'] = '12.0.0-rc.1'; + inputs['resolve-stable'] = 'false'; inputs.stable = 'true'; const toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64'); @@ -151,6 +152,7 @@ describe('setup-node', () => { it('finds version in cache with stable not supplied', async () => { inputs['node-version'] = '12.0.0-rc.1'; + inputs['resolve-stable'] = 'false'; inSpy.mockImplementation(name => inputs[name]); @@ -163,6 +165,7 @@ describe('setup-node', () => { it('finds version in cache and adds it to the path', async () => { inputs['node-version'] = '12.0.0-rc.1'; + inputs['resolve-stable'] = 'false'; inSpy.mockImplementation(name => inputs[name]); @@ -177,6 +180,7 @@ describe('setup-node', () => { it('handles unhandled find error and reports error', async () => { const errMsg = 'unhandled error message'; inputs['node-version'] = '12.0.0-rc.1'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => { throw new Error(errMsg); @@ -196,6 +200,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -222,6 +227,7 @@ describe('setup-node', () => { const versionSpec = '9.99.9-rc.1'; inputs['node-version'] = versionSpec; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); await main.run(); @@ -241,6 +247,7 @@ describe('setup-node', () => { inputs['node-version'] = versionSpec; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; findSpy.mockImplementation(() => ''); findAllVersionsSpy.mockImplementation(() => []); @@ -270,6 +277,7 @@ describe('setup-node', () => { inputs['architecture'] = arch; inputs['always-auth'] = false; inputs['token'] = 'faketoken'; + inputs['resolve-stable'] = 'false'; const expectedUrl = `https://nodejs.org/download/rc/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; @@ -329,6 +337,7 @@ describe('setup-node', () => { cacheSpy.mockImplementation(async () => toolPath); inputs['node-version'] = input; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; // act @@ -365,6 +374,7 @@ describe('setup-node', () => { ]); inputs['node-version'] = input; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; @@ -388,6 +398,7 @@ describe('setup-node', () => { exSpy.mockImplementation(async () => '/some/other/temp/path'); inputs['node-version'] = versionSpec; + inputs['resolve-stable'] = 'false'; os['arch'] = 'x64'; os['platform'] = 'linux'; // act From 330f52866d140153adad2bda5d5d0d783aaacc75 Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 13 Apr 2023 20:14:15 +0200 Subject: [PATCH 23/25] Trying out self-hosted runner --- .github/workflows/versions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 93cb9751b..85d30175b 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -14,7 +14,7 @@ on: jobs: resolve-stable-test: - runs-on: ${{ matrix.os }} + runs-on: self-hosted strategy: fail-fast: false matrix: @@ -25,6 +25,6 @@ jobs: - name: Setup Node uses: ./ with: - node-version: ${{ matrix.node-version }} + node-version: 16.0.0 check-latest: true resolve-stable: true \ No newline at end of file From 77a2e9a19140d798597ac3283835388946341e8c Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 13 Apr 2023 20:22:21 +0200 Subject: [PATCH 24/25] Test self-hosted runner --- .github/workflows/versions.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 85d30175b..93e6fa545 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -15,11 +15,11 @@ on: jobs: resolve-stable-test: runs-on: self-hosted - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [15.0.0, 16.0.0, 16.8.1, 17.9.1, 18.15.0] + # strategy: + # fail-fast: false + # matrix: + # os: [ubuntu-latest, windows-latest, macos-latest] + # node-version: [15.0.0, 16.0.0, 16.8.1, 17.9.1, 18.15.0] steps: - uses: actions/checkout@v3 - name: Setup Node From 4f97f23634faaa8c098eb3acd76796447403d15a Mon Sep 17 00:00:00 2001 From: Dusan Trickovic Date: Thu, 13 Apr 2023 21:00:52 +0200 Subject: [PATCH 25/25] Try self-hosted against all latest OS's for testing purposes --- .github/workflows/versions.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 93e6fa545..baa697f64 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -15,16 +15,15 @@ on: jobs: resolve-stable-test: runs-on: self-hosted - # strategy: - # fail-fast: false - # matrix: - # os: [ubuntu-latest, windows-latest, macos-latest] - # node-version: [15.0.0, 16.0.0, 16.8.1, 17.9.1, 18.15.0] + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node-version: [15.0.0, 16.0.0, 16.8.1, 17.9.1, 18.15.0] steps: - uses: actions/checkout@v3 - name: Setup Node uses: ./ with: - node-version: 16.0.0 check-latest: true resolve-stable: true \ No newline at end of file