22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System . Collections . Immutable ;
5+ using Microsoft . DotNet . Docker . Shared ;
56
67namespace 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}
0 commit comments