-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rollout] Production rollout 2025-01-20 (#4346)
- Loading branch information
Showing
64 changed files
with
1,551 additions
and
409 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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
99 changes: 99 additions & 0 deletions
99
src/Microsoft.DotNet.Darc/DarcLib/Conflicts/BackFlowConflictResolver.cs
This file contains 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,99 @@ | ||
// 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; | ||
using System.Threading.Tasks; | ||
using Microsoft.DotNet.DarcLib.Helpers; | ||
using Microsoft.Extensions.Logging; | ||
|
||
#nullable enable | ||
namespace Microsoft.DotNet.DarcLib.Conflicts; | ||
|
||
public interface IBackFlowConflictResolver | ||
{ | ||
Task<bool> TryMergingRepoBranch( | ||
ILocalGitRepo repo, | ||
string baseBranch, | ||
string targetBranch); | ||
} | ||
|
||
/// <summary> | ||
/// This class is responsible for resolving well-known conflicts that can occur during a backflow operation. | ||
/// The conflicts can happen when backward and forward flow PRs get merged out of order. | ||
/// This can be shown on the following schema (the order of events is numbered): | ||
/// | ||
/// repo VMR | ||
/// O────────────────────►O | ||
/// │ 2. │ | ||
/// 1.O────────────────O │ | ||
/// │ 4. │ │ | ||
/// │ O───────────┼────O 3. | ||
/// │ │ │ │ | ||
/// │ │ │ │ | ||
/// 6.O◄───┘ └───►O 5. | ||
/// │ 7. │ | ||
/// │ O───────────────| | ||
/// 8.O◄────┘ │ | ||
/// │ │ | ||
/// | ||
/// The conflict arises in step 8. and is caused by the fact that: | ||
/// - When the backflow PR branch is being opened in 7., the last sync (from the point of view of 5.) is from 1. | ||
/// - This means that the PR branch will be based on 1. (the real PR branch will be a commit on top of 1.) | ||
/// - This means that when 6. merged, Version.Details.xml got updated with the SHA of the 3. | ||
/// - So the Source tag in Version.Details.xml in 6. contains the SHA of 3. | ||
/// - The backflow PR branch contains the SHA of 5. | ||
/// - So the Version.Details.xml file conflicts on the SHA (3. vs 5.) | ||
/// - There's also a similar conflict in the package versions that got updated in those commits. | ||
/// - However, if only the version files are in conflict, we can try merging 6. into 7. and resolve the conflict. | ||
/// - This is because basically we know we want to set the version files to point at 5. | ||
/// </summary> | ||
public class BackFlowConflictResolver : CodeFlowConflictResolver, IBackFlowConflictResolver | ||
{ | ||
private readonly ILogger<ForwardFlowConflictResolver> _logger; | ||
|
||
public BackFlowConflictResolver(ILogger<ForwardFlowConflictResolver> logger) | ||
: base(logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public async Task<bool> TryMergingRepoBranch( | ||
ILocalGitRepo repo, | ||
string targetBranch, | ||
string branchToMerge) | ||
{ | ||
return await TryMergingBranch(repo, targetBranch, branchToMerge); | ||
} | ||
|
||
protected override async Task<bool> TryResolvingConflicts(ILocalGitRepo repo, IEnumerable<UnixPath> conflictedFiles) | ||
{ | ||
foreach (var filePath in conflictedFiles) | ||
{ | ||
// Known conflict in eng/Version.Details.xml | ||
if (string.Equals(filePath, VersionFiles.VersionDetailsXml, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
await Task.CompletedTask; | ||
return false; | ||
|
||
// TODO https://github.com/dotnet/arcade-services/issues/4196: Resolve conflicts in eng/Version.Details.xml | ||
// return true; | ||
} | ||
|
||
// Known conflict in eng/Versions.props | ||
if (string.Equals(filePath, VersionFiles.VersionProps, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
await Task.CompletedTask; | ||
return false; | ||
|
||
// TODO https://github.com/dotnet/arcade-services/issues/4196: Resolve conflicts in eng/Version.Details.xml | ||
// return true; | ||
} | ||
|
||
_logger.LogInformation("Unable to resolve conflicts in {file}", filePath); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/Microsoft.DotNet.Darc/DarcLib/Conflicts/CodeFlowConflictResolver.cs
This file contains 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,76 @@ | ||
// 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; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.DotNet.DarcLib.Helpers; | ||
using Microsoft.Extensions.Logging; | ||
|
||
#nullable enable | ||
namespace Microsoft.DotNet.DarcLib.Conflicts; | ||
|
||
/// <summary> | ||
/// This class is responsible for resolving well-known conflicts that can occur during codeflow operations. | ||
/// The conflicts usually happen when backward a forward flow PRs get merged out of order. | ||
/// </summary> | ||
public abstract class CodeFlowConflictResolver | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public CodeFlowConflictResolver(ILogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
protected async Task<bool> TryMergingBranch( | ||
ILocalGitRepo repo, | ||
string targetBranch, | ||
string branchToMerge) | ||
{ | ||
_logger.LogInformation("Trying to merge target branch {targetBranch} into {baseBranch}", branchToMerge, targetBranch); | ||
|
||
await repo.CheckoutAsync(targetBranch); | ||
var result = await repo.RunGitCommandAsync(["merge", "--no-commit", "--no-ff", branchToMerge]); | ||
if (result.Succeeded) | ||
{ | ||
_logger.LogInformation("Successfully merged the branch {targetBranch} into {headBranch} in {repoPath}", | ||
branchToMerge, | ||
targetBranch, | ||
repo.Path); | ||
await repo.CommitAsync($"Merging {branchToMerge} into {targetBranch}", allowEmpty: true); | ||
return true; | ||
} | ||
|
||
result = await repo.RunGitCommandAsync(["diff", "--name-only", "--diff-filter=U", "--relative"]); | ||
if (!result.Succeeded) | ||
{ | ||
_logger.LogInformation("Failed to merge the branch {targetBranch} into {headBranch} in {repoPath}", | ||
branchToMerge, | ||
targetBranch, | ||
repo.Path); | ||
result = await repo.RunGitCommandAsync(["merge", "--abort"]); | ||
return false; | ||
} | ||
|
||
var conflictedFiles = result.StandardOutput | ||
.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries) | ||
.Select(line => new UnixPath(line.Trim())); | ||
|
||
if (!await TryResolvingConflicts(repo, conflictedFiles)) | ||
{ | ||
result = await repo.RunGitCommandAsync(["merge", "--abort"]); | ||
return false; | ||
} | ||
|
||
_logger.LogInformation("Successfully resolved version file conflicts between branches {targetBranch} and {headBranch} in {repoPath}", | ||
branchToMerge, | ||
targetBranch, | ||
repo.Path); | ||
await repo.CommitAsync($"Merge branch {branchToMerge} into {targetBranch}", allowEmpty: false); | ||
return true; | ||
} | ||
|
||
protected abstract Task<bool> TryResolvingConflicts(ILocalGitRepo repo, IEnumerable<UnixPath> conflictedFiles); | ||
} |
Oops, something went wrong.