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 # Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
node-version: '' 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. # If node-version and node-version-file are both provided the action will use version from node-version.
node-version-file: '' node-version-file: ''
@ -103,12 +103,12 @@ The `node-version` input supports the Semantic Versioning Specification, for mor
Examples: Examples:
- Major versions: `14`, `16`, `18` - Major versions: `16`, `18`, `20`
- More specific versions: `10.15`, `16.15.1` , `18.4.0` - More specific versions: `10.15`, `16.15.1` , `18.4.0`
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n` - NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n`
- Latest release: `*` or `latest`/`current`/`node` - 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). `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. 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'} ${' 14.1.0 '} | ${'14.1.0'}
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'} ${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'} ${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{}'} | ${null}
`.it('parses "$contents"', ({contents, expected}) => { `.it('parses "$contents"', ({contents, expected}) => {
expect(util.parseNodeVersionFile(contents)).toBe(expected); expect(util.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, .tool-versions.' description: 'File containing the version Spec of the version to use. Examples: package.json, .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

@ -82953,11 +82953,20 @@ process.on('uncaughtException', e => {
const warningPrefix = '[warning]'; const warningPrefix = '[warning]';
core.info(`${warningPrefix}${e.message}`); 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* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const cacheLock = core.getState(constants_1.State.CachePackageManager); const cacheLock = core.getState(constants_1.State.CachePackageManager);
yield cachePackages(cacheLock); if (cacheLock) {
yield cachePackages(cacheLock);
if (earlyExit) {
process.exit(0);
}
}
else {
core.debug(`Caching for '${cacheLock}' is not supported`);
}
} }
catch (error) { catch (error) {
core.setFailed(error.message); 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}`); core.info(`Cache saved with the key: ${primaryKey}`);
}); });
run(); run(true);
/***/ }), /***/ }),
@ -83329,9 +83338,25 @@ function parseNodeVersionFile(contents) {
let nodeVersion; let nodeVersion;
// Try parsing the file as an NPM `package.json` file. // Try parsing the file as an NPM `package.json` file.
try { try {
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node; const manifest = JSON.parse(contents);
if (!nodeVersion) // JSON can parse numbers, but that's handled later
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node; 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) { catch (_d) {
core.info('Node version file is not JSON file'); core.info('Node version file is not JSON file');

30
dist/setup/index.js vendored
View file

@ -93730,7 +93730,13 @@ function resolveVersionInput() {
if (!fs_1.default.existsSync(versionFilePath)) { if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`); 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}`); core.info(`Resolved ${versionFileInput} as ${version}`);
} }
return version; return version;
@ -93785,9 +93791,25 @@ function parseNodeVersionFile(contents) {
let nodeVersion; let nodeVersion;
// Try parsing the file as an NPM `package.json` file. // Try parsing the file as an NPM `package.json` file.
try { try {
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node; const manifest = JSON.parse(contents);
if (!nodeVersion) // JSON can parse numbers, but that's handled later
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node; 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) { catch (_d) {
core.info('Node version file is not JSON file'); core.info('Node version file is not JSON file');

View file

@ -12,10 +12,20 @@ process.on('uncaughtException', e => {
core.info(`${warningPrefix}${e.message}`); 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 { try {
const cacheLock = core.getState(State.CachePackageManager); const cacheLock = core.getState(State.CachePackageManager);
await cachePackages(cacheLock);
if (cacheLock) {
await cachePackages(cacheLock);
if (earlyExit) {
process.exit(0);
}
} else {
core.debug(`Caching for '${cacheLock}' is not supported`);
}
} catch (error) { } catch (error) {
core.setFailed((error as Error).message); core.setFailed((error as Error).message);
} }
@ -58,4 +68,4 @@ const cachePackages = async (packageManager: string) => {
core.info(`Cache saved with the key: ${primaryKey}`); 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}`); core.info(`Resolved ${versionFileInput} as ${version}`);
} }

View file

@ -1,13 +1,31 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
export function parseNodeVersionFile(contents: string): string { export function parseNodeVersionFile(contents: string): string | null {
let nodeVersion: string | undefined; let nodeVersion: string | undefined;
// Try parsing the file as an NPM `package.json` file. // Try parsing the file as an NPM `package.json` file.
try { try {
nodeVersion = JSON.parse(contents).volta?.node; const manifest = JSON.parse(contents);
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
// 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 { } catch {
core.info('Node version file is not JSON file'); core.info('Node version file is not JSON file');
} }