Compare commits

...

10 Commits

Author SHA1 Message Date
Dmitry Shibanov
2fddd8803e fixing pnpm output issue (#545) 2022-07-13 16:20:39 +02:00
Marko Zivic
ad8542ca5e Merge pull request #540 from dmitry-shibanov/fix-error-node-version
Fix error node version output
2022-07-12 15:59:02 +02:00
Dmitry Shibanov
3d11add771 remove unused import 2022-07-12 14:44:36 +02:00
Dmitry Shibanov
072a2e3b10 add trim and silent true 2022-07-12 14:19:55 +02:00
Dmitry Shibanov
28ad38fe06 add try catch 2022-07-12 10:45:50 +02:00
Dmitry Shibanov
48de4c13f6 change to streams 2022-07-12 10:36:10 +02:00
Dmitry Shibanov
aab7cc882a add silent 2022-07-12 10:30:30 +02:00
Marko Zivic
5b949b50c3 Merge pull request #373 from ganta/add-support-for-asdf-format-as-node-version-file
Add support for asdf format as Node.js version file
2022-07-11 13:48:55 +02:00
Hideki Igarashi
dbb64ac1d1 Add support for asdf format as Node.js version file 2022-05-30 20:13:04 +09:00
Hideki Igarashi
82496765f3 Add tests for parseNodeVersionFile 2022-05-30 20:05:14 +09:00
10 changed files with 65 additions and 25 deletions

View File

@@ -92,12 +92,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

View File

@@ -0,0 +1 @@
nodejs 14.0.0

View File

@@ -8,6 +8,7 @@ import fs from 'fs';
import cp from 'child_process'; import cp from 'child_process';
import osm = require('os'); import osm = require('os');
import path from 'path'; import path from 'path';
import each from 'jest-each';
import * as main from '../src/main'; import * as main from '../src/main';
import * as auth from '../src/authutil'; import * as auth from '../src/authutil';
@@ -904,3 +905,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);
});
});
});

View File

@@ -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:

View File

@@ -59931,7 +59931,7 @@ exports.supportedPackageManagers = {
}, },
pnpm: { pnpm: {
lockFilePatterns: ['pnpm-lock.yaml'], lockFilePatterns: ['pnpm-lock.yaml'],
getCacheFolderCommand: 'pnpm store path' getCacheFolderCommand: 'pnpm store path --silent'
}, },
yarn1: { yarn1: {
lockFilePatterns: ['yarn.lock'], lockFilePatterns: ['yarn.lock'],
@@ -59986,7 +59986,7 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
throw new Error(`Could not get cache folder path for ${packageManager}`); throw new Error(`Could not get cache folder path for ${packageManager}`);
} }
core.debug(`${packageManager} path is ${stdOut}`); core.debug(`${packageManager} path is ${stdOut}`);
return stdOut; return stdOut.trim();
}); });
function isGhes() { function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');

25
dist/setup/index.js vendored
View File

@@ -71277,7 +71277,7 @@ exports.supportedPackageManagers = {
}, },
pnpm: { pnpm: {
lockFilePatterns: ['pnpm-lock.yaml'], lockFilePatterns: ['pnpm-lock.yaml'],
getCacheFolderCommand: 'pnpm store path' getCacheFolderCommand: 'pnpm store path --silent'
}, },
yarn1: { yarn1: {
lockFilePatterns: ['yarn.lock'], lockFilePatterns: ['yarn.lock'],
@@ -71332,7 +71332,7 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
throw new Error(`Could not get cache folder path for ${packageManager}`); throw new Error(`Could not get cache folder path for ${packageManager}`);
} }
core.debug(`${packageManager} path is ${stdOut}`); core.debug(`${packageManager} path is ${stdOut}`);
return stdOut; return stdOut.trim();
}); });
function isGhes() { function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
@@ -71768,11 +71768,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) {
@@ -71842,8 +71846,13 @@ function run() {
yield installer.getNode(version, stable, checkLatest, auth, arch); yield installer.getNode(version, stable, checkLatest, auth, arch);
} }
// Output version of node is being used // Output version of node is being used
const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true }); try {
core.setOutput('node-version', installedVersion); const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true, silent: true });
core.setOutput('node-version', installedVersion.trim());
}
catch (err) {
core.setOutput('node-version', '');
}
const registryUrl = core.getInput('registry-url'); const registryUrl = core.getInput('registry-url');
const alwaysAuth = core.getInput('always-auth'); const alwaysAuth = core.getInput('always-auth');
if (registryUrl) { if (registryUrl) {

View File

@@ -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.

View File

@@ -18,7 +18,7 @@ export const supportedPackageManagers: SupportedPackageManagers = {
}, },
pnpm: { pnpm: {
lockFilePatterns: ['pnpm-lock.yaml'], lockFilePatterns: ['pnpm-lock.yaml'],
getCacheFolderCommand: 'pnpm store path' getCacheFolderCommand: 'pnpm store path --silent'
}, },
yarn1: { yarn1: {
lockFilePatterns: ['yarn.lock'], lockFilePatterns: ['yarn.lock'],
@@ -94,7 +94,7 @@ export const getCacheDirectoryPath = async (
core.debug(`${packageManager} path is ${stdOut}`); core.debug(`${packageManager} path is ${stdOut}`);
return stdOut; return stdOut.trim();
}; };
export function isGhes(): boolean { export function isGhes(): boolean {

View File

@@ -495,12 +495,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 {

View File

@@ -41,12 +41,16 @@ export async function run() {
} }
// Output version of node is being used // Output version of node is being used
const {stdout: installedVersion} = await exec.getExecOutput( try {
'node', const {stdout: installedVersion} = await exec.getExecOutput(
['--version'], 'node',
{ignoreReturnCode: true} ['--version'],
); {ignoreReturnCode: true, silent: true}
core.setOutput('node-version', installedVersion); );
core.setOutput('node-version', installedVersion.trim());
} catch (err) {
core.setOutput('node-version', '');
}
const registryUrl: string = core.getInput('registry-url'); const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth'); const alwaysAuth: string = core.getInput('always-auth');