From 0b66095a848d5fcfa12981fab71344e96921d0f8 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Wed, 29 Jan 2025 18:41:57 +0530 Subject: [PATCH 01/11] mirrorurl code --- action.yml | 3 + dist/setup/index.js | 184 ++++++++++++------ src/distributions/base-distribution.ts | 26 +++ src/distributions/base-models.ts | 2 + .../official_builds/official_builds.ts | 51 +++++ src/main.ts | 6 +- 6 files changed, 210 insertions(+), 62 deletions(-) diff --git a/action.yml b/action.yml index 99db5869..e2e7697a 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,9 @@ inputs: check-latest: description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.' default: false + mirrorURL: + description: 'Custom mirror URL to download Node.js from (optional)' + required: false registry-url: description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.' scope: diff --git a/dist/setup/index.js b/dist/setup/index.js index cdca1dbf..ab183ef2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100174,6 +100174,26 @@ class BaseDistribution { fileName: fileName }; } + getNodejsMirrorURLInfo(version) { + const mirrorURL = this.nodeInfo.mirrorURL; + const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); + version = semver_1.default.clean(version) || ''; + const fileName = this.osPlat == 'win32' + ? `node-v${version}-win-${osArch}` + : `node-v${version}-${this.osPlat}-${osArch}`; + const urlFileName = this.osPlat == 'win32' + ? this.nodeInfo.arch === 'arm64' + ? `${fileName}.zip` + : `${fileName}.7z` + : `${fileName}.tar.gz`; + const url = `${mirrorURL}/v${version}/${urlFileName}`; + return { + downloadUrl: url, + resolvedVersion: version, + arch: osArch, + fileName: fileName + }; + } downloadNodejs(info) { return __awaiter(this, void 0, void 0, function* () { let downloadPath = ''; @@ -100451,73 +100471,90 @@ class OfficialBuilds extends base_distribution_1.default { } setupNodeJs() { return __awaiter(this, void 0, void 0, function* () { - var _a; - let manifest; - let nodeJsVersions; - const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); - if (this.isLtsAlias(this.nodeInfo.versionSpec)) { - core.info('Attempt to resolve LTS alias from manifest...'); - // No try-catch since it's not possible to resolve LTS alias without manifest - manifest = yield this.getManifest(); - this.nodeInfo.versionSpec = this.resolveLtsAliasFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, manifest); - } - if (this.isLatestSyntax(this.nodeInfo.versionSpec)) { - nodeJsVersions = yield this.getNodeJsVersions(); - const versions = this.filterVersions(nodeJsVersions); - this.nodeInfo.versionSpec = this.evaluateVersions(versions); - core.info('getting latest node version...'); - } - if (this.nodeInfo.checkLatest) { - core.info('Attempt to resolve the latest version from manifest...'); - const resolvedVersion = yield this.resolveVersionFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest); - if (resolvedVersion) { - this.nodeInfo.versionSpec = resolvedVersion; - core.info(`Resolved as '${resolvedVersion}'`); - } - else { - core.info(`Failed to resolve version ${this.nodeInfo.versionSpec} from manifest`); - } - } - let toolPath = this.findVersionInHostedToolCacheDirectory(); - if (toolPath) { - core.info(`Found in cache @ ${toolPath}`); - this.addToolPath(toolPath); - return; - } - 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); + var _a, _b; + if (this.nodeInfo.mirrorURL) { + let downloadPath = ''; + let toolPath = ''; + try { + core.info(`Attempting to download using mirror URL...`); + downloadPath = yield this.downloadFromMirrorURL(); // Attempt to download from the mirror if (downloadPath) { - toolPath = yield this.extractArchive(downloadPath, versionInfo, false); + toolPath = downloadPath; } } - 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 { + catch (err) { core.info(err.message); + core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack'); } - core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack'); - core.info('Falling back to download directly from Node'); } - if (!toolPath) { - toolPath = yield this.downloadDirectlyFromNode(); + else { + let manifest; + let nodeJsVersions; + const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); + if (this.isLtsAlias(this.nodeInfo.versionSpec)) { + core.info('Attempt to resolve LTS alias from manifest...'); + // No try-catch since it's not possible to resolve LTS alias without manifest + manifest = yield this.getManifest(); + this.nodeInfo.versionSpec = this.resolveLtsAliasFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, manifest); + } + if (this.isLatestSyntax(this.nodeInfo.versionSpec)) { + nodeJsVersions = yield this.getNodeJsVersions(); + const versions = this.filterVersions(nodeJsVersions); + this.nodeInfo.versionSpec = this.evaluateVersions(versions); + core.info('getting latest node version...'); + } + if (this.nodeInfo.checkLatest) { + core.info('Attempt to resolve the latest version from manifest...'); + const resolvedVersion = yield this.resolveVersionFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest); + if (resolvedVersion) { + this.nodeInfo.versionSpec = resolvedVersion; + core.info(`Resolved as '${resolvedVersion}'`); + } + else { + core.info(`Failed to resolve version ${this.nodeInfo.versionSpec} from manifest`); + } + } + let toolPath = this.findVersionInHostedToolCacheDirectory(); + if (toolPath) { + core.info(`Found in cache @ ${toolPath}`); + this.addToolPath(toolPath); + return; + } + 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, false); + } + } + 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((_b = err.stack) !== null && _b !== void 0 ? _b : 'empty 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); } - if (this.osPlat != 'win32') { - toolPath = path_1.default.join(toolPath, 'bin'); - } - core.addPath(toolPath); }); } addToolPath(toolPath) { @@ -100626,6 +100663,29 @@ class OfficialBuilds extends base_distribution_1.default { isLatestSyntax(versionSpec) { return ['current', 'latest', 'node'].includes(versionSpec); } + downloadFromMirrorURL() { + 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.getNodejsMirrorURLInfo(evaluatedVersion); + 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.'); + } + throw error; + } + }); + } } exports["default"] = OfficialBuilds; @@ -100748,6 +100808,7 @@ function run() { if (!arch) { arch = os_1.default.arch(); } + const mirrorURL = core.getInput('mirrorURL').trim(); // .trim() to remove any accidental spaces if (version) { const token = core.getInput('token'); const auth = !token ? undefined : `token ${token}`; @@ -100758,7 +100819,8 @@ function run() { checkLatest, auth, stable, - arch + arch, + mirrorURL }; const nodeDistribution = (0, installer_factory_1.getNodejsDistribution)(nodejsInfo); yield nodeDistribution.setupNodeJs(); diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 70b4b572..ac13ccc7 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -25,6 +25,7 @@ export default abstract class BaseDistribution { } protected abstract getDistributionUrl(): string; + public async setupNodeJs() { let nodeJsVersions: INodeVersion[] | undefined; @@ -128,6 +129,31 @@ export default abstract class BaseDistribution { }; } + protected getNodejsMirrorURLInfo(version: string) { + const mirrorURL = this.nodeInfo.mirrorURL; + const osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch); + version = semver.clean(version) || ''; + const fileName: string = + this.osPlat == 'win32' + ? `node-v${version}-win-${osArch}` + : `node-v${version}-${this.osPlat}-${osArch}`; + const urlFileName: string = + this.osPlat == 'win32' + ? this.nodeInfo.arch === 'arm64' + ? `${fileName}.zip` + : `${fileName}.7z` + : `${fileName}.tar.gz`; + + const url = `${mirrorURL}/v${version}/${urlFileName}`; + + return { + downloadUrl: url, + resolvedVersion: version, + arch: osArch, + fileName: fileName + }; + } + protected async downloadNodejs(info: INodeVersionInfo) { let downloadPath = ''; core.info( diff --git a/src/distributions/base-models.ts b/src/distributions/base-models.ts index 0be93b63..d3dbee15 100644 --- a/src/distributions/base-models.ts +++ b/src/distributions/base-models.ts @@ -4,6 +4,7 @@ export interface NodeInputs { auth?: string; checkLatest: boolean; stable: boolean; + mirrorURL: string; } export interface INodeVersionInfo { @@ -11,6 +12,7 @@ export interface INodeVersionInfo { resolvedVersion: string; arch: string; fileName: string; + } export interface INodeVersion { diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index e56eaf81..7f8b65b7 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -12,9 +12,27 @@ interface INodeRelease extends tc.IToolRelease { export default class OfficialBuilds extends BaseDistribution { constructor(nodeInfo: NodeInputs) { super(nodeInfo); + } + public async setupNodeJs() { + if(this.nodeInfo.mirrorURL){ + + let downloadPath = ''; + let toolPath = ''; + try { + core.info(`Attempting to download using mirror URL...`); + downloadPath = await this.downloadFromMirrorURL(); // Attempt to download from the mirror + if (downloadPath) { + toolPath = downloadPath; + } + } catch (err) { + core.info((err as Error).message); + core.debug((err as Error).stack ?? 'empty stack'); + } + + }else{ let manifest: tc.IToolRelease[] | undefined; let nodeJsVersions: INodeVersion[] | undefined; const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); @@ -125,6 +143,8 @@ export default class OfficialBuilds extends BaseDistribution { core.addPath(toolPath); } +} + protected addToolPath(toolPath: string) { if (this.osPlat != 'win32') { @@ -180,6 +200,7 @@ export default class OfficialBuilds extends BaseDistribution { return `https://nodejs.org/dist`; } + private getManifest(): Promise { core.debug('Getting manifest from actions/node-versions@main'); return tc.getManifestFromRepo( @@ -291,4 +312,34 @@ export default class OfficialBuilds extends BaseDistribution { private isLatestSyntax(versionSpec): boolean { return ['current', 'latest', 'node'].includes(versionSpec); } + + protected async downloadFromMirrorURL() { + 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.getNodejsMirrorURLInfo(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; + } + } + } diff --git a/src/main.ts b/src/main.ts index c55c3b00..a3856ace 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,6 +33,9 @@ export async function run() { arch = os.arch(); } + const mirrorURL = core.getInput('mirrorURL').trim(); // .trim() to remove any accidental spaces + + if (version) { const token = core.getInput('token'); const auth = !token ? undefined : `token ${token}`; @@ -45,7 +48,8 @@ export async function run() { checkLatest, auth, stable, - arch + arch, + mirrorURL }; const nodeDistribution = getNodejsDistribution(nodejsInfo); await nodeDistribution.setupNodeJs(); From 6285145ddd41a0712b584e98152cd49fb3f1a39b Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 10:08:06 +0530 Subject: [PATCH 02/11] code --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index e2e7697a..a98f1fe9 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: check-latest: description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.' default: false - mirrorURL: + mirrorURL: description: 'Custom mirror URL to download Node.js from (optional)' required: false registry-url: From a7b5311f2bcf06d5385bc89081c9292eba046888 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 15:37:56 +0530 Subject: [PATCH 03/11] check-latest --- action.yml | 2 +- dist/setup/index.js | 6 +++++- src/distributions/official_builds/official_builds.ts | 5 +++++ src/main.ts | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index a98f1fe9..3cd51852 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: check-latest: description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.' default: false - mirrorURL: + mirror-url: description: 'Custom mirror URL to download Node.js from (optional)' required: false registry-url: diff --git a/dist/setup/index.js b/dist/setup/index.js index ab183ef2..0111cbdd 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100668,6 +100668,10 @@ class OfficialBuilds extends base_distribution_1.default { const nodeJsVersions = yield this.getNodeJsVersions(); const versions = this.filterVersions(nodeJsVersions); const evaluatedVersion = this.evaluateVersions(versions); + if (this.nodeInfo.checkLatest) { + const evaluatedVersion = yield this.findVersionInDist(nodeJsVersions); + this.nodeInfo.versionSpec = evaluatedVersion; + } if (!evaluatedVersion) { throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`); } @@ -100808,7 +100812,7 @@ function run() { if (!arch) { arch = os_1.default.arch(); } - const mirrorURL = core.getInput('mirrorURL').trim(); // .trim() to remove any accidental spaces + const mirrorURL = core.getInput('mirror-url').trim(); // .trim() to remove any accidental spaces if (version) { const token = core.getInput('token'); const auth = !token ? undefined : `token ${token}`; diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index 7f8b65b7..22eab867 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -318,6 +318,11 @@ export default class OfficialBuilds extends BaseDistribution { const versions = this.filterVersions(nodeJsVersions); const evaluatedVersion = this.evaluateVersions(versions); + if (this.nodeInfo.checkLatest) { + const evaluatedVersion = await this.findVersionInDist(nodeJsVersions); + this.nodeInfo.versionSpec = evaluatedVersion; + } + if (!evaluatedVersion) { throw new Error( `Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.` diff --git a/src/main.ts b/src/main.ts index a3856ace..4face073 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,7 +33,7 @@ export async function run() { arch = os.arch(); } - const mirrorURL = core.getInput('mirrorURL').trim(); // .trim() to remove any accidental spaces + const mirrorURL = core.getInput('mirror-url').trim(); // .trim() to remove any accidental spaces if (version) { From 630895f2486b958207df0bc8eccc387de08d6731 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 15:51:00 +0530 Subject: [PATCH 04/11] checklatest --- dist/setup/index.js | 3 +++ src/distributions/official_builds/official_builds.ts | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0111cbdd..d8b092af 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100666,11 +100666,14 @@ class OfficialBuilds extends base_distribution_1.default { downloadFromMirrorURL() { return __awaiter(this, void 0, void 0, function* () { const nodeJsVersions = yield this.getNodeJsVersions(); + core.info('versions from nodeJSVersions' + nodeJsVersions); const versions = this.filterVersions(nodeJsVersions); + core.info('versions' + versions); const evaluatedVersion = this.evaluateVersions(versions); if (this.nodeInfo.checkLatest) { const evaluatedVersion = yield this.findVersionInDist(nodeJsVersions); this.nodeInfo.versionSpec = evaluatedVersion; + core.info('versionSpec' + this.nodeInfo.versionSpec); } if (!evaluatedVersion) { throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`); diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index 22eab867..caabd281 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -315,12 +315,17 @@ export default class OfficialBuilds extends BaseDistribution { protected async downloadFromMirrorURL() { const nodeJsVersions = await this.getNodeJsVersions(); + core.info('versions from nodeJSVersions'+nodeJsVersions); const versions = this.filterVersions(nodeJsVersions); + core.info('versions'+versions); + const evaluatedVersion = this.evaluateVersions(versions); if (this.nodeInfo.checkLatest) { const evaluatedVersion = await this.findVersionInDist(nodeJsVersions); this.nodeInfo.versionSpec = evaluatedVersion; + core.info('versionSpec'+this.nodeInfo.versionSpec); + } if (!evaluatedVersion) { From b587ad80d99294a529cc34219b7e78e27d111d5c Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 15:56:55 +0530 Subject: [PATCH 05/11] print statements --- dist/setup/index.js | 1 + src/distributions/official_builds/official_builds.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index d8b092af..ec968c14 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100670,6 +100670,7 @@ class OfficialBuilds extends base_distribution_1.default { const versions = this.filterVersions(nodeJsVersions); core.info('versions' + versions); const evaluatedVersion = this.evaluateVersions(versions); + core.info('eversions' + evaluatedVersion); if (this.nodeInfo.checkLatest) { const evaluatedVersion = yield this.findVersionInDist(nodeJsVersions); this.nodeInfo.versionSpec = evaluatedVersion; diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index caabd281..1cef6481 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -320,12 +320,12 @@ export default class OfficialBuilds extends BaseDistribution { core.info('versions'+versions); const evaluatedVersion = this.evaluateVersions(versions); - + core.info('eversions'+evaluatedVersion); if (this.nodeInfo.checkLatest) { const evaluatedVersion = await this.findVersionInDist(nodeJsVersions); this.nodeInfo.versionSpec = evaluatedVersion; core.info('versionSpec'+this.nodeInfo.versionSpec); - + } if (!evaluatedVersion) { From 67032b7211022b05667c1e95b59bd35184cba7fb Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 16:13:25 +0530 Subject: [PATCH 06/11] versionSpec --- dist/setup/index.js | 2 +- src/distributions/official_builds/official_builds.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ec968c14..ffd27daf 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100670,7 +100670,7 @@ class OfficialBuilds extends base_distribution_1.default { const versions = this.filterVersions(nodeJsVersions); core.info('versions' + versions); const evaluatedVersion = this.evaluateVersions(versions); - core.info('eversions' + evaluatedVersion); + core.info('versionSpec' + this.nodeInfo.versionSpec); if (this.nodeInfo.checkLatest) { const evaluatedVersion = yield this.findVersionInDist(nodeJsVersions); this.nodeInfo.versionSpec = evaluatedVersion; diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index 1cef6481..1805cb9e 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -320,7 +320,8 @@ export default class OfficialBuilds extends BaseDistribution { core.info('versions'+versions); const evaluatedVersion = this.evaluateVersions(versions); - core.info('eversions'+evaluatedVersion); + core.info('versionSpec'+this.nodeInfo.versionSpec); + if (this.nodeInfo.checkLatest) { const evaluatedVersion = await this.findVersionInDist(nodeJsVersions); this.nodeInfo.versionSpec = evaluatedVersion; From cc7fac46796d56fa446ea6e19e2471b1121d913b Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 16:25:22 +0530 Subject: [PATCH 07/11] error --- dist/setup/index.js | 6 +++++- src/distributions/official_builds/official_builds.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ffd27daf..bac7fe81 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100686,10 +100686,14 @@ class OfficialBuilds extends base_distribution_1.default { } 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. ` + + core.error(`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 type, you can log the error message. + core.error(`An unexpected error occurred like url might not correct`); + } throw error; } }); diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index 1805cb9e..04ebba23 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -342,11 +342,14 @@ export default class OfficialBuilds extends BaseDistribution { return toolPath; } catch (error) { if (error instanceof tc.HTTPError && error.httpStatusCode === 404) { - core.warning( + core.error( `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.' + '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 type, you can log the error message. + core.error(`An unexpected error occurred like url might not correct`); } throw error; From 35af15253e43256deb0410b3cf58221db9698600 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 16:45:39 +0530 Subject: [PATCH 08/11] error --- dist/setup/index.js | 1 + src/distributions/base-distribution.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index bac7fe81..278becce 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100207,6 +100207,7 @@ class BaseDistribution { this.osPlat == 'win32') { return yield this.acquireWindowsNodeFromFallbackLocation(info.resolvedVersion, info.arch); } + core.error(`Download failed from ${info.downloadUrl}. Please check the URl and try again.`); throw err; } const toolPath = yield this.extractArchive(downloadPath, info, true); diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index ac13ccc7..f2fb1976 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -172,6 +172,7 @@ export default abstract class BaseDistribution { info.arch ); } + core.error(`Download failed from ${info.downloadUrl}. Please check the URl and try again.`); throw err; } From 5809c5dc63dd56167574d2d593e883852ba2f6ac Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 17:09:26 +0530 Subject: [PATCH 09/11] error for wrong URL --- dist/setup/index.js | 3 +++ src/distributions/base-distribution.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 278becce..babe4b66 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100238,6 +100238,9 @@ class BaseDistribution { exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`; libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`; core.info(`Downloading only node binary from ${exeUrl}`); + if (!exeUrl) { + core.error('unable to download node binary with the provided URL. Please check and try again'); + } const exePath = yield tc.downloadTool(exeUrl); yield io.cp(exePath, path.join(tempDir, 'node.exe')); const libPath = yield tc.downloadTool(libUrl); diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index f2fb1976..1eb20e6d 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -211,6 +211,8 @@ export default abstract class BaseDistribution { libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`; core.info(`Downloading only node binary from ${exeUrl}`); + if(!exeUrl ){core.error('unable to download node binary with the provided URL. Please check and try again');} + const exePath = await tc.downloadTool(exeUrl); await io.cp(exePath, path.join(tempDir, 'node.exe')); From 01498de30c2de0dff893204687542b054dc9f590 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 17:13:00 +0530 Subject: [PATCH 10/11] error handling --- dist/setup/index.js | 1 + src/distributions/base-distribution.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index babe4b66..3d4c4c12 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100225,6 +100225,7 @@ class BaseDistribution { acquireWindowsNodeFromFallbackLocation(version_1) { return __awaiter(this, arguments, void 0, function* (version, arch = os_1.default.arch()) { const initialUrl = this.getDistributionUrl(); + core.info('url: ' + initialUrl); const osArch = this.translateArchToDistUrl(arch); // Create temporary folder to download to const tempDownloadFolder = `temp_${(0, uuid_1.v4)()}`; diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index 1eb20e6d..b1504449 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -196,7 +196,8 @@ export default abstract class BaseDistribution { arch: string = os.arch() ): Promise { const initialUrl = this.getDistributionUrl(); - const osArch: string = this.translateArchToDistUrl(arch); + core.info('url: ' + initialUrl); + const osArch: string = this.translateArchToDistUrl(arch); // Create temporary folder to download to const tempDownloadFolder = `temp_${uuidv4()}`; From 50efbd2a86c64b1d4ff6eced9d4f0d3148511088 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 30 Jan 2025 17:29:09 +0530 Subject: [PATCH 11/11] error --- dist/setup/index.js | 6 +++--- src/distributions/base-distribution.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 3d4c4c12..4a2d9a78 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100205,7 +100205,7 @@ class BaseDistribution { if (err instanceof tc.HTTPError && err.httpStatusCode == 404 && this.osPlat == 'win32') { - return yield this.acquireWindowsNodeFromFallbackLocation(info.resolvedVersion, info.arch); + return yield this.acquireWindowsNodeFromFallbackLocation(info.resolvedVersion, info.arch, info.downloadUrl); } core.error(`Download failed from ${info.downloadUrl}. Please check the URl and try again.`); throw err; @@ -100223,7 +100223,7 @@ class BaseDistribution { return { range: valid, options }; } acquireWindowsNodeFromFallbackLocation(version_1) { - return __awaiter(this, arguments, void 0, function* (version, arch = os_1.default.arch()) { + return __awaiter(this, arguments, void 0, function* (version, arch = os_1.default.arch(), downloadUrl) { const initialUrl = this.getDistributionUrl(); core.info('url: ' + initialUrl); const osArch = this.translateArchToDistUrl(arch); @@ -100239,7 +100239,7 @@ class BaseDistribution { exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`; libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`; core.info(`Downloading only node binary from ${exeUrl}`); - if (!exeUrl) { + if (downloadUrl != exeUrl) { core.error('unable to download node binary with the provided URL. Please check and try again'); } const exePath = yield tc.downloadTool(exeUrl); diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts index b1504449..3ced9a82 100644 --- a/src/distributions/base-distribution.ts +++ b/src/distributions/base-distribution.ts @@ -169,7 +169,8 @@ export default abstract class BaseDistribution { ) { return await this.acquireWindowsNodeFromFallbackLocation( info.resolvedVersion, - info.arch + info.arch, + info.downloadUrl ); } core.error(`Download failed from ${info.downloadUrl}. Please check the URl and try again.`); @@ -193,11 +194,12 @@ export default abstract class BaseDistribution { protected async acquireWindowsNodeFromFallbackLocation( version: string, - arch: string = os.arch() + arch: string = os.arch(), + downloadUrl : string ): Promise { const initialUrl = this.getDistributionUrl(); core.info('url: ' + initialUrl); - const osArch: string = this.translateArchToDistUrl(arch); + const osArch: string = this.translateArchToDistUrl(arch); // Create temporary folder to download to const tempDownloadFolder = `temp_${uuidv4()}`; @@ -212,7 +214,7 @@ export default abstract class BaseDistribution { libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`; core.info(`Downloading only node binary from ${exeUrl}`); - if(!exeUrl ){core.error('unable to download node binary with the provided URL. Please check and try again');} + if(downloadUrl != exeUrl ){core.error('unable to download node binary with the provided URL. Please check and try again');} const exePath = await tc.downloadTool(exeUrl);