Merge remote-tracking branch 'upstream/main' into feature/corepack

This commit is contained in:
Jacob Parish 2023-12-14 10:26:52 -06:00
commit 802542be35
8 changed files with 1825 additions and 1739 deletions

View File

@ -25,7 +25,7 @@ See [action.yml](action.yml)
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
node-version: ''
# File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
# If node-version and node-version-file are both provided the action will use version from node-version.
node-version-file: ''
@ -103,12 +103,12 @@ The `node-version` input supports the Semantic Versioning Specification, for mor
Examples:
- Major versions: `14`, `16`, `18`
- Major versions: `16`, `18`, `20`
- More specific versions: `10.15`, `16.15.1` , `18.4.0`
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n`
- Latest release: `*` or `latest`/`current`/`node`
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
`current`/`latest`/`node` always resolve to the latest [dist version](https://nodejs.org/dist/index.json).
That version is then downloaded from actions/node-versions if possible, or directly from Node.js if not.

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

@ -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, .tool-versions.'
description: 'File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.'
architecture:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest:

View File

@ -82953,11 +82953,20 @@ process.on('uncaughtException', e => {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${e.message}`);
});
function run() {
// Added early exit to resolve issue with slow post action step:
function run(earlyExit) {
return __awaiter(this, void 0, void 0, function* () {
try {
const cacheLock = core.getState(constants_1.State.CachePackageManager);
if (cacheLock) {
yield cachePackages(cacheLock);
if (earlyExit) {
process.exit(0);
}
}
else {
core.debug(`Caching for '${cacheLock}' is not supported`);
}
}
catch (error) {
core.setFailed(error.message);
@ -82990,7 +82999,7 @@ const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, func
}
core.info(`Cache saved with the key: ${primaryKey}`);
});
run();
run(true);
/***/ }),
@ -83329,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;
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 = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
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');

28
dist/setup/index.js vendored
View File

@ -93730,7 +93730,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;
@ -93785,9 +93791,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;
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 = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
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

@ -12,10 +12,20 @@ process.on('uncaughtException', e => {
core.info(`${warningPrefix}${e.message}`);
});
export async function run() {
// Added early exit to resolve issue with slow post action step:
export async function run(earlyExit?: boolean) {
try {
const cacheLock = core.getState(State.CachePackageManager);
if (cacheLock) {
await cachePackages(cacheLock);
if (earlyExit) {
process.exit(0);
}
} else {
core.debug(`Caching for '${cacheLock}' is not supported`);
}
} catch (error) {
core.setFailed((error as Error).message);
}
@ -58,4 +68,4 @@ const cachePackages = async (packageManager: string) => {
core.info(`Cache saved with the key: ${primaryKey}`);
};
run();
run(true);

View File

@ -112,7 +112,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');
}