Skip to content

Commit dbb64ac

Browse files
committed
Add support for asdf format as Node.js version file
1 parent 8249676 commit dbb64ac

File tree

7 files changed

+33
-21
lines changed

7 files changed

+33
-21
lines changed

.github/workflows/versions.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ jobs:
8484
fail-fast: false
8585
matrix:
8686
os: [ubuntu-latest, windows-latest, macos-latest]
87+
node-version-file: [.nvmrc, .tool-versions]
8788
steps:
8889
- uses: actions/checkout@v3
8990
- name: Setup node from node version file
9091
uses: ./
9192
with:
92-
node-version-file: '__tests__/data/.nvmrc'
93+
node-version-file: '__tests__/data/${{ matrix.node-version-file }}'
9394
- name: Verify node
9495
run: __tests__/verify-node.sh 14
9596

__tests__/data/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 14.0.0

__tests__/installer.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -946,15 +946,17 @@ describe('setup-node', () => {
946946
describe('helper methods', () => {
947947
describe('parseNodeVersionFile', () => {
948948
each`
949-
contents | expected
950-
${'12'} | ${'12'}
951-
${'12.3'} | ${'12.3'}
952-
${'12.3.4'} | ${'12.3.4'}
953-
${'v12.3.4'} | ${'12.3.4'}
954-
${'lts/erbium'} | ${'lts/erbium'}
955-
${'lts/*'} | ${'lts/*'}
956-
${''} | ${''}
957-
${'unknown format'} | ${'unknown format'}
949+
contents | expected
950+
${'12'} | ${'12'}
951+
${'12.3'} | ${'12.3'}
952+
${'12.3.4'} | ${'12.3.4'}
953+
${'v12.3.4'} | ${'12.3.4'}
954+
${'lts/erbium'} | ${'lts/erbium'}
955+
${'lts/*'} | ${'lts/*'}
956+
${'nodejs 12.3.4'} | ${'12.3.4'}
957+
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
958+
${''} | ${''}
959+
${'unknown format'} | ${'unknown format'}
958960
`.it('parses "$contents"', ({contents, expected}) => {
959961
expect(im.parseNodeVersionFile(contents)).toBe(expected);
960962
});

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
node-version:
99
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
1010
node-version-file:
11-
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version.'
11+
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.'
1212
architecture:
1313
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
1414
check-latest:

dist/setup/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70963,11 +70963,15 @@ function translateArchToDistUrl(arch) {
7096370963
}
7096470964
}
7096570965
function parseNodeVersionFile(contents) {
70966-
let nodeVersion = contents.trim();
70967-
if (/^v\d/.test(nodeVersion)) {
70968-
nodeVersion = nodeVersion.substring(1);
70969-
}
70970-
return nodeVersion;
70966+
var _a;
70967+
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
70968+
const nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
70969+
if (nodeVersion) {
70970+
return nodeVersion;
70971+
}
70972+
// In the case of an unknown format,
70973+
// return as is and evaluate the version separately.
70974+
return contents.trim();
7097170975
}
7097270976
exports.parseNodeVersionFile = parseNodeVersionFile;
7097370977
function isLatestSyntax(versionSpec) {

docs/advanced-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ steps:
5656
5757
## Node version file
5858
59-
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc` or `.node-version`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
59+
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version` or `.tool-versions`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
6060
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)
6161
> The action will search for the node version file relative to the repository root.
6262

src/installer.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,16 @@ function translateArchToDistUrl(arch: string): string {
487487
}
488488

489489
export function parseNodeVersionFile(contents: string): string {
490-
let nodeVersion = contents.trim();
490+
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
491+
const nodeVersion = found?.groups?.version;
491492

492-
if (/^v\d/.test(nodeVersion)) {
493-
nodeVersion = nodeVersion.substring(1);
493+
if (nodeVersion) {
494+
return nodeVersion;
494495
}
495-
return nodeVersion;
496+
497+
// In the case of an unknown format,
498+
// return as is and evaluate the version separately.
499+
return contents.trim();
496500
}
497501

498502
function isLatestSyntax(versionSpec): boolean {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy