Skip to content

Commit 66097fc

Browse files
committed
Sort versions in internal-versions.txt file
1 parent e4f1b25 commit 66097fc

File tree

6 files changed

+60
-23
lines changed

6 files changed

+60
-23
lines changed

eng/update-dependencies/FromStagingPipelineCommand.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Dotnet.Docker.Git;
55
using Dotnet.Docker.Sync;
6+
using Microsoft.DotNet.Docker.Shared;
67
using Microsoft.Extensions.Logging;
78

89
namespace Dotnet.Docker;
@@ -66,12 +67,13 @@ public override async Task<int> ExecuteAsync(FromStagingPipelineOptions options)
6667
options.StagingPipelineRunId);
6768

6869
string dotnetProductVersion = VersionHelper.ResolveProductVersion(releaseConfig.RuntimeBuild);
69-
string dockerfileVersion = VersionHelper.ResolveMajorMinorVersion(releaseConfig.RuntimeBuild).ToString();
70+
DotNetVersion dotNetVersion = DotNetVersion.Parse(releaseConfig.RuntimeBuild);
71+
string majorMinorVersionString = dotNetVersion.ToString(2);
7072

71-
// Record pipeline run ID for this dockerfileVersion, for later use by sync-internal-release command
73+
// Record pipeline run ID for this internal version, for later use by sync-internal-release command
7274
_internalVersionsService.RecordInternalStagingBuild(
7375
repoRoot: gitRepoContext.LocalRepoPath,
74-
dockerfileVersion: dockerfileVersion,
76+
dotNetVersion: dotNetVersion,
7577
stagingPipelineRunId: options.StagingPipelineRunId);
7678

7779
var productVersions = (options.Internal, releaseConfig.SdkOnly) switch
@@ -130,7 +132,7 @@ public override async Task<int> ExecuteAsync(FromStagingPipelineOptions options)
130132
var updateDependenciesOptions = new SpecificCommandOptions()
131133
{
132134
RepoRoot = gitRepoContext.LocalRepoPath,
133-
DockerfileVersion = dockerfileVersion.ToString(),
135+
DockerfileVersion = majorMinorVersionString,
134136
ProductVersions = productVersions,
135137
InternalBaseUrl = internalBaseUrl,
136138
};
@@ -144,10 +146,10 @@ public override async Task<int> ExecuteAsync(FromStagingPipelineOptions options)
144146
return exitCode;
145147
}
146148

147-
var commitMessage = $"Update .NET {dockerfileVersion} to {productVersions["sdk"]} SDK / {productVersions["runtime"]} Runtime";
149+
var commitMessage = $"Update .NET {majorMinorVersionString} to {productVersions["sdk"]} SDK / {productVersions["runtime"]} Runtime";
148150
var prTitle = $"[{options.TargetBranch}] {commitMessage}";
149151
var prBody = $"""
150-
This pull request updates .NET {dockerfileVersion} to the following versions:
152+
This pull request updates .NET {majorMinorVersionString} to the following versions:
151153
152154
- SDK: {productVersions["sdk"]}
153155
- Runtime: {productVersions["runtime"]}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.DotNet.Docker.Shared;
5+
using NuGet.Versioning;
6+
7+
namespace Dotnet.Docker.Sync;
8+
9+
/// <summary>
10+
/// <see cref="DotNetVersion"/> Extensions that are only used for release branch synchronization.
11+
/// </summary>
12+
internal static class DotNetVersionExtensions
13+
{
14+
/// <summary>
15+
/// Converts a <see cref="DotNetVersion"/> to a new <see cref="DotNetVersion"/>
16+
/// with only the major and minor version parts.
17+
/// </summary>
18+
public static DotNetVersion ToMajorMinorVersion(this DotNetVersion version) =>
19+
new DotNetVersion(new SemanticVersion(version.Major, version.Minor, 0));
20+
}

eng/update-dependencies/Sync/IInternalVersionsService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Microsoft.DotNet.Docker.Shared;
5+
46
namespace Dotnet.Docker.Sync;
57

68
/// <summary>
@@ -18,13 +20,13 @@ internal interface IInternalVersionsService
1820
/// Records a staging pipeline run ID in the repo.
1921
/// </summary>
2022
/// <remarks>
21-
/// This will only store one staging pipeline run ID per dockerfileVersion.
23+
/// This will only store one staging pipeline run ID per <paramref name="dotNetVersion"/>.
2224
/// If a version already exists for the same dockerfileVersion, it will be
2325
/// overwritten.
2426
/// </remarks>
25-
/// <param name="dockerfileVersion">major-minor version</param>
27+
/// <param name="dotNetVersion">.NET build or product version</param>
2628
/// <param name="stagingPipelineRunId">the build ID of the staging pipeline run</param>
27-
void RecordInternalStagingBuild(string repoRoot, string dockerfileVersion, int stagingPipelineRunId);
29+
void RecordInternalStagingBuild(string repoRoot, DotNetVersion dotNetVersion, int stagingPipelineRunId);
2830

2931
/// <summary>
3032
/// Gets any previously recorded internal staging builds in the repo.

eng/update-dependencies/Sync/InternalStagingBuilds.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Immutable;
5+
using Microsoft.DotNet.Docker.Shared;
56

67
namespace Dotnet.Docker.Sync;
78

@@ -12,7 +13,7 @@ namespace Dotnet.Docker.Sync;
1213
/// <param name="Versions">
1314
/// Mapping of Major.Minor .NET version to staging pipeline run ID.
1415
/// </param>
15-
internal sealed record InternalStagingBuilds(ImmutableDictionary<string, int> Versions)
16+
internal sealed record InternalStagingBuilds(ImmutableDictionary<DotNetVersion, int> Versions)
1617
{
1718
/// <summary>
1819
/// Parses <see cref=" InternalStagingBuilds"/> from lines of text.
@@ -25,7 +26,11 @@ public static InternalStagingBuilds Parse(IEnumerable<string> lines)
2526
var versions = lines
2627
.Select(line => line.Split('=', 2))
2728
.Where(parts => parts.Length == 2)
28-
.ToImmutableDictionary(parts => parts[0], parts => int.Parse(parts[1]));
29+
.ToImmutableDictionary(
30+
// Reduce the version to major.minor only.
31+
// If we don't, we could end up with multiple entries for the same version.
32+
parts => DotNetVersion.Parse(parts[0]).ToMajorMinorVersion(),
33+
parts => int.Parse(parts[1]));
2934

3035
return new InternalStagingBuilds(versions);
3136
}
@@ -34,9 +39,14 @@ public static InternalStagingBuilds Parse(IEnumerable<string> lines)
3439
/// Returns a new <see cref="InternalStagingBuilds"/> with the specified
3540
/// version added.
3641
/// </summary>
37-
public InternalStagingBuilds Add(string dockerfileVersion, int stagingPipelineRunId) =>
38-
this with { Versions = Versions.SetItem(dockerfileVersion, stagingPipelineRunId) };
42+
public InternalStagingBuilds Add(DotNetVersion dotNetVersion, int stagingPipelineRunId) =>
43+
this with { Versions = Versions.SetItem(dotNetVersion, stagingPipelineRunId) };
3944

45+
// Internal versions file should have one line per dockerfileVersion, and
46+
// each line should be formatted as: <dockerfileVersion>=<stagingPipelineRunId>
4047
public override string ToString() =>
41-
string.Join(Environment.NewLine, Versions.Select(kv => $"{kv.Key}={kv.Value}"));
48+
string.Join(Environment.NewLine,
49+
Versions
50+
.OrderBy(kv => kv.Key)
51+
.Select(kv => $"{kv.Key.ToString(2)}={kv.Value}"));
4252
}

eng/update-dependencies/Sync/InternalVersionsService.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Immutable;
5+
using Microsoft.DotNet.Docker.Shared;
56

67
namespace Dotnet.Docker.Sync;
78

@@ -21,12 +22,12 @@ public InternalStagingBuilds GetInternalStagingBuilds(string repoRoot)
2122
}
2223
catch (FileNotFoundException)
2324
{
24-
return new InternalStagingBuilds(ImmutableDictionary<string, int>.Empty);
25+
return new InternalStagingBuilds(ImmutableDictionary<DotNetVersion, int>.Empty);
2526
}
2627
}
2728

2829
/// <inheritdoc/>
29-
public void RecordInternalStagingBuild(string repoRoot, string dockerfileVersion, int stagingPipelineRunId)
30+
public void RecordInternalStagingBuild(string repoRoot, DotNetVersion dotNetVersion, int stagingPipelineRunId)
3031
{
3132
// Internal versions file should have one line per dockerfileVersion
3233
// Each line should be formatted as: <dockerfileVersion>=<stagingPipelineRunId>
@@ -38,10 +39,7 @@ public void RecordInternalStagingBuild(string repoRoot, string dockerfileVersion
3839
// 2) lots of regex JSON manipulation which is error-prone and harder to maintain
3940
//
4041
// So for now, the separate file and format is a compromise.
41-
42-
// Internal versions file should have one line per dockerfileVersion
43-
// Each line should be formatted as: <dockerfileVersion>=<stagingPipelineRunId>
44-
var builds = GetInternalStagingBuilds(repoRoot).Add(dockerfileVersion, stagingPipelineRunId);
42+
var builds = GetInternalStagingBuilds(repoRoot).Add(dotNetVersion, stagingPipelineRunId);
4543
var internalVersionFile = Path.Combine(repoRoot, InternalVersionsFileName);
4644
File.WriteAllText(internalVersionFile, builds.ToString());
4745
}

tests/UpdateDependencies.Tests/SyncInternalReleaseTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Dotnet.Docker.Git;
77
using Dotnet.Docker.Sync;
88
using Microsoft.DotNet.DarcLib;
9+
using Microsoft.DotNet.Docker.Shared;
910
using Microsoft.Extensions.Logging;
1011

1112
namespace UpdateDependencies.Tests;
@@ -224,7 +225,11 @@ public async Task Sync()
224225
: throw new Exception($"PR {PullRequestUrl} was not created first"));
225226

226227
// For this scenario, two internal versions have been checked in to this repo.
227-
var internalVersions = new Dictionary<string, int> { { "8.0", 8000000 }, { "10.0", 1000000 } };
228+
var internalVersions = new Dictionary<DotNetVersion, int>
229+
{
230+
{ DotNetVersion.Parse("8.0"), 8000000 },
231+
{ DotNetVersion.Parse("10.0"), 1000000 }
232+
};
228233
var internalVersionsService = CreateInternalVersionsService(LocalRepoPath, internalVersions);
229234

230235
var fromStagingPipelineCommandMock = new Mock<ICommand<FromStagingPipelineOptions>>();
@@ -239,7 +244,7 @@ public async Task Sync()
239244
exitCode.ShouldBe(0);
240245

241246
// Verify that we re-applied all internal versions by calling the downstream command.
242-
foreach ((string dotnetVersion, int buildId) in internalVersions)
247+
foreach ((_, int buildId) in internalVersions)
243248
{
244249
fromStagingPipelineCommandMock.Verify(command =>
245250
command.ExecuteAsync(It.Is<FromStagingPipelineOptions>(o =>
@@ -299,7 +304,7 @@ private SyncInternalReleaseCommand CreateCommand(
299304
/// Helper method to create a mock version of <see cref="IInternalVersionsService"/>
300305
/// </summary>
301306
private static IInternalVersionsService CreateInternalVersionsService(
302-
string repoPath, Dictionary<string, int> versions)
307+
string repoPath, Dictionary<DotNetVersion, int> versions)
303308
{
304309
var internalStagingBuilds = new InternalStagingBuilds(versions.ToImmutableDictionary());
305310

0 commit comments

Comments
 (0)