diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index ce43847a..34da05a7 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -57,7 +57,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [17-nightly, 18-nightly, 19-nightly] + node-version: [16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly] steps: - uses: actions/checkout@v3 - name: Setup Node diff --git a/__tests__/README.md b/__tests__/README.md new file mode 100644 index 00000000..bbb4ac06 --- /dev/null +++ b/__tests__/README.md @@ -0,0 +1,10 @@ +Files located in data directory are used only for testing purposes. + + +## Here the list of files in the data directory + - `.nvmrc`, `.tools-versions` and `package.json` are used to test node-version-file logic + - `package-lock.json`, `pnpm-lock.yaml` and `yarn.lock` are used to test cache logic + - `versions-manifest.json` is used for unit testing to check downloading Node.js versions from the node-versions repository. + - `node-dist-index.json` is used for unit testing to check downloading Node.js versions from the official site. + - `node-rc-index.json` is used for unit testing to check downloading Node.js rc versions from the official site. + - `node-nightly-index.json` is used for unit testing to check downloading Node.js nightly builds from the official site. \ No newline at end of file diff --git a/dist/setup/index.js b/dist/setup/index.js index a39bcda2..c3e53647 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73438,7 +73438,7 @@ function evaluateNightlyVersions(versions, versionSpec) { } } if (range) { - versions.sort((a, b) => +semver.lt(a, b) - 0.5); + versions.sort(semver.rcompare); for (const currentVersion of versions) { const satisfied = semver.satisfies(currentVersion.replace('-nightly', '-nightly.'), range, { includePrerelease: true }) && currentVersion.includes('nightly'); if (satisfied) { @@ -73462,12 +73462,7 @@ function evaluateVersions(versions, versionSpec) { if (versionSpec.includes('nightly')) { return evaluateNightlyVersions(versions, versionSpec); } - versions = versions.sort((a, b) => { - if (semver.gt(a, b)) { - return 1; - } - return -1; - }); + versions = versions.sort(semver.rcompare); for (let i = versions.length - 1; i >= 0; i--) { const potential = versions[i]; const satisfied = semver.satisfies(potential, versionSpec); diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 287b130f..c2a8374e 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -106,7 +106,9 @@ jobs: ## Nightly versions -You can specify a nightly version to download it from https://nodejs.org/download/nightly. +You can specify a nightly version to download it from https://nodejs.org/download/nightly. + +### Install nightly build for specific node version ```yaml jobs: @@ -117,7 +119,39 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: '16.0.0-nightly' # or 16-nightly + node-version: '16.0.0-nightly' # it will install the latest nigthly release for node 16.0.0 + - run: npm ci + - run: npm test +``` + +### Install nightly build for major node version + +```yaml +jobs: + build: + runs-on: ubuntu-latest + name: Node sample + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16-nightly' # it will install the latest nigthly release for node 16 + - run: npm ci + - run: npm test +``` + +### Install the exact nightly version + +```yaml +jobs: + build: + runs-on: ubuntu-latest + name: Node sample + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16.0.0-nightly20210420a0261d231c' - run: npm ci - run: npm test ``` @@ -140,6 +174,8 @@ jobs: - run: npm test ``` +**Note:** You should specify the exact version for rc: `16.0.0-rc.1`. + ## Caching packages data The action follows [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) guidelines, and caches global cache on the machine instead of `node_modules`, so cache can be reused between different Node.js versions. diff --git a/src/installer.ts b/src/installer.ts index 37bb7ce8..1b5659b6 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -370,7 +370,7 @@ function evaluateNightlyVersions( versionSpec: string ): string { let version = ''; - let range: string | null | undefined; + let range: string | undefined; const [raw, prerelease] = versionSpec.split('-'); const isValidVersion = semver.valid(raw); const rawVersion = isValidVersion ? raw : semver.coerce(raw); @@ -383,7 +383,7 @@ function evaluateNightlyVersions( } if (range) { - versions.sort((a, b) => +semver.lt(a, b) - 0.5); + versions.sort(semver.rcompare); for (const currentVersion of versions) { const satisfied: boolean = semver.satisfies( @@ -416,12 +416,7 @@ function evaluateVersions(versions: string[], versionSpec: string): string { return evaluateNightlyVersions(versions, versionSpec); } - versions = versions.sort((a, b) => { - if (semver.gt(a, b)) { - return 1; - } - return -1; - }); + versions = versions.sort(semver.rcompare); for (let i = versions.length - 1; i >= 0; i--) { const potential: string = versions[i]; const satisfied: boolean = semver.satisfies(potential, versionSpec);