Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<clear />
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="dotnet-libraries" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion eng/Set-DotnetVersions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ if ($AzdoVariableName) {
Write-Host "##vso[task.setvariable variable=$AzdoVariableName]$updateDepsArgs"
}
else {
& dotnet run --project $PSScriptRoot/update-dependencies/update-dependencies.csproj @updateDepsArgs
& dotnet run --project $PSScriptRoot/update-dependencies/update-dependencies.csproj specific @updateDepsArgs
}
45 changes: 45 additions & 0 deletions eng/update-dependencies/BaseCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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<TOptions>() where TOptions : IOptions
{
public abstract Task<int> ExecuteAsync(TOptions options);

public static void Register<T>(IServiceCollection serviceCollection) where T : BaseCommand<TOptions>
{
serviceCollection.AddSingleton<BaseCommand<TOptions>, T>();
}

public static Command Create(string name, string description)
{
var command = new Command(name, description);

foreach (var option in TOptions.Options)
{
command.Add(option);
}

foreach (var argument in TOptions.Arguments)
{
command.Add(argument);
}

command.Action = Handler;
return command;
}

private static BindingHandler Handler =>
CommandHandler.Create<TOptions, IHost>(async (options, host) =>
{
var thisCommand = host.Services.GetRequiredService<BaseCommand<TOptions>>();
return await thisCommand.ExecuteAsync(options);
});
}
10 changes: 5 additions & 5 deletions eng/update-dependencies/BaseUrlUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ namespace Dotnet.Docker;
internal class BaseUrlUpdater : FileRegexUpdater
{
private const string BaseUrlGroupName = "BaseUrlValue";
private readonly Options _options;
private readonly SpecificCommandOptions _options;
private readonly JObject _manifestVariables;

public BaseUrlUpdater(string repoRoot, Options options)
public BaseUrlUpdater(string repoRoot, SpecificCommandOptions options)
{
Path = System.IO.Path.Combine(repoRoot, UpdateDependencies.VersionsFilename);
Path = System.IO.Path.Combine(repoRoot, SpecificCommand.VersionsFilename);
VersionGroupName = BaseUrlGroupName;
Regex = ManifestHelper.GetManifestVariableRegex(
ManifestHelper.GetBaseUrlVariableName(options.DockerfileVersion, options.SourceBranch, options.VersionSourceName),
$"(?<{BaseUrlGroupName}>.+)");
_options = options;

_manifestVariables = (JObject?)ManifestHelper.LoadManifest(UpdateDependencies.VersionsFilename)["variables"] ??
throw new InvalidOperationException($"'{UpdateDependencies.VersionsFilename}' property missing in '{UpdateDependencies.VersionsFilename}'"); ;
_manifestVariables = (JObject?)ManifestHelper.LoadManifest(SpecificCommand.VersionsFilename)["variables"] ??
throw new InvalidOperationException($"'{SpecificCommand.VersionsFilename}' property missing in '{SpecificCommand.VersionsFilename}'"); ;
}

protected override string TryGetDesiredValue(IEnumerable<IDependencyInfo> dependencyInfos, out IEnumerable<IDependencyInfo> usedDependencyInfos)
Expand Down
28 changes: 9 additions & 19 deletions eng/update-dependencies/DockerfileShaUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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.Collections.Generic;
Expand Down Expand Up @@ -38,13 +37,13 @@ public class DockerfileShaUpdater : FileRegexUpdater
private readonly string? _buildVersion;
private readonly string _arch;
private readonly string _os;
private readonly Options _options;
private readonly SpecificCommandOptions _options;
private readonly string _versions;
private readonly Dictionary<string, string> _urls;
private readonly Lazy<JObject> _manifestVariables;

public DockerfileShaUpdater(
string productName, string dockerfileVersion, string? buildVersion, string arch, string os, string versions, Options options)
string productName, string dockerfileVersion, string? buildVersion, string arch, string os, string versions, SpecificCommandOptions options)
{
_productName = productName;
_dockerfileVersion = new Version(dockerfileVersion);
Expand Down Expand Up @@ -74,10 +73,10 @@ public DockerfileShaUpdater(
() =>
{
const string VariablesProperty = "variables";
JToken? variables = ManifestHelper.LoadManifest(UpdateDependencies.VersionsFilename)[VariablesProperty];
JToken? variables = ManifestHelper.LoadManifest(SpecificCommand.VersionsFilename)[VariablesProperty];
if (variables is null)
{
throw new InvalidOperationException($"'{VariablesProperty}' property missing in '{UpdateDependencies.VersionsFilename}'");
throw new InvalidOperationException($"'{VariablesProperty}' property missing in '{SpecificCommand.VersionsFilename}'");
}
return (JObject)variables;
});
Expand All @@ -92,23 +91,14 @@ public DockerfileShaUpdater(
}

public static IEnumerable<IDependencyUpdater> CreateUpdaters(
string productName, string dockerfileVersion, string repoRoot, Options options)
string productName, string dockerfileVersion, string repoRoot, SpecificCommandOptions options)
{
string versionsPath = System.IO.Path.Combine(repoRoot, UpdateDependencies.VersionsFilename);
string versionsPath = System.IO.Path.Combine(repoRoot, SpecificCommand.VersionsFilename);
string versions = File.ReadAllText(versionsPath);

// The format of the sha variable name is '<productName>|<dockerfileVersion>|<os>|<arch>|sha'.
// The 'os' and 'arch' segments are optional.
string shaVariablePattern;
if (productName == NetStandard21TargetingPack)
{
// NetStandard targeting pack is not associated with a specific Dockerfile version
shaVariablePattern = $"\"(?<{ShaVariableGroupName}>{Regex.Escape(productName)}.*\\|sha)\":";
}
else
{
shaVariablePattern = $"\"(?<{ShaVariableGroupName}>{Regex.Escape(productName)}\\|{Regex.Escape(dockerfileVersion)}.*\\|sha)\":";
}
string shaVariablePattern = $"\"(?<{ShaVariableGroupName}>{Regex.Escape(productName)}\\|{Regex.Escape(dockerfileVersion)}.*\\|sha)\":";

Regex shaVariableRegex = new(shaVariablePattern);

Expand Down Expand Up @@ -151,7 +141,7 @@ public static IEnumerable<IDependencyUpdater> CreateUpdaters(
// 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 versionFile = SpecificCommand.ResolveProductVersion(versionDir, _options);

string downloadUrl = _urls[_productName]
.Replace("$DOTNET_BASE_URL", baseUrl)
Expand Down Expand Up @@ -416,7 +406,7 @@ Other times the first line is the first checksum entry. This
return checksumEntries;
}

private static string? GetBuildVersion(string productName, string dockerfileVersion, string variables, Options options)
private static string? GetBuildVersion(string productName, string dockerfileVersion, string variables, SpecificCommandOptions options)
{
string? buildVersion;
if (options.ProductVersions.TryGetValue(productName, out string? version))
Expand Down
13 changes: 13 additions & 0 deletions eng/update-dependencies/IOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.CommandLine;

namespace Dotnet.Docker;

public interface IOptions
{
public static abstract List<Option> Options { get; }
public static abstract List<Argument> Arguments { get; }
}
5 changes: 2 additions & 3 deletions eng/update-dependencies/ManifestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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.IO;
Expand All @@ -22,7 +21,7 @@ public static partial class ManifestHelper
/// </summary>
/// <param name="manifestVariables">JSON object of the variables from the manifest.</param>
/// <param name="options">Configured options from the app.</param>
public static string GetBaseUrl(JObject manifestVariables, Options options) =>
public static string GetBaseUrl(JObject manifestVariables, SpecificCommandOptions options) =>
ResolveVariableValue(GetBaseUrlVariableName(options.DockerfileVersion, options.SourceBranch, options.VersionSourceName), manifestVariables);

/// <summary>
Expand Down Expand Up @@ -94,7 +93,7 @@ public static string GetVariableValue(string variableName, JObject variables)
/// <param name="filename">Name, not path, of the manifest file located at the root of the repo.</param>
public static JObject LoadManifest(string filename)
{
string path = Path.Combine(UpdateDependencies.RepoRoot, filename);
string path = Path.Combine(SpecificCommand.RepoRoot, filename);
string contents = File.ReadAllText(path);
return JObject.Parse(contents);
}
Expand Down
5 changes: 2 additions & 3 deletions eng/update-dependencies/NuGetConfigUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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.Collections.Generic;
Expand All @@ -19,10 +18,10 @@ internal class NuGetConfigUpdater : IDependencyUpdater
{
private const string PkgSrcSuffix = "_internal";
private readonly string _repoRoot;
private readonly Options _options;
private readonly SpecificCommandOptions _options;
private readonly string _configPath;

public NuGetConfigUpdater(string repoRoot, Options options)
public NuGetConfigUpdater(string repoRoot, SpecificCommandOptions options)
{
_repoRoot = repoRoot;
_options = options;
Expand Down
125 changes: 0 additions & 125 deletions eng/update-dependencies/Options.cs

This file was deleted.

26 changes: 26 additions & 0 deletions eng/update-dependencies/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using System.CommandLine.Hosting;
using Dotnet.Docker;
using Microsoft.Extensions.Hosting;

var rootCommand = new RootCommand()
{
SpecificCommand.Create(
name: "specific",
description: "Update dependencies using specific product versions"),
};

var config = new CommandLineConfiguration(rootCommand);

config.UseHost(
_ => Host.CreateDefaultBuilder(),
host => host.ConfigureServices(services =>
{
SpecificCommand.Register<SpecificCommand>(services);
})
);

return await config.InvokeAsync(args);
10 changes: 10 additions & 0 deletions eng/update-dependencies/ReleaseState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Dotnet.Docker;

public enum ReleaseState
{
Prerelease,
Release
}
Loading