diff --git a/eng/update-dependencies/Updaters/ChiselUpdater.cs b/eng/update-dependencies/Updaters/ChiselUpdater.cs index dfe79d642d..655a37db0a 100644 --- a/eng/update-dependencies/Updaters/ChiselUpdater.cs +++ b/eng/update-dependencies/Updaters/ChiselUpdater.cs @@ -8,6 +8,7 @@ namespace Microsoft.DotNet.Docker.UpdateDependencies.Updaters; public sealed class ChiselUpdater(IReleasesClient releases, HttpClient httpClient) : IGitHubReleaseUpdater { + private const string BuildVersionVariable = "chisel|latest|build-version"; private const string Owner = "canonical"; private const string Repo = "chisel"; @@ -23,6 +24,12 @@ private static string GetChiselManifestVariable(string product, string arch, str private static Regex GetAssetRegex(string arch) => new(@"chisel_v\d+\.\d+\.\d+_linux_" + arch + @"\.tar\.gz"); + private static string GetDownloadUrl(string arch) + { + string buildVersion = $"$({BuildVersionVariable})"; + return $"https://github.com/{Owner}/{Repo}/releases/download/{buildVersion}/chisel_{buildVersion}_linux_{arch}.tar.gz"; + } + private static string ToManifestArch(string arch) => arch == "amd64" ? "x64" : arch; public async Task ResolveFromGitHubReleaseAsync(CancellationToken cancellationToken) @@ -39,13 +46,20 @@ private async Task ApplyAsync( Release release, CancellationToken cancellationToken) { + if (!variables.ShouldUpdateLiteral(BuildVersionVariable)) + { + return; + } + + variables.SetValue(BuildVersionVariable, release.TagName); + foreach (string arch in s_supportedArchitectures) { string urlVariable = GetChiselManifestVariable(Name, arch, "url"); string shaVariable = GetChiselManifestVariable(Name, arch, "sha384"); - bool updateUrl = variables.ShouldUpdateLiteral(urlVariable); - bool updateSha = variables.ShouldUpdateLiteral(shaVariable); - if (!updateUrl && !updateSha) + variables.SetValue(urlVariable, GetDownloadUrl(arch)); + + if (!variables.ShouldUpdateLiteral(shaVariable)) { continue; } @@ -54,20 +68,12 @@ private async Task ApplyAsync( ReleaseAsset asset = release.Assets.FirstOrDefault(asset => assetRegex.IsMatch(asset.Name)) ?? throw new InvalidOperationException($"Could not find Chisel release asset matching regex {assetRegex}."); - if (updateUrl) - { - variables.SetValue(urlVariable, asset.BrowserDownloadUrl); - } - - if (updateSha) - { - string checksumUrl = $"{asset.BrowserDownloadUrl}.sha384"; - string content = await httpClient.GetStringAsync(checksumUrl, cancellationToken); + string checksumUrl = $"{asset.BrowserDownloadUrl}.sha384"; + string content = await httpClient.GetStringAsync(checksumUrl, cancellationToken); - // Each checksum file contains " ". - string sha = content.Split(" ")[0].ToLowerInvariant(); - variables.SetValue(shaVariable, sha); - } + // Each checksum file contains " ". + string sha = content.Split(" ")[0].ToLowerInvariant(); + variables.SetValue(shaVariable, sha); } } }