Skip to content

Commit 17f8bd9

Browse files
authored
Expand current syntax to support aliases for latest version (current/latest/node) (#483)
1 parent b067f78 commit 17f8bd9

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

.github/workflows/versions.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,34 @@ jobs:
139139
- name: Verify node
140140
run: __tests__/verify-arch.sh "ia32"
141141
shell: bash
142+
143+
node-latest-aliases:
144+
runs-on: ${{ matrix.os }}
145+
strategy:
146+
fail-fast: false
147+
matrix:
148+
os: [ubuntu-latest, windows-latest, macos-latest]
149+
node-version: [current, latest, node]
150+
steps:
151+
- name: Get node version
152+
run: |
153+
latestNodeVersion=$(curl https://nodejs.org/dist/index.json | jq -r '. [0].version')
154+
echo "::set-output name=LATEST_NODE_VERSION::$latestNodeVersion"
155+
id: version
156+
shell: bash
157+
- uses: actions/checkout@v3
158+
- name: Setup Node
159+
uses: ./
160+
with:
161+
node-version: ${{ matrix.node-version }}
162+
- name: Retrieve version after install
163+
run: |
164+
updatedVersion=$(echo $(node --version))
165+
echo "::set-output name=NODE_VERSION_UPDATED::$updatedVersion"
166+
id: updatedVersion
167+
shell: bash
168+
- name: Compare versions
169+
if: ${{ steps.version.outputs.LATEST_NODE_VERSION != steps.updatedVersion.outputs.NODE_VERSION_UPDATED}}
170+
run: |
171+
echo "Latest node version failed to download."
172+
exit 1

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ The `node-version` input supports the following syntax:
4040
major versions: `12`, `14`, `16`
4141
more specific versions: `10.15`, `14.2.0`, `16.3.0`
4242
nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*`
43+
latest release: `latest`/`current`/`node`
44+
45+
**Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist
4346

4447
### Checking in lockfiles
4548

__tests__/installer.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,4 +909,30 @@ describe('setup-node', () => {
909909
);
910910
});
911911
});
912+
913+
describe('latest alias syntax', () => {
914+
it.each(['latest', 'current', 'node'])(
915+
'download the %s version if alias is provided',
916+
async inputVersion => {
917+
// Arrange
918+
inputs['node-version'] = inputVersion;
919+
920+
os.platform = 'darwin';
921+
os.arch = 'x64';
922+
923+
findSpy.mockImplementation(() => '');
924+
getManifestSpy.mockImplementation(() => {
925+
throw new Error('Unable to download manifest');
926+
});
927+
928+
// Act
929+
await main.run();
930+
931+
// assert
932+
expect(logSpy).toHaveBeenCalledWith('Unable to download manifest');
933+
934+
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
935+
}
936+
);
937+
});
912938
});

dist/setup/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62587,6 +62587,12 @@ function queryDistForMatch(versionSpec, arch = os.arch()) {
6258762587
}
6258862588
let versions = [];
6258962589
let nodeVersions = yield getVersionsFromDist();
62590+
if (versionSpec === 'current' ||
62591+
versionSpec === 'latest' ||
62592+
versionSpec === 'node') {
62593+
core.info(`getting latest node version...`);
62594+
return nodeVersions[0].version;
62595+
}
6259062596
nodeVersions.forEach((nodeVersion) => {
6259162597
// ensure this version supports your os and platform
6259262598
if (nodeVersion.files.indexOf(dataFileName) >= 0) {

src/installer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ async function queryDistForMatch(
373373
let versions: string[] = [];
374374
let nodeVersions = await getVersionsFromDist();
375375

376+
if (
377+
versionSpec === 'current' ||
378+
versionSpec === 'latest' ||
379+
versionSpec === 'node'
380+
) {
381+
core.info(`getting latest node version...`);
382+
return nodeVersions[0].version;
383+
}
384+
376385
nodeVersions.forEach((nodeVersion: INodeVersion) => {
377386
// ensure this version supports your os and platform
378387
if (nodeVersion.files.indexOf(dataFileName) >= 0) {

0 commit comments

Comments
 (0)