added check-latest

This commit is contained in:
Aparna Jyothi 2025-03-04 12:50:08 +05:30
parent d8619e6d5a
commit 8495358ea6
3 changed files with 69 additions and 12 deletions

40
dist/setup/index.js vendored
View File

@ -100124,6 +100124,19 @@ class BaseDistribution {
return evaluatedVersion; 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) { evaluateVersions(versions) {
let version = ''; let version = '';
const { range, options } = this.validRange(this.nodeInfo.versionSpec); const { range, options } = this.validRange(this.nodeInfo.versionSpec);
@ -100705,28 +100718,43 @@ class OfficialBuilds extends base_distribution_1.default {
} }
downloadFromMirrorURL() { downloadFromMirrorURL() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Fetch the available Node.js versions from the mirror
const nodeJsVersions = yield this.getMirrorUrlVersions(); const nodeJsVersions = yield this.getMirrorUrlVersions();
// Filter the available versions based on your criteria
const versions = this.filterVersions(nodeJsVersions); const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions); let evaluatedVersion;
if (!evaluatedVersion) { // If `checkLatest` is set, use the latest version from the mirror
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`); 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
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.`);
}
// Get the tool name for downloading
const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion); const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion);
try { try {
// Try to download the Node.js binaries
const toolPath = yield this.downloadNodejs(toolName); const toolPath = yield this.downloadNodejs(toolName);
return toolPath; return toolPath;
} }
catch (error) { catch (error) {
// Handle specific HTTP error (404 - Not Found)
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) { 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. ` + 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/. ' + '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.'); 'To resolve this issue you may either fall back to the older version or try again later.');
} }
else { else {
// For any other error type, you can log the error message. // For any other error, log the actual error message
core.setFailed(`An unexpected error occurred like url might not correct`); core.setFailed(`An unexpected error occurred:'url might not be correct'}`);
} }
throw error; throw error; // Re-throw the error after logging
} }
}); });
} }

View File

@ -63,6 +63,20 @@ export default abstract class BaseDistribution {
return evaluatedVersion; 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 { protected evaluateVersions(versions: string[]): string {
let version = ''; let version = '';

View File

@ -310,24 +310,39 @@ export default class OfficialBuilds extends BaseDistribution {
} }
protected async downloadFromMirrorURL() { protected async downloadFromMirrorURL() {
// Fetch the available Node.js versions from the mirror
const nodeJsVersions = await this.getMirrorUrlVersions(); const nodeJsVersions = await this.getMirrorUrlVersions();
// Filter the available versions based on your criteria
const versions = this.filterVersions(nodeJsVersions); const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions); let evaluatedVersion;
// 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) { if (!evaluatedVersion) {
throw new Error( 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); const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion);
try { try {
// Try to download the Node.js binaries
const toolPath = await this.downloadNodejs(toolName); const toolPath = await this.downloadNodejs(toolName);
return toolPath; return toolPath;
} catch (error) { } catch (error) {
// Handle specific HTTP error (404 - Not Found)
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) { if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
core.setFailed( core.setFailed(
`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` + `Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
@ -335,13 +350,13 @@ export default class OfficialBuilds extends BaseDistribution {
'To resolve this issue you may either fall back to the older version or try again later.' 'To resolve this issue you may either fall back to the older version or try again later.'
); );
} else { } else {
// For any other error type, you can log the error message. // For any other error, log the actual error message
core.setFailed( core.setFailed(
`An unexpected error occurred like url might not correct` `An unexpected error occurred:'url might not be correct'}`
); );
} }
throw error; throw error; // Re-throw the error after logging
} }
} }
} }