diff --git a/eng/update-dependencies/BaseCommand.cs b/eng/update-dependencies/BaseCommand.cs index d5d459528d..402b3e7fc3 100644 --- a/eng/update-dependencies/BaseCommand.cs +++ b/eng/update-dependencies/BaseCommand.cs @@ -3,13 +3,12 @@ using System.CommandLine; using System.CommandLine.NamingConventionBinder; -using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace Dotnet.Docker; -public abstract class BaseCommand() where TOptions : IOptions +public abstract class BaseCommand() : ICommand where TOptions : IOptions { public abstract Task ExecuteAsync(TOptions options); @@ -34,7 +33,7 @@ public static Command Create(string name, string description) private static BindingHandler Handler => CommandHandler.Create(async (options, host) => { - var thisCommand = host.Services.GetRequiredService>(); + var thisCommand = host.Services.GetRequiredService>(); return await thisCommand.ExecuteAsync(options); }); } diff --git a/eng/update-dependencies/BaseUrlUpdater.cs b/eng/update-dependencies/BaseUrlUpdater.cs index d9e7909061..4b65bfbdef 100644 --- a/eng/update-dependencies/BaseUrlUpdater.cs +++ b/eng/update-dependencies/BaseUrlUpdater.cs @@ -17,7 +17,7 @@ internal class BaseUrlUpdater : FileRegexUpdater { private const string BaseUrlGroupName = "BaseUrlValue"; private readonly SpecificCommandOptions _options; - private readonly JObject _manifestVariables; + private readonly ManifestVariables _manifestVariables; private readonly string _manifestVariableName; /// @@ -25,40 +25,36 @@ internal class BaseUrlUpdater : FileRegexUpdater /// If the base URL variable cannot be found in the manifest, the updater /// won't do anything. /// - public static IDependencyUpdater Create(string repoRoot, SpecificCommandOptions options) + public static IDependencyUpdater Create(ManifestVariables manifestVariables, SpecificCommandOptions options) { - // Load manifest and extract variables once so the constructor doesn't duplicate this logic - var manifest = ManifestHelper.LoadManifest(SpecificCommand.VersionsFilename); - var manifestVariables = (JObject?)manifest["variables"]; - if (manifestVariables is null) { Trace.TraceWarning("BaseUrlUpdater: manifest variables missing - skipping base URL update."); return new EmptyDependencyUpdater(); } + var upstreamBranch = manifestVariables.GetValue("branch"); string baseUrlVarName = ManifestHelper.GetBaseUrlVariableName( - options.DockerfileVersion, - options.SourceBranch, - options.VersionSourceName, - options.IsSdkOnly); + dockerfileVersion: options.DockerfileVersion, + branch: upstreamBranch, + versionSourceName: options.VersionSourceName, + sdkOnlyRelease: options.IsSdkOnly); - if (!manifestVariables.ContainsKey(baseUrlVarName)) + if (!manifestVariables.HasValue(baseUrlVarName)) { Trace.TraceWarning($"BaseUrlUpdater: variable '{baseUrlVarName}' not found - skipping base URL update."); return new EmptyDependencyUpdater(); } - return new BaseUrlUpdater(repoRoot, options, manifestVariables, baseUrlVarName); + return new BaseUrlUpdater(options, manifestVariables, baseUrlVarName); } private BaseUrlUpdater( - string repoRoot, SpecificCommandOptions options, - JObject manifestVariables, + ManifestVariables manifestVariables, string manifestVariableName) { - Path = System.IO.Path.Combine(repoRoot, SpecificCommand.VersionsFilename); + Path = options.GetManifestVersionsFilePath(); VersionGroupName = BaseUrlGroupName; _options = options; _manifestVariables = manifestVariables; @@ -72,7 +68,7 @@ protected override string TryGetDesiredValue(IEnumerable depend usedDependencyInfos = Enumerable.Empty(); string baseUrlVersionVarName = _manifestVariableName; - string unresolvedBaseUrl = _manifestVariables[baseUrlVersionVarName]?.ToString() ?? + string unresolvedBaseUrl = _manifestVariables.Variables[baseUrlVersionVarName]?.ToString() ?? throw new InvalidOperationException($"Variable with name '{baseUrlVersionVarName}' is missing."); if (_options.IsInternal) diff --git a/eng/update-dependencies/CreatePullRequestOptions.cs b/eng/update-dependencies/CreatePullRequestOptions.cs index 46e88b2d51..36f0bdc737 100644 --- a/eng/update-dependencies/CreatePullRequestOptions.cs +++ b/eng/update-dependencies/CreatePullRequestOptions.cs @@ -8,33 +8,43 @@ namespace Dotnet.Docker; public abstract record CreatePullRequestOptions { - private string? _targetBranch = null; + private string _azdoOrganizationUrl = ""; + + /// + /// The root of the dotnet-docker repo to run against. + /// + public string RepoRoot { get; init; } = Directory.GetCurrentDirectory(); public string User { get; init; } = ""; public string Email { get; init; } = ""; public string Password { get; init; } = ""; - public string AzdoOrganization { get; init; } = ""; + public string AzdoOrganization + { + get => _azdoOrganizationUrl; + init => _azdoOrganizationUrl = value.TrimEnd('/'); + } public string AzdoProject { get; init; } = ""; public string AzdoRepo { get; init; } = ""; public string VersionSourceName { get; init; } = ""; - public string SourceBranch { get; init; } = "nightly"; - public string TargetBranch - { - get => _targetBranch ?? SourceBranch; - init => _targetBranch = value; - } + public string SourceBranch { get; init; } = ""; + public string TargetBranch { get; init; } = "nightly"; public static List