From 8b9906e7bfb160343a7920ad64f0cd72ced9b8c5 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Tue, 4 Mar 2025 13:07:51 +0530 Subject: [PATCH] update --- dist/setup/index.js | 38 +++---------------- src/distributions/base-distribution.ts | 14 ------- .../official_builds/official_builds.ts | 27 +++---------- 3 files changed, 11 insertions(+), 68 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0dbb269e..bf340c22 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100124,19 +100124,6 @@ class BaseDistribution { return evaluatedVersion; }); } - findMirrorVersionInDist(nodeJsVersions) { - return __awaiter(this, void 0, void 0, function* () { - if (!nodeJsVersions) { - 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}.`); - } - return evaluatedVersion; - }); - } evaluateVersions(versions) { let version = ''; const { range, options } = this.validRange(this.nodeInfo.versionSpec); @@ -100718,43 +100705,28 @@ class OfficialBuilds extends base_distribution_1.default { } downloadFromMirrorURL() { return __awaiter(this, void 0, void 0, function* () { - // Fetch the available Node.js versions from the mirror const nodeJsVersions = yield this.getMirrorUrlVersions(); - // Filter the available versions based on your criteria const versions = this.filterVersions(nodeJsVersions); - let evaluatedVersion; - // If `checkLatest` is set, use the latest version from the mirror - if (this.nodeInfo.checkLatest) { - evaluatedVersion = yield this.findMirrorVersionInDist(nodeJsVersions); - this.nodeInfo.versionSpec = evaluatedVersion; // Update versionSpec to the latest version - } - else { - // Otherwise, evaluate the version from the filtered list - evaluatedVersion = this.evaluateVersions(versions); - } - // If no version is found, throw an error + 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} from the provided mirror-url ${this.nodeInfo.mirrorURL}. Please check the mirror-url.`); + throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} from the provided mirror-url ${this.nodeInfo.mirrorURL}. Please check the mirror-url`); } - // Get the tool name for downloading const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion); try { - // Try to download the Node.js binaries const toolPath = yield this.downloadNodejs(toolName); return toolPath; } catch (error) { - // Handle specific HTTP error (404 - Not Found) if (error instanceof tc.HTTPError && error.httpStatusCode === 404) { core.setFailed(`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.'); } else { - // For any other error, log the actual error message - core.setFailed(`An unexpected error occurred:'url might not be correct'}`); + // For any other error type, you can log the error message. + core.setFailed(`An unexpected error occurred like url might not correct`); } - throw error; // Re-throw the error after logging + throw error; } }); } diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 0ca1d1da..21923ab4 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -63,20 +63,6 @@ export default abstract class BaseDistribution { return evaluatedVersion; } - protected async findMirrorVersionInDist(nodeJsVersions?: INodeVersion[]) { - if (!nodeJsVersions) { - 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}.` - ); - } - - return evaluatedVersion; - } protected evaluateVersions(versions: string[]): string { let version = ''; diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index a5bc2195..24db9dd4 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -310,39 +310,24 @@ export default class OfficialBuilds extends BaseDistribution { } protected async downloadFromMirrorURL() { - // Fetch the available Node.js versions from the mirror const nodeJsVersions = await this.getMirrorUrlVersions(); - - // Filter the available versions based on your criteria const versions = this.filterVersions(nodeJsVersions); - let evaluatedVersion; + const evaluatedVersion = this.evaluateVersions(versions); - // If `checkLatest` is set, use the latest version from the mirror - if (this.nodeInfo.checkLatest) { - evaluatedVersion = await this.findMirrorVersionInDist(nodeJsVersions); - this.nodeInfo.versionSpec = evaluatedVersion; // Update versionSpec to the latest version - } else { - // Otherwise, evaluate the version from the filtered list - evaluatedVersion = this.evaluateVersions(versions); - } - - // If no version is found, throw an error if (!evaluatedVersion) { throw new Error( - `Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} from the provided mirror-url ${this.nodeInfo.mirrorURL}. Please check the mirror-url.` + `Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} from the provided mirror-url ${this.nodeInfo.mirrorURL}. Please check the mirror-url` ); } - // Get the tool name for downloading const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion); try { - // Try to download the Node.js binaries const toolPath = await this.downloadNodejs(toolName); + return toolPath; } catch (error) { - // Handle specific HTTP error (404 - Not Found) if (error instanceof tc.HTTPError && error.httpStatusCode === 404) { core.setFailed( `Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` + @@ -350,13 +335,13 @@ export default class OfficialBuilds extends BaseDistribution { 'To resolve this issue you may either fall back to the older version or try again later.' ); } else { - // For any other error, log the actual error message + // For any other error type, you can log the error message. core.setFailed( - `An unexpected error occurred:'url might not be correct'}` + `An unexpected error occurred like url might not correct` ); } - throw error; // Re-throw the error after logging + throw error; } } }