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

Expand current syntax to support aliases for latest version (current/latest/node) #483

Merged
merged 23 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
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
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

### Checking in lockfiles

Expand Down
26 changes: 26 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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