Fix node-version-file interprets entire package.json as a version (#865)
Some checks failed
Basic validation / Basic validation (push) Failing after 3s
Check dist / Check dist/ (push) Failing after 3s
CodeQL analysis / CodeQL analysis (push) Failing after 3s
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 49s
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 10s
e2e-cache / Test yarn subprojects all locally managed (14) (push) Failing after 14s
e2e-cache / Test yarn subprojects (16) (push) Failing after 14s
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, ubuntu-latest) (push) Failing after 55s
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 1m0s
e2e-cache / Test yarn subprojects (12) (push) Failing after 56s
e2e-cache / Test yarn subprojects (14) (push) Failing after 15s
e2e-cache / Test yarn subprojects all locally managed (12) (push) Failing after 14s
e2e-cache / Test yarn subprojects some locally managed (14) (push) Failing after 28s
e2e-cache / Test yarn subprojects managed by git (12) (push) Failing after 25s
e2e-cache / Test yarn subprojects some locally managed (16) (push) Failing after 19s
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 10s
e2e-cache / Test yarn subprojects managed by git (16) (push) Failing after 6m33s
e2e-cache / Test yarn subprojects managed by git (14) (push) Failing after 6m44s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, ubuntu-latest) (push) Failing after 10m45s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 10m42s
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, ubuntu-latest) (push) Failing after 10m42s
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 10m39s
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 10m37s
e2e-cache / Test yarn subprojects all locally managed (16) (push) Failing after 10m29s
e2e-cache / Test yarn subprojects some locally managed (12) (push) Failing after 10m26s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 36m17s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled

This commit is contained in:
NullVoxPopuli 2023-12-14 07:53:26 -05:00 committed by GitHub
parent 7247617371
commit b39b52d121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 11 deletions

View File

@ -101,6 +101,7 @@ describe('main tests', () => {
${' 14.1.0 '} | ${'14.1.0'}
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{}'} | ${null}
`.it('parses "$contents"', ({contents, expected}) => {
expect(util.parseNodeVersionFile(contents)).toBe(expected);
});

View File

@ -83338,9 +83338,25 @@ function parseNodeVersionFile(contents) {
let nodeVersion;
// Try parsing the file as an NPM `package.json` file.
try {
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
nodeVersion = (_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node;
// if contents are an object, we parsed JSON
// this can happen if node-version-file is a package.json
// yet contains no volta.node or engines.node
//
// if node-version file is _not_ json, control flow
// will not have reached these lines.
//
// And because we've reached here, we know the contents
// *are* JSON, so no further string parsing makes sense.
if (!nodeVersion) {
return null;
}
}
}
catch (_d) {
core.info('Node version file is not JSON file');

30
dist/setup/index.js vendored
View File

@ -93728,7 +93728,13 @@ function resolveVersionInput() {
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
version = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
const parsedVersion = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
if (parsedVersion) {
version = parsedVersion;
}
else {
core.warning(`Could not determine node version from ${versionFilePath}. Falling back`);
}
core.info(`Resolved ${versionFileInput} as ${version}`);
}
return version;
@ -93783,9 +93789,25 @@ function parseNodeVersionFile(contents) {
let nodeVersion;
// Try parsing the file as an NPM `package.json` file.
try {
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
nodeVersion = (_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node;
// if contents are an object, we parsed JSON
// this can happen if node-version-file is a package.json
// yet contains no volta.node or engines.node
//
// if node-version file is _not_ json, control flow
// will not have reached these lines.
//
// And because we've reached here, we know the contents
// *are* JSON, so no further string parsing makes sense.
if (!nodeVersion) {
return null;
}
}
}
catch (_d) {
core.info('Node version file is not JSON file');

View File

@ -105,7 +105,17 @@ function resolveVersionInput(): string {
);
}
version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
const parsedVersion = parseNodeVersionFile(
fs.readFileSync(versionFilePath, 'utf8')
);
if (parsedVersion) {
version = parsedVersion;
} else {
core.warning(
`Could not determine node version from ${versionFilePath}. Falling back`
);
}
core.info(`Resolved ${versionFileInput} as ${version}`);
}

View File

@ -1,13 +1,31 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
export function parseNodeVersionFile(contents: string): string {
export function parseNodeVersionFile(contents: string): string | null {
let nodeVersion: string | undefined;
// Try parsing the file as an NPM `package.json` file.
try {
nodeVersion = JSON.parse(contents).volta?.node;
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
nodeVersion = manifest.volta?.node;
if (!nodeVersion) nodeVersion = manifest.engines?.node;
// if contents are an object, we parsed JSON
// this can happen if node-version-file is a package.json
// yet contains no volta.node or engines.node
//
// if node-version file is _not_ json, control flow
// will not have reached these lines.
//
// And because we've reached here, we know the contents
// *are* JSON, so no further string parsing makes sense.
if (!nodeVersion) {
return null;
}
}
} catch {
core.info('Node version file is not JSON file');
}