mirror of
https://github.com/actions/setup-node.git
synced 2026-06-30 10:26:41 +00:00
Compare commits
1 Commits
123d781fcd
...
320f3799ba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
320f3799ba |
@ -357,41 +357,6 @@ describe('setup-node', () => {
|
|||||||
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports when download failed but version exists', async () => {
|
|
||||||
os.platform = 'linux';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
// a version which is not in the manifest but is in node dist
|
|
||||||
const versionSpec = '11.15.0';
|
|
||||||
|
|
||||||
inputs['node-version'] = versionSpec;
|
|
||||||
inputs['always-auth'] = false;
|
|
||||||
inputs['token'] = 'faketoken';
|
|
||||||
|
|
||||||
// ... but not in the local cache
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
|
|
||||||
dlSpy.mockImplementationOnce(async () => {
|
|
||||||
throw new tc.HTTPError(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(getManifestSpy).toHaveBeenCalled();
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Attempting to download ${versionSpec}...`
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
'Not found in manifest. Falling back to download directly from Node'
|
|
||||||
);
|
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
|
||||||
`Node version ${versionSpec} for platform ${os.platform} and architecture ${os.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.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('acquires specified architecture of node', async () => {
|
it('acquires specified architecture of node', async () => {
|
||||||
for (const {arch, version, osSpec} of [
|
for (const {arch, version, osSpec} of [
|
||||||
{arch: 'x86', version: '12.16.2', osSpec: 'win32'},
|
{arch: 'x86', version: '12.16.2', osSpec: 'win32'},
|
||||||
|
|||||||
90
dist/setup/index.js
vendored
90
dist/setup/index.js
vendored
@ -72783,38 +72783,45 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||||||
let toolPath = this.findVersionInHostedToolCacheDirectory();
|
let toolPath = this.findVersionInHostedToolCacheDirectory();
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
core.info(`Found in cache @ ${toolPath}`);
|
core.info(`Found in cache @ ${toolPath}`);
|
||||||
this.addToolPath(toolPath);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
let downloadPath = '';
|
else {
|
||||||
try {
|
let downloadPath = '';
|
||||||
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
try {
|
||||||
const versionInfo = yield this.getInfoFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest);
|
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
||||||
if (versionInfo) {
|
const versionInfo = yield this.getInfoFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest);
|
||||||
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
|
if (versionInfo) {
|
||||||
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
|
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
|
||||||
if (downloadPath) {
|
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
|
||||||
toolPath = yield this.extractArchive(downloadPath, versionInfo);
|
if (downloadPath) {
|
||||||
|
toolPath = yield this.extractArchive(downloadPath, versionInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info('Not found in manifest. Falling back to download directly from Node');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
catch (err) {
|
||||||
core.info('Not found in manifest. Falling back to download directly from Node');
|
// 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.message);
|
||||||
|
}
|
||||||
|
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
|
||||||
|
core.info('Falling back to download directly from Node');
|
||||||
}
|
}
|
||||||
}
|
if (!toolPath) {
|
||||||
catch (err) {
|
const nodeJsVersions = yield this.getNodeJsVersions();
|
||||||
// Rate limit?
|
const versions = this.filterVersions(nodeJsVersions);
|
||||||
if (err instanceof tc.HTTPError &&
|
const evaluatedVersion = this.evaluateVersions(versions);
|
||||||
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
|
if (!evaluatedVersion) {
|
||||||
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
|
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
|
||||||
|
}
|
||||||
|
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
||||||
|
toolPath = yield this.downloadNodejs(toolName);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
core.info(err.message);
|
|
||||||
}
|
|
||||||
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
|
|
||||||
core.info('Falling back to download directly from Node');
|
|
||||||
}
|
|
||||||
if (!toolPath) {
|
|
||||||
toolPath = yield this.downloadDirectlyFromNode();
|
|
||||||
}
|
}
|
||||||
if (this.osPlat != 'win32') {
|
if (this.osPlat != 'win32') {
|
||||||
toolPath = path_1.default.join(toolPath, 'bin');
|
toolPath = path_1.default.join(toolPath, 'bin');
|
||||||
@ -72822,35 +72829,6 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||||||
core.addPath(toolPath);
|
core.addPath(toolPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
addToolPath(toolPath) {
|
|
||||||
if (this.osPlat != 'win32') {
|
|
||||||
toolPath = path_1.default.join(toolPath, 'bin');
|
|
||||||
}
|
|
||||||
core.addPath(toolPath);
|
|
||||||
}
|
|
||||||
downloadDirectlyFromNode() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const nodeJsVersions = yield this.getNodeJsVersions();
|
|
||||||
const versions = this.filterVersions(nodeJsVersions);
|
|
||||||
const evaluatedVersion = this.evaluateVersions(versions);
|
|
||||||
if (!evaluatedVersion) {
|
|
||||||
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
|
|
||||||
}
|
|
||||||
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
|
||||||
try {
|
|
||||||
const toolPath = yield 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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
evaluateVersions(versions) {
|
evaluateVersions(versions) {
|
||||||
let version = '';
|
let version = '';
|
||||||
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
||||||
|
|||||||
@ -18,7 +18,6 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
let manifest: tc.IToolRelease[] | undefined;
|
let manifest: tc.IToolRelease[] | undefined;
|
||||||
let nodeJsVersions: INodeVersion[] | undefined;
|
let nodeJsVersions: INodeVersion[] | undefined;
|
||||||
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||||
|
|
||||||
if (this.isLtsAlias(this.nodeInfo.versionSpec)) {
|
if (this.isLtsAlias(this.nodeInfo.versionSpec)) {
|
||||||
core.info('Attempt to resolve LTS alias from manifest...');
|
core.info('Attempt to resolve LTS alias from manifest...');
|
||||||
|
|
||||||
@ -62,57 +61,63 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
|
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
core.info(`Found in cache @ ${toolPath}`);
|
core.info(`Found in cache @ ${toolPath}`);
|
||||||
this.addToolPath(toolPath);
|
} else {
|
||||||
return;
|
let downloadPath = '';
|
||||||
}
|
try {
|
||||||
|
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
||||||
|
|
||||||
let downloadPath = '';
|
const versionInfo = await this.getInfoFromManifest(
|
||||||
try {
|
this.nodeInfo.versionSpec,
|
||||||
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
this.nodeInfo.stable,
|
||||||
|
osArch,
|
||||||
const versionInfo = await this.getInfoFromManifest(
|
manifest
|
||||||
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 (versionInfo) {
|
||||||
|
core.info(
|
||||||
|
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
|
||||||
|
);
|
||||||
|
downloadPath = await tc.downloadTool(
|
||||||
|
versionInfo.downloadUrl,
|
||||||
|
undefined,
|
||||||
|
this.nodeInfo.auth
|
||||||
|
);
|
||||||
|
|
||||||
if (downloadPath) {
|
if (downloadPath) {
|
||||||
toolPath = await this.extractArchive(downloadPath, versionInfo);
|
toolPath = await this.extractArchive(downloadPath, versionInfo);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
core.info(
|
||||||
|
'Not found in manifest. Falling back to download directly from Node'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} catch (err) {
|
||||||
core.info(
|
// Rate limit?
|
||||||
'Not found in manifest. Falling back to download directly from Node'
|
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');
|
||||||
}
|
}
|
||||||
} 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) {
|
if (!toolPath) {
|
||||||
toolPath = await this.downloadDirectlyFromNode();
|
const nodeJsVersions = await this.getNodeJsVersions();
|
||||||
|
const versions = this.filterVersions(nodeJsVersions);
|
||||||
|
const evaluatedVersion = this.evaluateVersions(versions);
|
||||||
|
if (!evaluatedVersion) {
|
||||||
|
throw new Error(
|
||||||
|
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
||||||
|
toolPath = await this.downloadNodejs(toolName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.osPlat != 'win32') {
|
if (this.osPlat != 'win32') {
|
||||||
@ -122,43 +127,6 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
core.addPath(toolPath);
|
core.addPath(toolPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected addToolPath(toolPath: string) {
|
|
||||||
if (this.osPlat != 'win32') {
|
|
||||||
toolPath = path.join(toolPath, 'bin');
|
|
||||||
}
|
|
||||||
|
|
||||||
core.addPath(toolPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async downloadDirectlyFromNode() {
|
|
||||||
const nodeJsVersions = await this.getNodeJsVersions();
|
|
||||||
const versions = this.filterVersions(nodeJsVersions);
|
|
||||||
const evaluatedVersion = this.evaluateVersions(versions);
|
|
||||||
|
|
||||||
if (!evaluatedVersion) {
|
|
||||||
throw new Error(
|
|
||||||
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
protected evaluateVersions(versions: string[]): string {
|
||||||
let version = '';
|
let version = '';
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user