mirror of
https://github.com/actions/setup-node.git
synced 2024-12-23 09:29:49 +08:00
Expand current syntax to support aliases for latest version (current/latest/node) (#483)
This commit is contained in:
parent
b067f78ed3
commit
17f8bd9264
31
.github/workflows/versions.yml
vendored
31
.github/workflows/versions.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
dist/setup/index.js
vendored
6
dist/setup/index.js
vendored
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user