Skip to content

Commit 6e9e448

Browse files
Merge pull request #872 from akv-platform/add-notice-about-binaries-not-being-updated
Add notice about binaries not being updated yet
2 parents 7da2a7e + e52912e commit 6e9e448

File tree

3 files changed

+177
-88
lines changed

3 files changed

+177
-88
lines changed

__tests__/official-installer.test.ts

+35
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,41 @@ describe('setup-node', () => {
357357
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
358358
});
359359

360+
it('reports when download failed but version exists', async () => {
361+
os.platform = 'linux';
362+
os.arch = 'x64';
363+
364+
// a version which is not in the manifest but is in node dist
365+
const versionSpec = '11.15.0';
366+
367+
inputs['node-version'] = versionSpec;
368+
inputs['always-auth'] = false;
369+
inputs['token'] = 'faketoken';
370+
371+
// ... but not in the local cache
372+
findSpy.mockImplementation(() => '');
373+
374+
dlSpy.mockImplementationOnce(async () => {
375+
throw new tc.HTTPError(404);
376+
});
377+
378+
await main.run();
379+
380+
expect(getManifestSpy).toHaveBeenCalled();
381+
expect(logSpy).toHaveBeenCalledWith(
382+
`Attempting to download ${versionSpec}...`
383+
);
384+
expect(logSpy).toHaveBeenCalledWith(
385+
'Not found in manifest. Falling back to download directly from Node'
386+
);
387+
expect(dlSpy).toHaveBeenCalled();
388+
expect(warningSpy).toHaveBeenCalledWith(
389+
`Node version ${versionSpec} for platform ${os.platform} and architecture ${os.arch} was found but failed to download. ` +
390+
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
391+
'To resolve this issue you may either fall back to the older version or try again later.'
392+
);
393+
});
394+
360395
it('acquires specified architecture of node', async () => {
361396
for (const {arch, version, osSpec} of [
362397
{arch: 'x86', version: '12.16.2', osSpec: 'win32'},

dist/setup/index.js

+57-35
Original file line numberDiff line numberDiff line change
@@ -72783,52 +72783,74 @@ class OfficialBuilds extends base_distribution_1.default {
7278372783
let toolPath = this.findVersionInHostedToolCacheDirectory();
7278472784
if (toolPath) {
7278572785
core.info(`Found in cache @ ${toolPath}`);
72786+
this.addToolPath(toolPath);
72787+
return;
7278672788
}
72787-
else {
72788-
let downloadPath = '';
72789-
try {
72790-
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
72791-
const versionInfo = yield this.getInfoFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest);
72792-
if (versionInfo) {
72793-
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
72794-
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
72795-
if (downloadPath) {
72796-
toolPath = yield this.extractArchive(downloadPath, versionInfo);
72797-
}
72798-
}
72799-
else {
72800-
core.info('Not found in manifest. Falling back to download directly from Node');
72789+
let downloadPath = '';
72790+
try {
72791+
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
72792+
const versionInfo = yield this.getInfoFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest);
72793+
if (versionInfo) {
72794+
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
72795+
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
72796+
if (downloadPath) {
72797+
toolPath = yield this.extractArchive(downloadPath, versionInfo);
7280172798
}
7280272799
}
72803-
catch (err) {
72804-
// Rate limit?
72805-
if (err instanceof tc.HTTPError &&
72806-
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
72807-
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
72808-
}
72809-
else {
72810-
core.info(err.message);
72811-
}
72812-
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
72813-
core.info('Falling back to download directly from Node');
72814-
}
72815-
if (!toolPath) {
72816-
const nodeJsVersions = yield this.getNodeJsVersions();
72817-
const versions = this.filterVersions(nodeJsVersions);
72818-
const evaluatedVersion = this.evaluateVersions(versions);
72819-
if (!evaluatedVersion) {
72820-
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
72821-
}
72822-
const toolName = this.getNodejsDistInfo(evaluatedVersion);
72823-
toolPath = yield this.downloadNodejs(toolName);
72800+
else {
72801+
core.info('Not found in manifest. Falling back to download directly from Node');
72802+
}
72803+
}
72804+
catch (err) {
72805+
// Rate limit?
72806+
if (err instanceof tc.HTTPError &&
72807+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
72808+
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
72809+
}
72810+
else {
72811+
core.info(err.message);
7282472812
}
72813+
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
72814+
core.info('Falling back to download directly from Node');
72815+
}
72816+
if (!toolPath) {
72817+
toolPath = yield this.downloadDirectlyFromNode();
7282572818
}
7282672819
if (this.osPlat != 'win32') {
7282772820
toolPath = path_1.default.join(toolPath, 'bin');
7282872821
}
7282972822
core.addPath(toolPath);
7283072823
});
7283172824
}
72825+
addToolPath(toolPath) {
72826+
if (this.osPlat != 'win32') {
72827+
toolPath = path_1.default.join(toolPath, 'bin');
72828+
}
72829+
core.addPath(toolPath);
72830+
}
72831+
downloadDirectlyFromNode() {
72832+
return __awaiter(this, void 0, void 0, function* () {
72833+
const nodeJsVersions = yield this.getNodeJsVersions();
72834+
const versions = this.filterVersions(nodeJsVersions);
72835+
const evaluatedVersion = this.evaluateVersions(versions);
72836+
if (!evaluatedVersion) {
72837+
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
72838+
}
72839+
const toolName = this.getNodejsDistInfo(evaluatedVersion);
72840+
try {
72841+
const toolPath = yield this.downloadNodejs(toolName);
72842+
return toolPath;
72843+
}
72844+
catch (error) {
72845+
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
72846+
core.warning(`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
72847+
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
72848+
'To resolve this issue you may either fall back to the older version or try again later.');
72849+
}
72850+
throw error;
72851+
}
72852+
});
72853+
}
7283272854
evaluateVersions(versions) {
7283372855
let version = '';
7283472856
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {

src/distributions/official_builds/official_builds.ts

+85-53
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default class OfficialBuilds extends BaseDistribution {
1818
let manifest: tc.IToolRelease[] | undefined;
1919
let nodeJsVersions: INodeVersion[] | undefined;
2020
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
21+
2122
if (this.isLtsAlias(this.nodeInfo.versionSpec)) {
2223
core.info('Attempt to resolve LTS alias from manifest...');
2324

@@ -61,72 +62,103 @@ export default class OfficialBuilds extends BaseDistribution {
6162

6263
if (toolPath) {
6364
core.info(`Found in cache @ ${toolPath}`);
64-
} else {
65-
let downloadPath = '';
66-
try {
67-
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
68-
69-
const versionInfo = await this.getInfoFromManifest(
70-
this.nodeInfo.versionSpec,
71-
this.nodeInfo.stable,
72-
osArch,
73-
manifest
65+
this.addToolPath(toolPath);
66+
return;
67+
}
68+
69+
let downloadPath = '';
70+
try {
71+
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
72+
73+
const versionInfo = await this.getInfoFromManifest(
74+
this.nodeInfo.versionSpec,
75+
this.nodeInfo.stable,
76+
osArch,
77+
manifest
78+
);
79+
80+
if (versionInfo) {
81+
core.info(
82+
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
83+
);
84+
downloadPath = await tc.downloadTool(
85+
versionInfo.downloadUrl,
86+
undefined,
87+
this.nodeInfo.auth
7488
);
75-
if (versionInfo) {
76-
core.info(
77-
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
78-
);
79-
downloadPath = await tc.downloadTool(
80-
versionInfo.downloadUrl,
81-
undefined,
82-
this.nodeInfo.auth
83-
);
84-
85-
if (downloadPath) {
86-
toolPath = await this.extractArchive(downloadPath, versionInfo);
87-
}
88-
} else {
89-
core.info(
90-
'Not found in manifest. Falling back to download directly from Node'
91-
);
92-
}
93-
} catch (err) {
94-
// Rate limit?
95-
if (
96-
err instanceof tc.HTTPError &&
97-
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
98-
) {
99-
core.info(
100-
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
101-
);
102-
} else {
103-
core.info((err as Error).message);
104-
}
105-
core.debug((err as Error).stack ?? 'empty stack');
106-
core.info('Falling back to download directly from Node');
107-
}
10889

109-
if (!toolPath) {
110-
const nodeJsVersions = await this.getNodeJsVersions();
111-
const versions = this.filterVersions(nodeJsVersions);
112-
const evaluatedVersion = this.evaluateVersions(versions);
113-
if (!evaluatedVersion) {
114-
throw new Error(
115-
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
116-
);
90+
if (downloadPath) {
91+
toolPath = await this.extractArchive(downloadPath, versionInfo);
11792
}
118-
const toolName = this.getNodejsDistInfo(evaluatedVersion);
119-
toolPath = await this.downloadNodejs(toolName);
93+
} else {
94+
core.info(
95+
'Not found in manifest. Falling back to download directly from Node'
96+
);
97+
}
98+
} catch (err) {
99+
// Rate limit?
100+
if (
101+
err instanceof tc.HTTPError &&
102+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
103+
) {
104+
core.info(
105+
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
106+
);
107+
} else {
108+
core.info((err as Error).message);
120109
}
110+
core.debug((err as Error).stack ?? 'empty stack');
111+
core.info('Falling back to download directly from Node');
112+
}
113+
114+
if (!toolPath) {
115+
toolPath = await this.downloadDirectlyFromNode();
116+
}
117+
118+
if (this.osPlat != 'win32') {
119+
toolPath = path.join(toolPath, 'bin');
121120
}
122121

122+
core.addPath(toolPath);
123+
}
124+
125+
protected addToolPath(toolPath: string) {
123126
if (this.osPlat != 'win32') {
124127
toolPath = path.join(toolPath, 'bin');
125128
}
126129

127130
core.addPath(toolPath);
128131
}
129132

133+
protected async downloadDirectlyFromNode() {
134+
const nodeJsVersions = await this.getNodeJsVersions();
135+
const versions = this.filterVersions(nodeJsVersions);
136+
const evaluatedVersion = this.evaluateVersions(versions);
137+
138+
if (!evaluatedVersion) {
139+
throw new Error(
140+
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
141+
);
142+
}
143+
144+
const toolName = this.getNodejsDistInfo(evaluatedVersion);
145+
146+
try {
147+
const toolPath = await this.downloadNodejs(toolName);
148+
return toolPath;
149+
} catch (error) {
150+
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
151+
core.warning(
152+
`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
153+
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
154+
'To resolve this issue you may either fall back to the older version or try again later.'
155+
);
156+
}
157+
158+
throw error;
159+
}
160+
}
161+
130162
protected evaluateVersions(versions: string[]): string {
131163
let version = '';
132164

0 commit comments

Comments
 (0)