mirror of
https://gitea.com/actions/setup-node.git
synced 2024-11-25 11:39:32 +01:00
Add support for asdf format as Node.js version file
This commit is contained in:
parent
82496765f3
commit
dbb64ac1d1
7 changed files with 32 additions and 20 deletions
3
.github/workflows/versions.yml
vendored
3
.github/workflows/versions.yml
vendored
|
@ -84,12 +84,13 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
node-version-file: [.nvmrc, .tool-versions]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version-file: '__tests__/data/.nvmrc'
|
node-version-file: '__tests__/data/${{ matrix.node-version-file }}'
|
||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-node.sh 14
|
run: __tests__/verify-node.sh 14
|
||||||
|
|
||||||
|
|
1
__tests__/data/.tool-versions
Normal file
1
__tests__/data/.tool-versions
Normal file
|
@ -0,0 +1 @@
|
||||||
|
nodejs 14.0.0
|
|
@ -953,6 +953,8 @@ describe('helper methods', () => {
|
||||||
${'v12.3.4'} | ${'12.3.4'}
|
${'v12.3.4'} | ${'12.3.4'}
|
||||||
${'lts/erbium'} | ${'lts/erbium'}
|
${'lts/erbium'} | ${'lts/erbium'}
|
||||||
${'lts/*'} | ${'lts/*'}
|
${'lts/*'} | ${'lts/*'}
|
||||||
|
${'nodejs 12.3.4'} | ${'12.3.4'}
|
||||||
|
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
|
||||||
${''} | ${''}
|
${''} | ${''}
|
||||||
${'unknown format'} | ${'unknown format'}
|
${'unknown format'} | ${'unknown format'}
|
||||||
`.it('parses "$contents"', ({contents, expected}) => {
|
`.it('parses "$contents"', ({contents, expected}) => {
|
||||||
|
|
|
@ -8,7 +8,7 @@ inputs:
|
||||||
node-version:
|
node-version:
|
||||||
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
|
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
|
||||||
node-version-file:
|
node-version-file:
|
||||||
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version.'
|
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.'
|
||||||
architecture:
|
architecture:
|
||||||
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
|
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
|
||||||
check-latest:
|
check-latest:
|
||||||
|
|
12
dist/setup/index.js
vendored
12
dist/setup/index.js
vendored
|
@ -70963,11 +70963,15 @@ function translateArchToDistUrl(arch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function parseNodeVersionFile(contents) {
|
function parseNodeVersionFile(contents) {
|
||||||
let nodeVersion = contents.trim();
|
var _a;
|
||||||
if (/^v\d/.test(nodeVersion)) {
|
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
nodeVersion = nodeVersion.substring(1);
|
const nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
|
||||||
}
|
if (nodeVersion) {
|
||||||
return nodeVersion;
|
return nodeVersion;
|
||||||
|
}
|
||||||
|
// In the case of an unknown format,
|
||||||
|
// return as is and evaluate the version separately.
|
||||||
|
return contents.trim();
|
||||||
}
|
}
|
||||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||||
function isLatestSyntax(versionSpec) {
|
function isLatestSyntax(versionSpec) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ steps:
|
||||||
|
|
||||||
## Node version file
|
## Node version file
|
||||||
|
|
||||||
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.
|
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.
|
||||||
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)
|
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)
|
||||||
> The action will search for the node version file relative to the repository root.
|
> The action will search for the node version file relative to the repository root.
|
||||||
|
|
||||||
|
|
|
@ -487,12 +487,16 @@ function translateArchToDistUrl(arch: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseNodeVersionFile(contents: string): string {
|
export function parseNodeVersionFile(contents: string): string {
|
||||||
let nodeVersion = contents.trim();
|
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
|
const nodeVersion = found?.groups?.version;
|
||||||
|
|
||||||
if (/^v\d/.test(nodeVersion)) {
|
if (nodeVersion) {
|
||||||
nodeVersion = nodeVersion.substring(1);
|
|
||||||
}
|
|
||||||
return nodeVersion;
|
return nodeVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In the case of an unknown format,
|
||||||
|
// return as is and evaluate the version separately.
|
||||||
|
return contents.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLatestSyntax(versionSpec): boolean {
|
function isLatestSyntax(versionSpec): boolean {
|
||||||
|
|
Loading…
Reference in a new issue