mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2024-11-22 04:40:57 -05:00
Merge pull request #872 from akv-platform/add-notice-about-binaries-not-being-updated
Add notice about binaries not being updated yet
This commit is contained in:
commit
6e9e44895f
3 changed files with 174 additions and 85 deletions
|
@ -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(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 () => {
|
||||
for (const {arch, version, osSpec} of [
|
||||
{arch: 'x86', version: '12.16.2', osSpec: 'win32'},
|
||||
|
|
32
dist/setup/index.js
vendored
32
dist/setup/index.js
vendored
|
@ -72783,8 +72783,9 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||
let toolPath = this.findVersionInHostedToolCacheDirectory();
|
||||
if (toolPath) {
|
||||
core.info(`Found in cache @ ${toolPath}`);
|
||||
this.addToolPath(toolPath);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
let downloadPath = '';
|
||||
try {
|
||||
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
||||
|
@ -72813,6 +72814,22 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||
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);
|
||||
});
|
||||
}
|
||||
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);
|
||||
|
@ -72820,13 +72837,18 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||
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);
|
||||
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.');
|
||||
}
|
||||
if (this.osPlat != 'win32') {
|
||||
toolPath = path_1.default.join(toolPath, 'bin');
|
||||
throw error;
|
||||
}
|
||||
core.addPath(toolPath);
|
||||
});
|
||||
}
|
||||
evaluateVersions(versions) {
|
||||
|
|
|
@ -18,6 +18,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
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...');
|
||||
|
||||
|
@ -61,7 +62,10 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
|
||||
if (toolPath) {
|
||||
core.info(`Found in cache @ ${toolPath}`);
|
||||
} else {
|
||||
this.addToolPath(toolPath);
|
||||
return;
|
||||
}
|
||||
|
||||
let downloadPath = '';
|
||||
try {
|
||||
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
||||
|
@ -72,6 +76,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
osArch,
|
||||
manifest
|
||||
);
|
||||
|
||||
if (versionInfo) {
|
||||
core.info(
|
||||
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
|
||||
|
@ -107,17 +112,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
}
|
||||
|
||||
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}.`
|
||||
);
|
||||
}
|
||||
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
||||
toolPath = await this.downloadNodejs(toolName);
|
||||
}
|
||||
toolPath = await this.downloadDirectlyFromNode();
|
||||
}
|
||||
|
||||
if (this.osPlat != 'win32') {
|
||||
|
@ -127,6 +122,43 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
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 {
|
||||
let version = '';
|
||||
|
||||
|
|
Loading…
Reference in a new issue