Skip to content

Commit

Permalink
Clean up update-dependencies project (#6093)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussell authored Dec 4, 2024
1 parent 35f7e8d commit 9f7a9b5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 148 deletions.
1 change: 0 additions & 1 deletion eng/update-dependencies/BaseUrlUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ protected override string TryGetDesiredValue(IEnumerable<IDependencyInfo> depend
return unresolvedBaseUrl;
}
}
#nullable disable
158 changes: 31 additions & 127 deletions eng/update-dependencies/DockerfileShaUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -43,7 +42,7 @@ public class DockerfileShaUpdater : FileRegexUpdater
private readonly string _os;
private readonly Options _options;
private readonly string _versions;
private readonly Dictionary<string, string[]> _urls;
private readonly Dictionary<string, string> _urls;
private readonly Lazy<JObject> _manifestVariables;

public DockerfileShaUpdater(
Expand All @@ -58,50 +57,19 @@ public DockerfileShaUpdater(
_options = options;

// Maps a product name to a set of one or more candidate URLs referencing the associated artifact. The order of the URLs
// should be in priority order with each subsequent URL being the fallback. This is primarily intended to support targeting
// pack RPMs because they only ship once for a given major/minor release and never again for servicing releases. However, during
// preview releases, they ship with each build. By making use of fallback URLs it allows support for either scenario, first checking
// for the build-specific location and then falling back to the overall major/minor release location.
// should be in priority order with each subsequent URL being the fallback.
_urls = new()
{
{ "powershell", new string[] { "https://powershellinfraartifacts-gkhedzdeaghdezhr.z01.azurefd.net/tool/$VERSION_DIR/PowerShell.$OS.$ARCH.$VERSION_FILE.nupkg" } },

{ "monitor", new string[] { $"$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" } },
{ "monitor-base", new string[] { $"$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-base-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" } },
{ "monitor-ext-azureblobstorage", new string[] { $"$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-egress-azureblobstorage-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" } },
{ "monitor-ext-s3storage", new string[] { $"$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-egress-s3storage-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" } },

{ "aspire-dashboard", [ $"$DOTNET_BASE_URL/aspire/$VERSION_DIR/aspire-dashboard-$OS-$ARCH.$ARCHIVE_EXT" ] },

{ "runtime", new string[] { $"$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-runtime-$VERSION_FILE$OPTIONAL_OS-{GetRuntimeSdkArchFormat()}.$ARCHIVE_EXT" } },
{ "runtime-host", new string[] { $"$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-host-$VERSION_FILE-{GetRpmArchFormat()}.$ARCHIVE_EXT" } },
{ "runtime-hostfxr", new string[] { $"$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-hostfxr-$VERSION_FILE-{GetRpmArchFormat()}.$ARCHIVE_EXT" } },
{
"runtime-targeting-pack",
new string[]
{
$"$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-targeting-pack-$VERSION_FILE-{GetRpmArchFormat()}.$ARCHIVE_EXT",
$"$DOTNET_BASE_URL/Runtime/$DF_VERSION.0/dotnet-targeting-pack-$DF_VERSION.0-{GetRpmArchFormat()}.$ARCHIVE_EXT"
}
},
{ "runtime-apphost-pack", new string[] { $"$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-apphost-pack-$VERSION_FILE-{GetRpmArchFormat()}.$ARCHIVE_EXT" } },
{ NetStandard21TargetingPack, new string[] { $"{ReleaseDotnetBaseUrl}/Runtime/3.1.0/netstandard-targeting-pack-2.1.0-$ARCH.$ARCHIVE_EXT" } },
{ "runtime-deps-cm.1", new string[] { $"$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-runtime-deps-$VERSION_FILE-cm.1-{GetRpmArchFormat()}.$ARCHIVE_EXT" } },
{ "runtime-deps-cm.2", new string[] { $"$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-runtime-deps-$VERSION_FILE-cm.2-{GetRpmArchFormat()}.$ARCHIVE_EXT" } },

{ "aspnet", new string[] { $"$DOTNET_BASE_URL/aspnetcore/Runtime/$VERSION_DIR/aspnetcore-runtime-$VERSION_FILE$OPTIONAL_OS-{GetRuntimeSdkArchFormat()}.$ARCHIVE_EXT" } },
{ "aspnet-composite", new string[] { $"$DOTNET_BASE_URL/aspnetcore/Runtime/$VERSION_DIR/aspnetcore-runtime-composite-$VERSION_FILE$OPTIONAL_OS-{GetRuntimeSdkArchFormat()}.$ARCHIVE_EXT" } },
{
"aspnet-runtime-targeting-pack",
new string[]
{
$"$DOTNET_BASE_URL/aspnetcore/Runtime/$VERSION_DIR/aspnetcore-targeting-pack-$VERSION_FILE{GetAspnetTargetingPackArchFormat()}.$ARCHIVE_EXT",
$"$DOTNET_BASE_URL/aspnetcore/Runtime/$DF_VERSION.0/aspnetcore-targeting-pack-$DF_VERSION.0{GetAspnetTargetingPackArchFormat()}.$ARCHIVE_EXT"
}
},

{ "sdk", new string[] { $"$DOTNET_BASE_URL/Sdk/$VERSION_DIR/dotnet-sdk-$VERSION_FILE$OPTIONAL_OS-{GetRuntimeSdkArchFormat()}.$ARCHIVE_EXT" } },
{ "lzma", new string[] { $"$DOTNET_BASE_URL/Sdk/$VERSION_DIR/nuGetPackagesArchive.lzma" } }
{ "aspire-dashboard", "$DOTNET_BASE_URL/aspire/$VERSION_DIR/aspire-dashboard-$OS-$ARCH.$ARCHIVE_EXT" },
{ "aspnet-composite", "$DOTNET_BASE_URL/aspnetcore/Runtime/$VERSION_DIR/aspnetcore-runtime-composite-$VERSION_FILE$OS-$ARCH.$ARCHIVE_EXT" },
{ "aspnet", "$DOTNET_BASE_URL/aspnetcore/Runtime/$VERSION_DIR/aspnetcore-runtime-$VERSION_FILE$OS-$ARCH.$ARCHIVE_EXT" },
{ "monitor-base", "$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-base-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" },
{ "monitor-ext-azureblobstorage", "$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-egress-azureblobstorage-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" },
{ "monitor-ext-s3storage", "$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-egress-s3storage-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" },
{ "monitor", "$DOTNET_BASE_URL/diagnostics/monitor/$VERSION_DIR/dotnet-monitor-$VERSION_FILE-$OS-$ARCH.$ARCHIVE_EXT" },
{ "powershell", "https://powershellinfraartifacts-gkhedzdeaghdezhr.z01.azurefd.net/tool/$VERSION_DIR/PowerShell.$OS.$ARCH.$VERSION_FILE.nupkg" },
{ "runtime", "$DOTNET_BASE_URL/Runtime/$VERSION_DIR/dotnet-runtime-$VERSION_FILE$OS-$ARCH.$ARCHIVE_EXT" },
{ "sdk", "$DOTNET_BASE_URL/Sdk/$VERSION_DIR/dotnet-sdk-$VERSION_FILE$OS-$ARCH.$ARCHIVE_EXT" },
};

_manifestVariables = new Lazy<JObject>(
Expand All @@ -125,12 +93,6 @@ public DockerfileShaUpdater(
}
}

private string GetRpmArchFormat() => _arch == "arm64" ? "aarch64" : "$ARCH";

private string GetAspnetTargetingPackArchFormat() => $"-{GetRpmArchFormat()}";

private string GetRuntimeSdkArchFormat() => _os.Contains("rpm") ? GetRpmArchFormat() : "$ARCH";

public static IEnumerable<IDependencyUpdater> CreateUpdaters(
string productName, string dockerfileVersion, string repoRoot, Options options)
{
Expand Down Expand Up @@ -185,75 +147,30 @@ public static IEnumerable<IDependencyUpdater> CreateUpdaters(
protected override string? TryGetDesiredValue(
IEnumerable<IDependencyInfo> dependencyBuildInfos, out IEnumerable<IDependencyInfo> usedBuildInfos)
{
IDependencyInfo productInfo = dependencyBuildInfos.First(info => info.SimpleName == _productName);

usedBuildInfos = new IDependencyInfo[] { productInfo };
usedBuildInfos = [ dependencyBuildInfos.First(info => info.SimpleName == _productName) ];

string baseUrl = ManifestHelper.GetBaseUrl(_manifestVariables.Value, _options);
// Remove Aspire Dashboard case once https://github.com/dotnet/aspire/issues/2035 is fixed.
string archiveExt = _os.Contains("win") || _productName.Contains("aspire-dashboard") ? "zip" : "tar.gz";
string versionDir = _buildVersion ?? "";
string versionFile = UpdateDependencies.ResolveProductVersion(versionDir, _options);

string archiveExt;
if (_os.Contains("win"))
{
archiveExt = "zip";
}
else if (_os.Contains("rpm"))
{
archiveExt = "rpm";
}
else
{
archiveExt = "tar.gz";
}

// Special case for Aspire Dashboard
// Remove once https://github.com/dotnet/aspire/issues/2035 is fixed.
if (_productName.Contains("aspire-dashboard"))
{
archiveExt = "zip";
}

string optionalOs = _os.Contains("rpm") ? string.Empty : $"-{_os}";

// Each product name has one or more candidate URLs from which to retrieve the artifact. Multiple candidate URLs
// should be listed in priority order. Each subsequent URL listed is treated as a fallback.
string[] candidateUrls = _urls[_productName];

for (int candidateUrlIndex = 0; candidateUrlIndex < candidateUrls.Length; candidateUrlIndex++)
{
string baseUrl = ManifestHelper.GetBaseUrl(_manifestVariables.Value, _options);
string downloadUrl = candidateUrls[candidateUrlIndex]
.Replace("$DOTNET_BASE_URL", baseUrl)
.Replace("$ARCHIVE_EXT", archiveExt)
.Replace("$VERSION_DIR", versionDir)
.Replace("$VERSION_FILE", versionFile)
.Replace("$OS", _os)
.Replace("$OPTIONAL_OS", optionalOs)
.Replace("$ARCH", _arch)
.Replace("$DF_VERSION", _options.DockerfileVersion)
.Replace("..", ".");

bool isLastUrlToCheck =
candidateUrlIndex == candidateUrls.Length - 1;

string? result = GetArtifactShaAsync(downloadUrl, errorOnNotFound: isLastUrlToCheck).Result;
if (result is not null)
{
return result;
}
}

return null;
string downloadUrl = _urls[_productName]
.Replace("$DOTNET_BASE_URL", baseUrl)
.Replace("$ARCHIVE_EXT", archiveExt)
.Replace("$VERSION_DIR", versionDir)
.Replace("$VERSION_FILE", versionFile)
.Replace("$OS", _os)
.Replace("$ARCH", _arch)
.Replace("$DF_VERSION", _options.DockerfileVersion)
.Replace("..", ".");

return GetArtifactShaAsync(downloadUrl).Result;
}

private static string GetOs(string[] variableParts)
{
if (variableParts.Length == 4 && !Version.TryParse(variableParts[1], out _))
{
// Handles the case of "netstandard-targeting-pack-2.1.0|linux-rpm|x64|sha".
return variableParts[1];
}
else if (variableParts.Length >= 4)
if (variableParts.Length >= 4)
{
return variableParts[2];
}
Expand All @@ -263,20 +180,15 @@ private static string GetOs(string[] variableParts)

private static string GetArch(string[] variableParts)
{
if (variableParts.Length == 4 && !Version.TryParse(variableParts[1], out _))
{
// Handles the case of "netstandard-targeting-pack-2.1.0|linux-rpm|x64|sha".
return variableParts[2];
}
else if (variableParts.Length >= 5)
if (variableParts.Length >= 5)
{
return variableParts[3];
}

return string.Empty;
}

private async Task<string?> GetArtifactShaAsync(string downloadUrl, bool errorOnNotFound)
private async Task<string?> GetArtifactShaAsync(string downloadUrl)
{
if (!s_shaCache.TryGetValue(downloadUrl, out string? sha))
{
Expand All @@ -296,14 +208,7 @@ private static string GetArch(string[] variableParts)
else
{
string notFoundMsg = $"Unable to retrieve sha for '{downloadUrl}'.";
if (errorOnNotFound)
{
Trace.TraceError(notFoundMsg);
}
else
{
Trace.TraceWarning(notFoundMsg);
}
Trace.TraceError(notFoundMsg);
}
}

Expand Down Expand Up @@ -531,4 +436,3 @@ Other times the first line is the first checksum entry. This
}
}
}
#nullable disable
11 changes: 3 additions & 8 deletions eng/update-dependencies/GitHubHelper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Octokit;

#nullable enable
Expand All @@ -20,15 +15,15 @@ public static Task<Release> GetLatestRelease(string owner, string repo)
return releasesClient.GetLatest(owner, repo);
}

private static IReleasesClient GetReleasesClient()
private static IReleasesClient GetReleasesClient()
{
GitHubClient client = new(productInformation: GetProductHeaderValue());
return client.Repository.Release;
}

private static Octokit.ProductHeaderValue GetProductHeaderValue()
private static ProductHeaderValue GetProductHeaderValue()
{
const string AppName = "dotnet-docker-update-dependencies";
return new Octokit.ProductHeaderValue(AppName);
return new ProductHeaderValue(AppName);
}
}
1 change: 0 additions & 1 deletion eng/update-dependencies/GitHubReleaseUpdaterBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Microsoft.DotNet.VersionTools.Dependencies;
using Octokit;

Expand Down
1 change: 0 additions & 1 deletion eng/update-dependencies/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ public static T GetRequiredToken<T>(this JToken token, string name)
where T : JToken =>
(T)(token[name] ?? throw new InvalidOperationException($"Missing '{name}' property"));
}
#nullable disable
5 changes: 2 additions & 3 deletions eng/update-dependencies/NuGetConfigUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public NuGetConfigUpdater(string repoRoot, Options options)
_repoRoot = repoRoot;
_options = options;

string configSuffix = (_options.IsInternal ? ".internal" : _options.SourceBranch == "nightly" ? ".nightly" : string.Empty);
string configSuffix = _options.IsInternal ? ".internal" : _options.SourceBranch == "nightly" ? ".nightly" : string.Empty;
_configPath = Path.Combine(_repoRoot, $"tests/Microsoft.DotNet.Docker.Tests/TestAppArtifacts/NuGet.config{configSuffix}");
}

Expand Down Expand Up @@ -106,7 +106,7 @@ private void UpdatePackageSourceCredentials(string pkgSrcName, XElement configur
}

private void UpdatePackageSources(string sdkVersion, string pkgSrcName, XElement configuration)
{
{
XElement? pkgSources = configuration.Element("packageSources");
if (_options.IsInternal)
{
Expand Down Expand Up @@ -189,4 +189,3 @@ public Utf8StringWriter(StringBuilder stringBuilder)
public override Encoding Encoding => Encoding.UTF8;
}
}
#nullable disable
1 change: 0 additions & 1 deletion eng/update-dependencies/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,3 @@ public enum ReleaseState
Release
}
}
#nullable disable
7 changes: 2 additions & 5 deletions eng/update-dependencies/UpdateDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
using Microsoft.DotNet.VersionTools.Automation.GitHubApi;
using Microsoft.DotNet.VersionTools.Dependencies;
using Microsoft.DotNet.VersionTools.Dependencies.BuildOutput;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;

#nullable enable
namespace Dotnet.Docker
Expand Down Expand Up @@ -143,15 +140,15 @@ private static async Task CreatePullRequestAsync()

if (Options.IsInternal)
{
await PushToAzdoBranch(commitMessage, prOptions);
PushToAzdoBranch(commitMessage, prOptions);
}
else
{
await CreateGitHubPullRequest(commitMessage, prOptions, branchSuffix);
}
}

private static async Task PushToAzdoBranch(string commitMessage, PullRequestOptions prOptions)
private static void PushToAzdoBranch(string commitMessage, PullRequestOptions prOptions)
{
using Repository repo = new(RepoRoot);

Expand Down
1 change: 0 additions & 1 deletion eng/update-dependencies/VersionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,3 @@ private static Regex GetVersionVariableRegex(string versionVariableName) =>
$"(?<{s_versionGroupName}>[\\d]+.[\\d]+.[\\d]+(-[\\w]+(.[\\d]+)*)?)");
}
}
#nullable disable

0 comments on commit 9f7a9b5

Please sign in to comment.