Resolve global.json latestMajor to the newest active release instead of LTS (#803)

* Resolve global.json latestMajor to the newest active release, not LTS

rollForward: latestMajor cleared the version, which createChannelArgument mapped to the LTS channel. When the declared sdk.version belongs to an STS release, the LTS channel is older than the declared version and the installed SDK does not satisfy global.json. Resolve it from the releases index to the newest active release of either support type, still GA only.

* Limit latestMajor resolution to global.json and enforce the minimum version

An empty version without rollForward latestMajor (for example a global.json
without sdk.version) resolves to the LTS channel again. After an online
install, the action fails if the installed SDK is older than the global.json
minimum version. The installer tests now mock the releases index instead of
calling the live service.
This commit is contained in:
Kamron Batman
2026-11-30 11:28:00 -06:00
committed by GitHub
parent 84bc3a3451
commit 186fc9ae17
5 changed files with 204 additions and 12 deletions
+30 -5
View File
@@ -78,7 +78,8 @@ export class DotnetVersionResolver {
constructor(
version: string,
private quality: QualityOptions = '',
private dotnetChannel?: string
private dotnetChannel?: string,
private rollForward?: string
) {
this.inputVersion = version.trim();
this.resolvedArgument = {type: '', value: '', qualityFlag: false};
@@ -118,6 +119,13 @@ export class DotnetVersionResolver {
return;
}
if (this.inputVersion === '' && this.rollForward === 'latestMajor') {
// global.json latestMajor: newest GA release, LTS or STS
this.resolvedArgument.type = 'channel';
this.resolvedArgument.value = await this.getLatestVersion('', '');
return;
}
if (this.dotnetChannel) {
core.warning(
`The 'dotnet-channel' input is only supported when 'dotnet-version' is set to 'latest'.`
@@ -192,7 +200,10 @@ export class DotnetVersionResolver {
return this.resolvedArgument;
}
private async getLatestVersion(channelFilter: string): Promise<string> {
private async getLatestVersion(
channelFilter: string,
quality: QualityOptions = this.quality
): Promise<string> {
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
allowRetries: true,
maxRetries: 3
@@ -216,7 +227,7 @@ export class DotnetVersionResolver {
// Filter out preview versions if quality is not 'preview' or 'daily'
// If quality is not specified, we assume strict stability (GA only)
const normalizedQuality = (this.quality || '').toLowerCase();
const normalizedQuality = (quality || '').toLowerCase();
if (!['preview', 'daily'].includes(normalizedQuality)) {
releasesInfo = releasesInfo.filter(
info => info['support-phase'] !== 'preview'
@@ -877,7 +888,8 @@ export class DotnetCoreInstaller {
const versionResolver = new DotnetVersionResolver(
this.version,
this.quality,
this.dotnetChannel
this.dotnetChannel,
this.rollForward
);
const dotnetVersion = await versionResolver.createDotnetVersion();
@@ -942,7 +954,20 @@ export class DotnetCoreInstaller {
);
}
return this.parseInstalledVersion(dotnetInstallOutput.stdout);
const installedVersion = this.parseInstalledVersion(
dotnetInstallOutput.stdout
);
if (
installedVersion &&
this.minimumVersion &&
semver.valid(installedVersion) &&
semver.lt(installedVersion, this.minimumVersion)
) {
throw new Error(
`The installed .NET SDK ${installedVersion} is older than the global.json minimum version ${this.minimumVersion}.`
);
}
return installedVersion;
}
public async installRuntime(): Promise<string | null> {