Skip to content

Commit 9e956a5

Browse files
Add notice about binaries not being updated yet
1 parent 7da2a7e commit 9e956a5

File tree

2 files changed

+120
-53
lines changed

2 files changed

+120
-53
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(logSpy).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'},

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');
121112
}
122113

114+
if (!toolPath) {
115+
toolPath = await this.downloadDirectlyFromNode();
116+
}
117+
118+
if (this.osPlat != 'win32') {
119+
toolPath = path.join(toolPath, 'bin');
120+
}
121+
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.info(
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)