Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,33 @@ jobs:
- name: Verify node
run: __tests__/verify-arch.sh "ia32"
shell: bash

node-latest-aliases:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [current, latest, node]
steps:
- name: Retrieve version before install
run: |
version=$(echo $(node --version))
echo "::set-output name=NODE_VERSION::$version"
id: version
shell: bash
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Retrieve version after install
run: |
updatedVersion=$(echo $(node --version))
echo "::set-output name=NODE_VERSION_UPDATED::$updatedVersion"
id: updatedVersion
shell: bash
- name: Compare versions
if: ${{ steps.version.outputs.NODE_VERSION == steps.updatedVersion.outputs.NODE_VERSION_UPDATED}}
run: |
echo "System node version ${{steps.updatedVersion.outputs.NODE_VERSION_UPDATED}} is same after the installation!"
Comment thread
vsafonkin marked this conversation as resolved.
Outdated
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ The `node-version` input supports the following syntax:
major versions: `12`, `14`, `16`
more specific versions: `10.15`, `14.2.0`, `16.3.0`
nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*`
latest release: `latest`/`current`/`node`

**Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist

## Caching global packages data

Expand Down
41 changes: 41 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,4 +909,45 @@ describe('setup-node', () => {
);
});
});

describe('latest alias syntax', () => {
it.each(['latest', 'current', 'node'])(
'download the %s version if alias is provided',
async inputVersion => {
// Arrange
inputs['node-version'] = inputVersion;

os.platform = 'darwin';
os.arch = 'x64';

const expectedVersion = nodeTestDist[0];

let expectedUrl = `https://nodejs.org/dist/${expectedVersion.version}/node-${expectedVersion.version}-${os.platform}-${os.arch}.tar.gz`;

findSpy.mockImplementation(() => '');
getManifestSpy.mockImplementation(() => {
throw new Error('Unable to download manifest');
});

// Act
await main.run();

// Assert
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${inputVersion}...`
);

expect(logSpy).toHaveBeenCalledWith('Unable to download manifest');

expect(logSpy).toHaveBeenCalledWith('getting latest node version...');

expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${expectedVersion.version.substring(
1,
expectedVersion.version.length
)} - ${os.arch} from ${expectedUrl}`
);
}
);
});
});
9 changes: 8 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62339,6 +62339,7 @@ const tc = __importStar(__webpack_require__(533));
const path = __importStar(__webpack_require__(622));
const semver = __importStar(__webpack_require__(280));
const fs = __webpack_require__(747);
const installer = __importStar(__webpack_require__(923));
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
// Store manifest data to avoid multiple calls
Expand Down Expand Up @@ -62586,7 +62587,13 @@ function queryDistForMatch(versionSpec, arch = os.arch()) {
throw new Error(`Unexpected OS '${osPlat}'`);
}
let versions = [];
let nodeVersions = yield getVersionsFromDist();
let nodeVersions = yield installer.getVersionsFromDist();
if (versionSpec === 'current' ||
versionSpec === 'latest' ||
versionSpec === 'node') {
core.info(`getting latest node version...`);
return nodeVersions[0].version;
}
nodeVersions.forEach((nodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
Expand Down
12 changes: 11 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as tc from '@actions/tool-cache';
import * as path from 'path';
import * as semver from 'semver';
import fs = require('fs');
import * as installer from './installer';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest omitting this import statement.


//
// Node versions interface
Expand Down Expand Up @@ -371,7 +372,16 @@ async function queryDistForMatch(
}

let versions: string[] = [];
let nodeVersions = await getVersionsFromDist();
let nodeVersions = await installer.getVersionsFromDist();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we omit the import statement above, we can omit that also:

Suggested change
let nodeVersions = await installer.getVersionsFromDist();
let nodeVersions = await getVersionsFromDist();


if (
versionSpec === 'current' ||
versionSpec === 'latest' ||
versionSpec === 'node'
) {
core.info(`getting latest node version...`);
return nodeVersions[0].version;
}

nodeVersions.forEach((nodeVersion: INodeVersion) => {
// ensure this version supports your os and platform
Expand Down