Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nightly and rc versions #611

2 changes: 1 addition & 1 deletion .github/workflows/versions.yml
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions __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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some info on where these files come from?

- `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.
9 changes: 2 additions & 7 deletions dist/setup/index.js
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
40 changes: 38 additions & 2 deletions docs/advanced-usage.md
Expand Up @@ -106,7 +106,25 @@ 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
Copy link
Contributor

@brcrista brcrista Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Install nightly build for specific node version
### Install the nightly build for a specific 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-nightly' # it will install the latest nigthly release for node 16.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node-version: '16.0.0-nightly' # it will install the latest nigthly release for node 16.0.0
node-version: '16.0.0-nightly' # it will install the latest nightly release for node 16.0.0

- run: npm ci
- run: npm test
```

### Install nightly build for major node version
Copy link
Contributor

@brcrista brcrista Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Install nightly build for major node version
### Install the nightly build for a major version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just for a better flow, I would move this first so it goes major version -> specific version -> exact nightly


```yaml
jobs:
Expand All @@ -117,7 +135,23 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.0.0-nightly' # or 16-nightly
node-version: '16-nightly' # it will install the latest nigthly release for node 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node-version: '16-nightly' # it will install the latest nigthly release for node 16
node-version: '16-nightly' # it will install the latest nightly release for node 16

- run: npm ci
- run: npm test
```

### Install the exact nightly version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Install the exact nightly version
### Install an 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
```
Expand All @@ -140,6 +174,8 @@ jobs:
- run: npm test
```

**Note:** You should specify the exact version for rc: `16.0.0-rc.1`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Note:** You should specify the exact version for rc: `16.0.0-rc.1`.
**Note:** Unlike nightly versions, which support version range specifiers, you must specify the exact version for a release candidate: `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.

Expand Down
11 changes: 3 additions & 8 deletions src/installer.ts
Expand Up @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down