-
Notifications
You must be signed in to change notification settings - Fork 81
Store SHA/version of synced repos in VMR using .props files
#2014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
56b416b
Add VmrDependencyInfo
premun 929ab3d
Plumb package version through Manager
premun 3f24915
Implement the DependencyInfo class
premun 202c22c
Rename VmrDependencyInfo to VmrDependencyTracker
premun c1d807b
Resolve nullability issue
premun d2af7bc
Fix DI, bugs
premun a37758d
Fix version property
premun 8593655
Create directory for XMLs
premun f5b9fc6
Add type for the sha/version tuple
premun 94e785a
Renamed parentDir
premun 5af934f
Disallow null for version updates
premun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/Microsoft.DotNet.Darc/src/DarcLib/VirtualMonoRepo/VmrDependencyTracker.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Threading; | ||
| using Microsoft.DotNet.Darc.Models.VirtualMonoRepo; | ||
|
|
||
| #nullable enable | ||
| namespace Microsoft.DotNet.DarcLib.VirtualMonoRepo; | ||
|
|
||
| public record VmrDependencyVersion(string Sha, string? PackageVersion); | ||
|
|
||
| public interface IVmrDependencyTracker | ||
| { | ||
| string VmrPath { get; } | ||
|
|
||
| string SourcesPath { get; } | ||
|
|
||
| IReadOnlyCollection<SourceMapping> Mappings { get; } | ||
|
|
||
| string GetRepoSourcesPath(SourceMapping mapping) => Path.Combine(SourcesPath, mapping.Name); | ||
|
|
||
| void UpdateDependencyVersion(SourceMapping mapping, VmrDependencyVersion version); | ||
|
|
||
| VmrDependencyVersion? GetDependencyVersion(SourceMapping mapping); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Holds information about versions of individual repositories synchronized in the VMR. | ||
| /// Uses the AllRepoVersions.props file as source of truth and propagates changes into the git-info files. | ||
| /// </summary> | ||
| public class VmrDependencyTracker : IVmrDependencyTracker | ||
| { | ||
| public const string SourceMappingsFileName = "source-mappings.json"; | ||
| public const string VmrSourcesDir = "src"; | ||
| public const string GitInfoSourcesDir = "git-info"; | ||
|
|
||
| // TODO: https://github.com/dotnet/source-build/issues/2250 | ||
| private const string DefaultVersion = "8.0.100"; | ||
|
|
||
| private readonly Lazy<AllVersionsPropsFile> _repoVersions; | ||
| private readonly string _allVersionsFilePath; | ||
|
|
||
| public string VmrPath { get; } | ||
|
|
||
| public string SourcesPath { get; } | ||
|
|
||
| public IReadOnlyCollection<SourceMapping> Mappings { get; } | ||
|
|
||
| public VmrDependencyTracker( | ||
| IVmrManagerConfiguration configuration, | ||
| IReadOnlyCollection<SourceMapping> mappings) | ||
| { | ||
| VmrPath = configuration.VmrPath; | ||
| SourcesPath = Path.Combine(configuration.VmrPath, VmrSourcesDir); | ||
| Mappings = mappings; | ||
|
|
||
| _allVersionsFilePath = Path.Combine(VmrPath, GitInfoSourcesDir, AllVersionsPropsFile.FileName); | ||
| _repoVersions = new Lazy<AllVersionsPropsFile>(LoadAllVersionsFile, LazyThreadSafetyMode.ExecutionAndPublication); | ||
| } | ||
|
|
||
| public VmrDependencyVersion? GetDependencyVersion(SourceMapping mapping) | ||
| => _repoVersions.Value.GetVersion(mapping.Name); | ||
|
|
||
| public void UpdateDependencyVersion(SourceMapping mapping, VmrDependencyVersion version) | ||
| { | ||
| // TODO: https://github.com/dotnet/source-build/issues/2250 | ||
| if (version.PackageVersion is null) | ||
| { | ||
| version = version with { PackageVersion = DefaultVersion }; | ||
| } | ||
|
|
||
| _repoVersions.Value.UpdateVersion(mapping.Name, version.Sha, version.PackageVersion); | ||
| _repoVersions.Value.SerializeToXml(_allVersionsFilePath); | ||
|
|
||
| var (buildId, releaseLabel) = VersionFiles.DeriveBuildInfo(mapping.Name, version.PackageVersion); | ||
|
|
||
| var gitInfo = new GitInfoFile | ||
| { | ||
| GitCommitHash = version.Sha, | ||
| OfficialBuildId = buildId, | ||
| PreReleaseVersionLabel = releaseLabel, | ||
| IsStable = string.IsNullOrWhiteSpace(releaseLabel), | ||
| OutputPackageVersion = version.PackageVersion, | ||
| }; | ||
|
|
||
| gitInfo.SerializeToXml(GetGitInfoFilePath(mapping)); | ||
| } | ||
|
|
||
| private AllVersionsPropsFile LoadAllVersionsFile() | ||
| { | ||
| if (!File.Exists(_allVersionsFilePath)) | ||
| { | ||
| return new AllVersionsPropsFile(new()); | ||
| } | ||
|
|
||
| return AllVersionsPropsFile.DeserializeFromXml(_allVersionsFilePath); | ||
| } | ||
|
|
||
| private string GetGitInfoFilePath(SourceMapping mapping) => Path.Combine(VmrPath, GitInfoSourcesDir, $"{mapping.Name}.props"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.