mirror of
https://github.com/actions/setup-node.git
synced 2025-06-30 22:53:50 +00:00
Merge remote-tracking branch 'upstream/main' into feature/corepack
This commit is contained in:
commit
802542be35
8 changed files with 1825 additions and 1739 deletions
|
@ -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);
|
||||
await cachePackages(cacheLock);
|
||||
|
||||
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);
|
||||
|
|
12
src/main.ts
12
src/main.ts
|
@ -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}`);
|
||||
}
|
||||
|
|
24
src/util.ts
24
src/util.ts
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue