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

Diff for: .github/workflows/versions.yml

+2-1
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

Diff for: __tests__/data/.tool-versions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 14.0.0

Diff for: __tests__/installer.test.ts

+11-9
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
});

Diff for: action.yml

+1-1
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:

Diff for: dist/setup/index.js

+9-5
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) {

Diff for: docs/advanced-usage.md

+1-1
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

Diff for: src/installer.ts

+8-4
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)