Skip to content

Commit

Permalink
Expand current syntax to support aliases for latest version (current/…
Browse files Browse the repository at this point in the history
…latest/node) (#483)
  • Loading branch information
panticmilos committed May 12, 2022
1 parent b067f78 commit 17f8bd9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/versions.yml
Expand Up @@ -139,3 +139,34 @@ jobs:
- name: Verify node
run: __tests__/verify-arch.sh "ia32"
shell: bash

node-latest-aliases:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [current, latest, node]
steps:
- name: Get node version
run: |
latestNodeVersion=$(curl https://nodejs.org/dist/index.json | jq -r '. [0].version')
echo "::set-output name=LATEST_NODE_VERSION::$latestNodeVersion"
id: version
shell: bash
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Retrieve version after install
run: |
updatedVersion=$(echo $(node --version))
echo "::set-output name=NODE_VERSION_UPDATED::$updatedVersion"
id: updatedVersion
shell: bash
- name: Compare versions
if: ${{ steps.version.outputs.LATEST_NODE_VERSION != steps.updatedVersion.outputs.NODE_VERSION_UPDATED}}
run: |
echo "Latest node version failed to download."
exit 1
3 changes: 3 additions & 0 deletions README.md
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

### Checking in lockfiles

Expand Down
26 changes: 26 additions & 0 deletions __tests__/installer.test.ts
Expand Up @@ -909,4 +909,30 @@ describe('setup-node', () => {
);
});
});

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

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

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

// Act
await main.run();

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

expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
}
);
});
});
6 changes: 6 additions & 0 deletions dist/setup/index.js
Expand Up @@ -62587,6 +62587,12 @@ function queryDistForMatch(versionSpec, arch = os.arch()) {
}
let versions = [];
let nodeVersions = yield getVersionsFromDist();
if (versionSpec === 'current' ||
versionSpec === 'latest' ||
versionSpec === 'node') {
core.info(`getting latest node version...`);
return nodeVersions[0].version;
}
nodeVersions.forEach((nodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
Expand Down
9 changes: 9 additions & 0 deletions src/installer.ts
Expand Up @@ -373,6 +373,15 @@ async function queryDistForMatch(
let versions: string[] = [];
let nodeVersions = await getVersionsFromDist();

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

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

0 comments on commit 17f8bd9

Please sign in to comment.