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

Add support for asdf format as Node.js version file #373

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
3 changes: 2 additions & 1 deletion .github/workflows/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version-file: [.nvmrc, .tool-versions]
steps:
- uses: actions/checkout@v3
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/.nvmrc'
node-version-file: '__tests__/data/${{ matrix.node-version-file }}'
- name: Verify node
run: __tests__/verify-node.sh 14

Expand Down
1 change: 1 addition & 0 deletions __tests__/data/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 14.0.0
21 changes: 21 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs from 'fs';
import cp from 'child_process';
import osm = require('os');
import path from 'path';
import each from 'jest-each';
import * as main from '../src/main';
import * as auth from '../src/authutil';

Expand Down Expand Up @@ -941,3 +942,23 @@ describe('setup-node', () => {
);
});
});

describe('helper methods', () => {
describe('parseNodeVersionFile', () => {
each`
contents | expected
${'12'} | ${'12'}
${'12.3'} | ${'12.3'}
${'12.3.4'} | ${'12.3.4'}
${'v12.3.4'} | ${'12.3.4'}
${'lts/erbium'} | ${'lts/erbium'}
${'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'}
`.it('parses "$contents"', ({contents, expected}) => {
expect(im.parseNodeVersionFile(contents)).toBe(expected);
});
});
});
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
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:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest:
Expand Down
14 changes: 9 additions & 5 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70963,11 +70963,15 @@ function translateArchToDistUrl(arch) {
}
}
function parseNodeVersionFile(contents) {
let nodeVersion = contents.trim();
if (/^v\d/.test(nodeVersion)) {
nodeVersion = nodeVersion.substring(1);
}
return nodeVersion;
var _a;
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
const nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
if (nodeVersion) {
return nodeVersion;
}
// In the case of an unknown format,
// return as is and evaluate the version separately.
return contents.trim();
}
exports.parseNodeVersionFile = parseNodeVersionFile;
function isLatestSyntax(versionSpec) {
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ steps:

## 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)
> The action will search for the node version file relative to the repository root.

Expand Down
12 changes: 8 additions & 4 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,16 @@ function translateArchToDistUrl(arch: 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)) {
nodeVersion = nodeVersion.substring(1);
if (nodeVersion) {
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 {
Expand Down