Skip to content

Commit

Permalink
Add notice about binaries not being updated yet
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolai-laevskii committed Jul 20, 2023
1 parent ca2d4e0 commit 3e9c263
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 88 deletions.
35 changes: 35 additions & 0 deletions __tests__/official-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,41 @@ describe('setup-node', () => {
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(logSpy).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 () => {
for (const {arch, version, osSpec} of [
{arch: 'x86', version: '12.16.2', osSpec: 'win32'},
Expand Down
89 changes: 54 additions & 35 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71986,52 +71986,71 @@ class OfficialBuilds extends base_distribution_1.default {
let toolPath = this.findVersionInHostedToolCacheDirectory();
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
if (this.osPlat != 'win32') {
toolPath = path_1.default.join(toolPath, 'bin');
}
core.addPath(toolPath);
return;
}
else {
let downloadPath = '';
try {
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
const versionInfo = yield this.getInfoFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest);
if (versionInfo) {
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
if (downloadPath) {
toolPath = yield this.extractArchive(downloadPath, versionInfo);
}
}
else {
core.info('Not found in manifest. Falling back to download directly from Node');
let downloadPath = '';
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
try {
const versionInfo = yield this.getInfoFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest);
if (versionInfo) {
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
if (downloadPath) {
toolPath = yield this.extractArchive(downloadPath, versionInfo);
}
}
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.message);
}
core.debug(err.stack);
core.info('Falling back to download directly from Node');
}
if (!toolPath) {
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);
toolPath = yield this.downloadNodejs(toolName);
else {
core.info('Not found in manifest. 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.message);
}
core.debug(err.stack);
core.info('Falling back to download directly from Node');
}
if (!toolPath) {
toolPath = yield this.downloadDirectlyFromNode();
}
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.info(`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) {
let version = '';
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
Expand Down
135 changes: 82 additions & 53 deletions src/distributions/official_builds/official_builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,63 +61,63 @@ export default class OfficialBuilds extends BaseDistribution {

if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
} else {
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);
}
} else {
core.info(
'Not found in manifest. 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.message);
}
core.debug(err.stack);
core.info('Falling back to download directly from Node');

if (this.osPlat != 'win32') {
toolPath = path.join(toolPath, 'bin');
}

if (!toolPath) {
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}.`
);
core.addPath(toolPath);
return;
}

let downloadPath = '';
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);

try {
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);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion);
toolPath = await this.downloadNodejs(toolName);
} else {
core.info(
'Not found in manifest. 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.message);
}
core.debug(err.stack);
core.info('Falling back to download directly from Node');
}

if (!toolPath) {
toolPath = await this.downloadDirectlyFromNode();
}

if (this.osPlat != 'win32') {
Expand All @@ -127,6 +127,35 @@ export default class OfficialBuilds extends BaseDistribution {
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.info(
`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 {
let version = '';

Expand Down

0 comments on commit 3e9c263

Please sign in to comment.