From c846dff95efa9795c146426cb19361921130d4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Thu, 7 Nov 2024 14:36:06 +0100 Subject: [PATCH] Don't download releases-index.json to resolving major version Starting with .NET 5 the minor version is always zero. The earlier releases don't get new versions anymore so we can hardcode the minor version instead of downloading releases-index.json to do the lookup. --- src/installer.ts | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index c71a8c69d..55ae6313e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -72,7 +72,12 @@ export class DotnetVersionResolver { } else if (this.isNumericTag(major) && this.isNumericTag(minor)) { this.resolvedArgument.value = `${major}.${minor}`; } else if (this.isNumericTag(major)) { - this.resolvedArgument.value = await this.getLatestByMajorTag(major); + // starting with .NET 5 the minor version is always zero, hardcode the earlier versions since they won't get new releases + this.resolvedArgument.value = + major == '1' ? '1.1' : + major == '2' ? '2.2' : + major == '3' ? '3.1' : + `${major}.0`; } else { // If "dotnet-version" is specified as *, x or X resolve latest version of .NET explicitly from LTS channel. The version argument will default to "latest" by install-dotnet script. this.resolvedArgument.value = 'LTS'; @@ -95,34 +100,6 @@ export class DotnetVersionResolver { } return this.resolvedArgument; } - - private async getLatestByMajorTag(majorTag: string): Promise { - const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { - allowRetries: true, - maxRetries: 3 - }); - const response = await httpClient.getJson( - DotnetVersionResolver.DotnetCoreIndexUrl - ); - const result = response.result || {}; - const releasesInfo: any[] = result['releases-index']; - - const releaseInfo = releasesInfo.find(info => { - const sdkParts: string[] = info['channel-version'].split('.'); - return sdkParts[0] === majorTag; - }); - - if (!releaseInfo) { - throw new Error( - `Could not find info for version with major tag: "${majorTag}" at ${DotnetVersionResolver.DotnetCoreIndexUrl}` - ); - } - - return releaseInfo['channel-version']; - } - - static DotnetCoreIndexUrl = - 'https://dotnetcli.azureedge.net/dotnet/release-metadata/releases-index.json'; } export class DotnetInstallScript {