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 Dotnet . Docker . Sync ;
45using Microsoft . Extensions . Logging ;
56
67namespace Dotnet . Docker ;
78
89internal partial class FromStagingPipelineCommand (
910 ILogger < FromStagingPipelineCommand > logger ,
10- PipelineArtifactProvider pipelineArtifactProvider )
11+ PipelineArtifactProvider pipelineArtifactProvider ,
12+ IInternalVersionsService internalVersionsService )
1113 : BaseCommand < FromStagingPipelineOptions >
1214{
1315 private readonly ILogger < FromStagingPipelineCommand > _logger = logger ;
1416 private readonly PipelineArtifactProvider _pipelineArtifactProvider = pipelineArtifactProvider ;
17+ private readonly IInternalVersionsService _internalVersionsService = internalVersionsService ;
1518
1619 public override async Task < int > ExecuteAsync ( FromStagingPipelineOptions options )
1720 {
@@ -44,7 +47,10 @@ public override async Task<int> ExecuteAsync(FromStagingPipelineOptions options)
4447 string dockerfileVersion = VersionHelper . ResolveMajorMinorVersion ( releaseConfig . RuntimeBuild ) . ToString ( ) ;
4548
4649 // Record pipeline run ID for this dockerfileVersion, for later use by sync-internal-release command
47- RecordInternalVersion ( dockerfileVersion , options . StagingPipelineRunId . ToString ( ) ) ;
50+ _internalVersionsService . RecordInternalStagingBuild (
51+ options . RepoRoot ,
52+ dockerfileVersion ,
53+ options . StagingPipelineRunId ) ;
4854
4955 var productVersions = ( options . Internal , releaseConfig . SdkOnly ) switch
5056 {
@@ -90,6 +96,7 @@ public override async Task<int> ExecuteAsync(FromStagingPipelineOptions options)
9096 var updateDependencies = new SpecificCommand ( ) ;
9197 var updateDependenciesOptions = new SpecificCommandOptions ( )
9298 {
99+ RepoRoot = options . RepoRoot ,
93100 DockerfileVersion = dockerfileVersion . ToString ( ) ,
94101 ProductVersions = productVersions ,
95102
@@ -109,59 +116,6 @@ public override async Task<int> ExecuteAsync(FromStagingPipelineOptions options)
109116 return await updateDependencies . ExecuteAsync ( updateDependenciesOptions ) ;
110117 }
111118
112- /// <summary>
113- /// Records the staging pipeline run ID in an easy to parse format. This
114- /// can be used by the sync-internal-release pipeline to record and
115- /// re-apply the same staging builds after resetting the state of the repo
116- /// to match the public release branch.
117- /// </summary>
118- /// <remarks>
119- /// This will only store one staging pipeline run ID per dockerfileVersion
120- /// </remarks>
121- /// <param name="dockerfileVersion">major-minor version</param>
122- /// <param name="stagingPipelineRunId">the build ID of the staging pipeline run</param>
123- private void RecordInternalVersion ( string dockerfileVersion , string stagingPipelineRunId )
124- {
125- const string InternalVersionsFile = "internal-versions.txt" ;
126-
127- // Internal versions file should have one line per dockerfileVersion
128- // Each line should be formatted as: <dockerfileVersion>=<stagingPipelineRunId>
129- //
130- // The preferable way to do this would be to record the version in
131- // manifest.versions.json, however that would require one of the following:
132- // 1) round-trip serialization, which would remove any whitespace/blank lines - which are
133- // important for keeping the file readable and reducing git merge conflicts
134- // 2) lots of regex JSON manipulation which is error-prone and harder to maintain
135- //
136- // So for now, the separate file and format is a compromise.
137-
138- var versionsFilePath = Path . GetFullPath ( SpecificCommand . VersionsFilename ) ;
139- var versionsFileDir = Path . GetDirectoryName ( versionsFilePath ) ?? "" ;
140- var internalVersionFile = Path . Combine ( versionsFileDir , InternalVersionsFile ) ;
141- Dictionary < string , string > versions = [ ] ;
142-
143- _logger . LogInformation (
144- "Recording staging pipeline build ID in {internalVersionFile}" ,
145- internalVersionFile ) ;
146-
147- try
148- {
149- // File already exists - read existing versions
150- versions = File . ReadAllLines ( internalVersionFile )
151- . Select ( line => line . Split ( '=' , 2 ) )
152- . Where ( parts => parts . Length == 2 )
153- . ToDictionary ( parts => parts [ 0 ] , parts => parts [ 1 ] ) ;
154- }
155- catch ( FileNotFoundException )
156- {
157- // File doesn't exist - it will be created
158- }
159-
160- versions [ dockerfileVersion ] = stagingPipelineRunId ;
161- var versionLines = versions . Select ( kv => $ "{ kv . Key } ={ kv . Value } ") ;
162- File . WriteAllLines ( internalVersionFile , versionLines ) ;
163- }
164-
165119 /// <summary>
166120 /// Formats a storage account URL has a specific format:
167121 /// - Starts with "https://"
0 commit comments