mirror of
https://github.com/actions/setup-node
synced 2026-12-04 15:01:27 +08:00
e2e-cache / Test npm (Node 22, ubuntu-latest) (push) Successful in 2m24s
e2e-cache / Test npm (Node 24, ubuntu-latest) (push) Successful in 1m34s
e2e-cache / Test npm (Node 26, ubuntu-latest) (push) Successful in 1m45s
e2e-cache / Test pnpm (Node 22, ubuntu-latest) (push) Failing after 32s
e2e-cache / Test pnpm (Node 24, ubuntu-latest) (push) Failing after 29s
e2e-cache / Test pnpm (Node 26, ubuntu-latest) (push) Failing after 28s
e2e-cache / Test yarn 1 (Node 22, ubuntu-latest) (push) Failing after 1m5s
e2e-cache / Test yarn 1 (Node 24, ubuntu-latest) (push) Failing after 1m10s
e2e-cache / Test yarn 1 (Node 26, ubuntu-latest) (push) Failing after 1m9s
e2e-cache / Test yarn 3 (Node 22, ubuntu-latest) (push) Failing after 1m36s
e2e-cache / Test yarn 3 (Node 24, ubuntu-latest) (push) Failing after 6m49s
e2e-cache / Test yarn 3 (Node 26, ubuntu-latest) (push) Failing after 2m16s
e2e-cache / Test yarn subprojects (22) (push) Successful in 1m38s
e2e-cache / Test yarn subprojects (24) (push) Successful in 1m34s
e2e-cache / Test yarn subprojects (26) (push) Successful in 1m33s
e2e-cache / Test yarn subprojects all locally managed (22) (push) Failing after 6m46s
e2e-cache / Test yarn subprojects all locally managed (24) (push) Failing after 7m1s
e2e-cache / Test yarn subprojects all locally managed (26) (push) Failing after 1m35s
e2e-cache / Test yarn subprojects some locally managed (22) (push) Failing after 31s
e2e-cache / Test yarn subprojects some locally managed (24) (push) Failing after 1m35s
e2e-cache / Test yarn subprojects some locally managed (26) (push) Failing after 31s
e2e-cache / Test yarn subprojects managed by git (22) (push) Successful in 1m29s
e2e-cache / Test yarn subprojects managed by git (24) (push) Successful in 1m40s
e2e-cache / Test yarn subprojects managed by git (26) (push) Failing after 6m57s
e2e-cache / Test auto cache with top-level packageManager (22, ubuntu-latest) (push) Successful in 57s
e2e-cache / Test auto cache with top-level packageManager (24, ubuntu-latest) (push) Successful in 55s
e2e-cache / Test auto cache with top-level packageManager (26, ubuntu-latest) (push) Successful in 56s
e2e-cache / Test auto cache with devEngines.packageManager (22, ubuntu-latest) (push) Successful in 56s
e2e-cache / Test auto cache with devEngines.packageManager (24, ubuntu-latest) (push) Successful in 56s
e2e-cache / Test auto cache with devEngines.packageManager (26, ubuntu-latest) (push) Successful in 58s
proxy / test-proxy (push) Failing after 1s
proxy / test-bypass-proxy (push) Failing after 1m0s
versions / local-cache (22, ubuntu-latest) (push) Successful in 16s
versions / local-cache (24, ubuntu-latest) (push) Successful in 11s
versions / local-cache (26, ubuntu-latest) (push) Successful in 11s
versions / lts-syntax (lts/*, ubuntu-latest) (push) Failing after 10s
versions / lts-syntax (lts/-1, ubuntu-latest) (push) Failing after 10s
versions / v8-canary-syntax (26-v8-canary, ubuntu-latest) (push) Successful in 23s
versions / v8-canary-syntax (26.0.0-v8-canary, ubuntu-latest) (push) Successful in 12s
versions / v8-canary-syntax (26.0.0-v8-canary20251016054584e5cf, ubuntu-latest) (push) Successful in 21s
versions / nightly-syntax (24.0.0-nightly, ubuntu-latest) (push) Successful in 28s
versions / nightly-syntax (25-nightly, ubuntu-latest) (push) Successful in 21s
versions / nightly-syntax (26-nightly, ubuntu-latest) (push) Successful in 23s
versions / rc-syntax (22.14.0-rc.1, ubuntu-latest) (push) Successful in 21s
versions / rc-syntax (24.0.0-rc.4, ubuntu-latest) (push) Successful in 7m40s
versions / rc-syntax (26.0.0-rc.1, ubuntu-latest) (push) Failing after 1m35s
versions / manifest (22.0.0, ubuntu-latest) (push) Failing after 4m45s
versions / manifest (24.9.0, ubuntu-latest) (push) Failing after 47s
versions / manifest (26.5.0, ubuntu-latest) (push) Failing after 39s
versions / check-latest (22, ubuntu-latest) (push) Failing after 2m0s
versions / check-latest (24, ubuntu-latest) (push) Failing after 2m1s
versions / check-latest (26, ubuntu-latest) (push) Failing after 1m35s
versions / allow-alpha (27, ubuntu-latest) (push) Failing after 40s
versions / allow-alpha (27.0.0, ubuntu-latest) (push) Failing after 31s
versions / version-file (.nvmrc, ubuntu-latest) (push) Failing after 1m38s
versions / version-file (.tool-versions, ubuntu-latest) (push) Failing after 39s
versions / version-file (.tool-versions-node, ubuntu-latest) (push) Failing after 40s
versions / version-file (mise.toml, ubuntu-latest) (push) Failing after 40s
versions / version-file (package.json, ubuntu-latest) (push) Failing after 1m40s
versions / version-file-dev-engines (ubuntu-latest) (push) Failing after 6m48s
versions / version-file-volta (ubuntu-latest) (push) Failing after 1m35s
versions / version-file-volta-extends (ubuntu-latest) (push) Failing after 1m36s
versions / node-dist (21, ubuntu-latest) (push) Failing after 6m50s
versions / node-dist (23, ubuntu-latest) (push) Failing after 39s
versions / old-versions (ubuntu-latest) (push) Failing after 41s
versions / node-latest-aliases (current, ubuntu-latest) (push) Failing after 11s
versions / node-latest-aliases (latest, ubuntu-latest) (push) Failing after 7s
versions / node-latest-aliases (node, ubuntu-latest) (push) Failing after 2s
e2e-cache / Test npm (Node 22, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test npm (Node 22, macos-latest) (push) Canceled after 0s
e2e-cache / Test npm (Node 22, windows-latest) (push) Canceled after 0s
e2e-cache / Test npm (Node 24, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test npm (Node 24, macos-latest) (push) Canceled after 0s
e2e-cache / Test npm (Node 24, windows-latest) (push) Canceled after 0s
e2e-cache / Test npm (Node 26, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test npm (Node 26, macos-latest) (push) Canceled after 0s
e2e-cache / Test npm (Node 26, windows-latest) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 22, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 22, macos-latest) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 22, windows-latest) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 24, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 24, macos-latest) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 24, windows-latest) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 26, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 26, macos-latest) (push) Canceled after 0s
e2e-cache / Test pnpm (Node 26, windows-latest) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 22, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 22, macos-latest) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 22, windows-latest) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 24, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 24, macos-latest) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 24, windows-latest) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 26, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 26, macos-latest) (push) Canceled after 0s
e2e-cache / Test yarn 1 (Node 26, windows-latest) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 22, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 22, macos-latest) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 22, windows-latest) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 24, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 24, macos-latest) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 24, windows-latest) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 26, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 26, macos-latest) (push) Canceled after 0s
e2e-cache / Test yarn 3 (Node 26, windows-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (22, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (22, macos-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (22, windows-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (24, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (24, macos-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (24, windows-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (26, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (26, macos-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with top-level packageManager (26, windows-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (22, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (22, macos-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (22, windows-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (24, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (24, macos-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (24, windows-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (26, macos-15-intel) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (26, macos-latest) (push) Canceled after 0s
e2e-cache / Test auto cache with devEngines.packageManager (26, windows-latest) (push) Canceled after 0s
versions / local-cache (22, macos-15-intel) (push) Canceled after 0s
versions / local-cache (22, macos-latest) (push) Canceled after 0s
versions / local-cache (22, windows-latest) (push) Canceled after 0s
versions / local-cache (24, macos-15-intel) (push) Canceled after 0s
versions / local-cache (24, macos-latest) (push) Canceled after 0s
versions / local-cache (24, windows-latest) (push) Canceled after 0s
versions / local-cache (26, macos-15-intel) (push) Canceled after 0s
versions / local-cache (26, macos-latest) (push) Canceled after 0s
versions / local-cache (26, windows-latest) (push) Canceled after 0s
versions / lts-syntax (lts/*, macos-15-intel) (push) Canceled after 0s
versions / lts-syntax (lts/*, windows-latest) (push) Canceled after 0s
versions / lts-syntax (lts/-1, macos-15-intel) (push) Canceled after 0s
versions / lts-syntax (lts/-1, windows-latest) (push) Canceled after 0s
versions / v8-canary-syntax (26-v8-canary, macos-15-intel) (push) Canceled after 0s
versions / v8-canary-syntax (26-v8-canary, macos-latest) (push) Canceled after 0s
versions / v8-canary-syntax (26-v8-canary, windows-latest) (push) Canceled after 0s
versions / v8-canary-syntax (26.0.0-v8-canary, macos-15-intel) (push) Canceled after 0s
versions / v8-canary-syntax (26.0.0-v8-canary, macos-latest) (push) Canceled after 0s
versions / v8-canary-syntax (26.0.0-v8-canary, windows-latest) (push) Canceled after 0s
versions / v8-canary-syntax (26.0.0-v8-canary20251016054584e5cf, macos-15-intel) (push) Canceled after 0s
versions / v8-canary-syntax (26.0.0-v8-canary20251016054584e5cf, macos-latest) (push) Canceled after 0s
versions / v8-canary-syntax (26.0.0-v8-canary20251016054584e5cf, windows-latest) (push) Canceled after 0s
versions / nightly-syntax (24.0.0-nightly, macos-15-intel) (push) Canceled after 0s
versions / nightly-syntax (24.0.0-nightly, macos-latest) (push) Canceled after 0s
versions / nightly-syntax (24.0.0-nightly, windows-latest) (push) Canceled after 0s
versions / nightly-syntax (25-nightly, macos-15-intel) (push) Canceled after 0s
versions / nightly-syntax (25-nightly, macos-latest) (push) Canceled after 0s
versions / nightly-syntax (25-nightly, windows-latest) (push) Canceled after 0s
versions / nightly-syntax (26-nightly, macos-15-intel) (push) Canceled after 0s
versions / nightly-syntax (26-nightly, macos-latest) (push) Canceled after 0s
versions / nightly-syntax (26-nightly, windows-latest) (push) Canceled after 0s
versions / rc-syntax (22.14.0-rc.1, macos-15-intel) (push) Canceled after 0s
versions / rc-syntax (22.14.0-rc.1, macos-latest) (push) Canceled after 0s
versions / rc-syntax (22.14.0-rc.1, windows-latest) (push) Canceled after 0s
versions / rc-syntax (24.0.0-rc.4, macos-15-intel) (push) Canceled after 0s
versions / rc-syntax (24.0.0-rc.4, macos-latest) (push) Canceled after 0s
versions / rc-syntax (24.0.0-rc.4, windows-latest) (push) Canceled after 0s
versions / rc-syntax (26.0.0-rc.1, macos-15-intel) (push) Canceled after 0s
versions / rc-syntax (26.0.0-rc.1, macos-latest) (push) Canceled after 0s
versions / rc-syntax (26.0.0-rc.1, windows-latest) (push) Canceled after 0s
versions / manifest (22.0.0, macos-15-intel) (push) Canceled after 0s
versions / manifest (22.0.0, macos-latest) (push) Canceled after 0s
versions / manifest (22.0.0, windows-latest) (push) Canceled after 0s
versions / manifest (24.9.0, macos-15-intel) (push) Canceled after 0s
versions / manifest (24.9.0, macos-latest) (push) Canceled after 0s
versions / manifest (24.9.0, windows-latest) (push) Canceled after 0s
versions / manifest (26.5.0, macos-15-intel) (push) Canceled after 0s
versions / manifest (26.5.0, macos-latest) (push) Canceled after 0s
versions / manifest (26.5.0, windows-latest) (push) Canceled after 0s
versions / check-latest (22, macos-15-intel) (push) Canceled after 0s
versions / check-latest (22, macos-latest) (push) Canceled after 0s
versions / check-latest (22, windows-latest) (push) Canceled after 0s
versions / check-latest (24, macos-15-intel) (push) Canceled after 0s
versions / check-latest (24, macos-latest) (push) Canceled after 0s
versions / check-latest (24, windows-latest) (push) Canceled after 0s
versions / check-latest (26, macos-15-intel) (push) Canceled after 0s
versions / check-latest (26, macos-latest) (push) Canceled after 0s
versions / check-latest (26, windows-latest) (push) Canceled after 0s
versions / allow-alpha (27, macos-latest) (push) Canceled after 0s
versions / allow-alpha (27, windows-latest) (push) Canceled after 0s
versions / allow-alpha (27.0.0, macos-latest) (push) Canceled after 0s
versions / allow-alpha (27.0.0, windows-latest) (push) Canceled after 0s
versions / version-file (.nvmrc, macos-15-intel) (push) Canceled after 0s
versions / version-file (.nvmrc, macos-latest) (push) Canceled after 0s
versions / version-file (.nvmrc, windows-latest) (push) Canceled after 0s
versions / version-file (.tool-versions, macos-15-intel) (push) Canceled after 0s
versions / version-file (.tool-versions, macos-latest) (push) Canceled after 0s
versions / version-file (.tool-versions, windows-latest) (push) Canceled after 0s
versions / version-file (.tool-versions-node, macos-15-intel) (push) Canceled after 0s
versions / version-file (.tool-versions-node, macos-latest) (push) Canceled after 0s
versions / version-file (.tool-versions-node, windows-latest) (push) Canceled after 0s
versions / version-file (mise.toml, macos-15-intel) (push) Canceled after 0s
versions / version-file (mise.toml, macos-latest) (push) Canceled after 0s
versions / version-file (mise.toml, windows-latest) (push) Canceled after 0s
versions / version-file (package.json, macos-15-intel) (push) Canceled after 0s
versions / version-file (package.json, macos-latest) (push) Canceled after 0s
versions / version-file (package.json, windows-latest) (push) Canceled after 0s
versions / version-file-dev-engines (macos-latest) (push) Canceled after 0s
versions / version-file-dev-engines (windows-latest) (push) Canceled after 0s
versions / version-file-volta (macos-15-intel) (push) Canceled after 0s
versions / version-file-volta (macos-latest) (push) Canceled after 0s
versions / version-file-volta (windows-latest) (push) Canceled after 0s
versions / version-file-volta-extends (macos-15-intel) (push) Canceled after 0s
versions / version-file-volta-extends (macos-latest) (push) Canceled after 0s
versions / version-file-volta-extends (windows-latest) (push) Canceled after 0s
versions / node-dist (21, macos-15-intel) (push) Canceled after 0s
versions / node-dist (21, macos-latest) (push) Canceled after 0s
versions / node-dist (21, windows-latest) (push) Canceled after 0s
versions / node-dist (23, macos-15-intel) (push) Canceled after 0s
versions / node-dist (23, macos-latest) (push) Canceled after 0s
versions / node-dist (23, windows-latest) (push) Canceled after 0s
versions / old-versions (macos-15-intel) (push) Canceled after 0s
versions / old-versions (windows-latest) (push) Canceled after 0s
versions / arch (push) Canceled after 0s
versions / node-latest-aliases (current, macos-15-intel) (push) Canceled after 0s
versions / node-latest-aliases (current, macos-latest) (push) Canceled after 0s
versions / node-latest-aliases (current, windows-latest) (push) Canceled after 0s
versions / node-latest-aliases (latest, macos-15-intel) (push) Canceled after 0s
versions / node-latest-aliases (latest, macos-latest) (push) Canceled after 0s
versions / node-latest-aliases (latest, windows-latest) (push) Canceled after 0s
versions / node-latest-aliases (node, macos-15-intel) (push) Canceled after 0s
versions / node-latest-aliases (node, macos-latest) (push) Canceled after 0s
versions / node-latest-aliases (node, windows-latest) (push) Canceled after 0s
443 lines
14 KiB
TypeScript
443 lines
14 KiB
TypeScript
import path from 'node:path';
|
|
|
|
import * as core from '@actions/core';
|
|
import * as exec from '@actions/exec';
|
|
import * as tc from '@actions/tool-cache';
|
|
import semver from 'semver';
|
|
|
|
import BaseDistribution from '../base-distribution.js';
|
|
import {NodeInputs, INodeVersion, INodeVersionInfo} from '../base-models.js';
|
|
|
|
interface INodeRelease extends tc.IToolRelease {
|
|
lts?: string;
|
|
}
|
|
|
|
const nodeVersionsManifestUrl =
|
|
'https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json';
|
|
const invalidManifestMessage =
|
|
'The manifest fetched is empty, truncated, or does not contain any valid tool release entries.';
|
|
|
|
function isValidManifest(manifest: unknown): manifest is tc.IToolRelease[] {
|
|
return Array.isArray(manifest) && manifest.length > 0;
|
|
}
|
|
|
|
export default class OfficialBuilds extends BaseDistribution {
|
|
constructor(nodeInfo: NodeInputs) {
|
|
super(nodeInfo);
|
|
}
|
|
|
|
public async setupNodeJs() {
|
|
let manifest: tc.IToolRelease[] | undefined;
|
|
let nodeJsVersions: INodeVersion[] | undefined;
|
|
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
|
|
|
if (this.isLtsAlias(this.nodeInfo.versionSpec)) {
|
|
core.info('Attempt to resolve LTS alias from manifest...');
|
|
|
|
// No try-catch since it's not possible to resolve LTS alias without manifest
|
|
manifest = await this.getManifest();
|
|
|
|
this.nodeInfo.versionSpec = this.resolveLtsAliasFromManifest(
|
|
this.nodeInfo.versionSpec,
|
|
this.nodeInfo.stable,
|
|
manifest
|
|
);
|
|
}
|
|
|
|
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
|
nodeJsVersions = await this.getNodeJsVersions();
|
|
const versions = this.filterVersions(nodeJsVersions);
|
|
this.nodeInfo.versionSpec = this.evaluateVersions(versions);
|
|
|
|
core.info('getting latest node version...');
|
|
}
|
|
|
|
if (this.nodeInfo.checkLatest) {
|
|
core.info('Attempt to resolve the latest version from manifest...');
|
|
let resolvedVersion: string | undefined;
|
|
try {
|
|
manifest ??= await this.getManifest();
|
|
const info = await this.getInfoFromManifest(
|
|
this.nodeInfo.versionSpec,
|
|
this.nodeInfo.stable,
|
|
osArch,
|
|
manifest
|
|
);
|
|
resolvedVersion = info?.resolvedVersion;
|
|
} catch (error) {
|
|
core.info('Unable to resolve version from manifest...');
|
|
core.debug((error as Error).message);
|
|
}
|
|
if (resolvedVersion) {
|
|
this.nodeInfo.versionSpec = resolvedVersion;
|
|
core.info(`Resolved as '${resolvedVersion}'`);
|
|
} else {
|
|
core.info(
|
|
`Failed to resolve version ${this.nodeInfo.versionSpec} from manifest`
|
|
);
|
|
}
|
|
}
|
|
|
|
let toolPath = this.findVersionInHostedToolCacheDirectory();
|
|
|
|
if (toolPath) {
|
|
core.info(`Found in cache @ ${toolPath}`);
|
|
const installedDir = toolPath;
|
|
this.addToolPath(toolPath);
|
|
await this.verifyNodeVersion(installedDir);
|
|
return;
|
|
}
|
|
|
|
let downloadPath = '';
|
|
try {
|
|
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
|
|
|
const versionInfo = await this.getInfoFromManifest(
|
|
this.nodeInfo.versionSpec,
|
|
this.nodeInfo.stable,
|
|
osArch,
|
|
manifest
|
|
);
|
|
|
|
if (versionInfo) {
|
|
core.info(
|
|
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
|
|
);
|
|
downloadPath = await tc.downloadTool(
|
|
versionInfo.downloadUrl,
|
|
undefined,
|
|
this.nodeInfo.auth
|
|
);
|
|
|
|
if (downloadPath) {
|
|
toolPath = await this.extractArchive(
|
|
downloadPath,
|
|
versionInfo,
|
|
false
|
|
);
|
|
}
|
|
} else {
|
|
core.info(
|
|
`Not found in manifest. Falling back to download directly from ${
|
|
this.nodeInfo.mirror || 'Node'
|
|
}`
|
|
);
|
|
}
|
|
} catch (err) {
|
|
// Rate limit?
|
|
if (
|
|
err instanceof tc.HTTPError &&
|
|
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
|
|
) {
|
|
core.info(
|
|
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
|
|
);
|
|
} else {
|
|
core.info((err as Error).message);
|
|
}
|
|
core.debug((err as Error).stack ?? 'empty stack');
|
|
core.info('Falling back to download directly from Node');
|
|
}
|
|
|
|
if (!toolPath) {
|
|
toolPath = await this.downloadDirectlyFromNode(nodeJsVersions);
|
|
}
|
|
|
|
const installedDir = toolPath;
|
|
if (this.osPlat != 'win32') {
|
|
toolPath = path.join(toolPath, 'bin');
|
|
}
|
|
|
|
core.addPath(toolPath);
|
|
await this.verifyNodeVersion(installedDir);
|
|
}
|
|
|
|
protected addToolPath(toolPath: string) {
|
|
if (this.osPlat != 'win32') {
|
|
toolPath = path.join(toolPath, 'bin');
|
|
}
|
|
|
|
core.addPath(toolPath);
|
|
}
|
|
|
|
protected async downloadDirectlyFromNode(nodeJsVersions?: INodeVersion[]) {
|
|
nodeJsVersions ??= await this.getNodeJsVersions();
|
|
const versions = this.filterVersions(nodeJsVersions);
|
|
const evaluatedVersion = this.evaluateVersions(versions);
|
|
|
|
if (!evaluatedVersion) {
|
|
let message = `Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`;
|
|
if (!this.nodeInfo.allowAlpha && this.findAlphaVersion(versions)) {
|
|
message += ` A matching alpha release is available; set 'allow-alpha: true' to use it.`;
|
|
}
|
|
throw new Error(message);
|
|
}
|
|
|
|
// The tool cache cannot match prereleases against a range such as `27`, so reuse a cached alpha here.
|
|
if (semver.prerelease(evaluatedVersion)) {
|
|
const cachedPath = tc.find(
|
|
'node',
|
|
evaluatedVersion,
|
|
this.translateArchToDistUrl(this.nodeInfo.arch)
|
|
);
|
|
if (cachedPath) {
|
|
core.info(`Found in cache @ ${cachedPath}`);
|
|
return cachedPath;
|
|
}
|
|
}
|
|
|
|
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
|
|
|
try {
|
|
const toolPath = await this.downloadNodejs(toolName);
|
|
return toolPath;
|
|
} catch (error) {
|
|
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
|
|
core.warning(
|
|
`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
|
|
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
|
|
'To resolve this issue you may either fall back to the older version or try again later.'
|
|
);
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
protected evaluateVersions(versions: string[]): string {
|
|
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
|
core.info(`getting latest node version...`);
|
|
|
|
const stableVersion = versions.find(
|
|
potential => semver.prerelease(potential) === null
|
|
);
|
|
|
|
if (!stableVersion) {
|
|
throw new Error(
|
|
`Unable to find a stable Node version for '${this.nodeInfo.versionSpec}' on platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
|
|
);
|
|
}
|
|
|
|
return stableVersion;
|
|
}
|
|
|
|
const version = super.evaluateVersions(versions);
|
|
if (version || !this.nodeInfo.allowAlpha) {
|
|
return version;
|
|
}
|
|
|
|
// Only fall back to an alpha when no stable release matches the spec.
|
|
const alphaVersion = this.findAlphaVersion(versions);
|
|
if (alphaVersion) {
|
|
core.info(
|
|
`No stable release matches '${this.nodeInfo.versionSpec}', using ${alphaVersion}`
|
|
);
|
|
}
|
|
|
|
return alphaVersion;
|
|
}
|
|
|
|
// Alphas are matched by their release version, so `27.0.0` or `^27.0.0` select `27.0.0-alpha.*`.
|
|
// Ranges with explicit prerelease bounds are already handled by standard semver.
|
|
private findAlphaVersion(versions: string[]): string {
|
|
const {range} = this.validRange(this.nodeInfo.versionSpec);
|
|
if (!semver.validRange(range) || this.hasPrereleaseBound(range)) {
|
|
return '';
|
|
}
|
|
|
|
return (
|
|
versions.find(potential => {
|
|
const parsed = semver.parse(potential);
|
|
return (
|
|
parsed?.prerelease[0] === 'alpha' &&
|
|
semver.satisfies(
|
|
`${parsed.major}.${parsed.minor}.${parsed.patch}`,
|
|
range
|
|
)
|
|
);
|
|
}) ?? ''
|
|
);
|
|
}
|
|
|
|
private hasPrereleaseBound(range: string): boolean {
|
|
// semver desugars `27`, `^27.0.0`, etc. into an upper bound such as `<28.0.0-0`; ignore that synthetic `-0`.
|
|
return new semver.Range(range).set.some(comparators =>
|
|
comparators.some(({operator, semver: bound}) => {
|
|
const prerelease = bound.prerelease ?? [];
|
|
const isSyntheticUpperBound =
|
|
operator === '<' && prerelease.length === 1 && prerelease[0] === 0;
|
|
return prerelease.length > 0 && !isSyntheticUpperBound;
|
|
})
|
|
);
|
|
}
|
|
|
|
protected getDistributionUrl(mirror: string): string {
|
|
const url = mirror || 'https://nodejs.org';
|
|
return `${url}/dist`;
|
|
}
|
|
|
|
private async getManifest(): Promise<tc.IToolRelease[]> {
|
|
let lastError: Error | undefined;
|
|
const maxAttempts = 3;
|
|
core.debug('Getting manifest from actions/node-versions@main');
|
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
try {
|
|
const manifest = await tc.getManifestFromRepo(
|
|
'actions',
|
|
'node-versions',
|
|
this.nodeInfo.auth,
|
|
'main'
|
|
);
|
|
if (isValidManifest(manifest)) {
|
|
return manifest;
|
|
}
|
|
lastError = new Error(invalidManifestMessage);
|
|
} catch (error) {
|
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
const status = (error as {statusCode?: number})?.statusCode;
|
|
if (status === 403 || status === 429) {
|
|
core.debug(
|
|
`GitHub API returned HTTP ${status}; trying raw manifest.`
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
core.debug(
|
|
`Attempt ${attempt}/${maxAttempts} to fetch the manifest failed: ${lastError.message}`
|
|
);
|
|
if (attempt < maxAttempts) {
|
|
core.info('Retrying to fetch the manifest...');
|
|
await new Promise(resolve =>
|
|
setTimeout(resolve, 1000 * 2 ** (attempt - 1))
|
|
);
|
|
}
|
|
}
|
|
|
|
core.debug(`GitHub API manifest fetch failed: ${lastError?.message}`);
|
|
core.debug(`Getting manifest from ${nodeVersionsManifestUrl}`);
|
|
try {
|
|
const {result} = await this.httpClient.getJson<tc.IToolRelease[]>(
|
|
nodeVersionsManifestUrl
|
|
);
|
|
if (!isValidManifest(result)) {
|
|
throw new Error(invalidManifestMessage);
|
|
}
|
|
return result;
|
|
} catch (error) {
|
|
const message = (error as Error).message;
|
|
throw new Error(
|
|
`Failed to fetch a valid manifest from the GitHub API and raw URL. API: ${lastError?.message}. Raw: ${message}`,
|
|
{cause: error}
|
|
);
|
|
}
|
|
}
|
|
|
|
private resolveLtsAliasFromManifest(
|
|
versionSpec: string,
|
|
stable: boolean,
|
|
manifest: INodeRelease[]
|
|
): string {
|
|
const alias = versionSpec.split('lts/')[1]?.toLowerCase();
|
|
|
|
if (!alias) {
|
|
throw new Error(
|
|
`Unable to parse LTS alias for Node version '${versionSpec}'`
|
|
);
|
|
}
|
|
|
|
core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`);
|
|
|
|
// Supported formats are `lts/<alias>`, `lts/*`, and `lts/-n`. Where asterisk means highest possible LTS and -n means the nth-highest.
|
|
const n = Number(alias);
|
|
const aliases = Object.fromEntries(
|
|
manifest
|
|
.filter(x => x.lts && x.stable === stable)
|
|
.map(x => [x.lts!.toLowerCase(), x])
|
|
.reverse()
|
|
);
|
|
const numbered = Object.values(aliases);
|
|
const release =
|
|
alias === '*'
|
|
? numbered[numbered.length - 1]
|
|
: n < 0
|
|
? numbered[numbered.length - 1 + n]
|
|
: aliases[alias];
|
|
|
|
if (!release) {
|
|
throw new Error(
|
|
`Unable to find LTS release '${alias}' for Node version '${versionSpec}'.`
|
|
);
|
|
}
|
|
|
|
core.debug(
|
|
`Found LTS release '${release.version}' for Node version '${versionSpec}'`
|
|
);
|
|
|
|
return release.version.split('.')[0];
|
|
}
|
|
|
|
private async getInfoFromManifest(
|
|
versionSpec: string,
|
|
stable: boolean,
|
|
osArch: string,
|
|
manifest: tc.IToolRelease[] | undefined
|
|
): Promise<INodeVersionInfo | null> {
|
|
let info: INodeVersionInfo | null = null;
|
|
if (!manifest) {
|
|
core.debug('No manifest cached');
|
|
manifest = await this.getManifest();
|
|
}
|
|
|
|
const rel = await tc.findFromManifest(
|
|
versionSpec,
|
|
stable,
|
|
manifest,
|
|
osArch
|
|
);
|
|
|
|
if (rel && rel.files.length > 0) {
|
|
info = <INodeVersionInfo>{};
|
|
info.resolvedVersion = rel.version;
|
|
info.arch = rel.files[0].arch;
|
|
info.downloadUrl = rel.files[0].download_url;
|
|
info.fileName = rel.files[0].filename;
|
|
}
|
|
|
|
return info;
|
|
}
|
|
|
|
private isLtsAlias(versionSpec: string): boolean {
|
|
return versionSpec.startsWith('lts/');
|
|
}
|
|
|
|
private isLatestSyntax(versionSpec): boolean {
|
|
return ['current', 'latest', 'node'].includes(versionSpec);
|
|
}
|
|
|
|
private async verifyNodeVersion(installedDir: string) {
|
|
// tool-cache layout: <root>/node/<version>/<arch>
|
|
const expectedVersion = 'v' + path.basename(path.dirname(installedDir));
|
|
let actualVersion = '';
|
|
try {
|
|
const {stdout} = await exec.getExecOutput('node', ['--version'], {
|
|
silent: true
|
|
});
|
|
actualVersion = stdout.trim();
|
|
} catch (err) {
|
|
throw new Error(
|
|
`Node installation failed. Node may not be installed or not on PATH: ${(err as Error).message}`,
|
|
{cause: err}
|
|
);
|
|
}
|
|
if (actualVersion !== expectedVersion) {
|
|
core.debug(
|
|
`Node installation failed: expected ${expectedVersion} but "node --version" reported ${actualVersion || '(empty)'} (installedDir: ${installedDir}).`
|
|
);
|
|
|
|
throw new Error(
|
|
`Node ${expectedVersion} installation failed, likely due to an incomplete or corrupted download.`
|
|
);
|
|
}
|
|
}
|
|
}
|