Skip to content

Allow ReproTool's flow-commit to work for non-VMR subscriptions #4755

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 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions tools/ProductConstructionService.ReproTool/DarcProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ public async Task<AsyncDisposableValue<string>> CreateSubscriptionAsync(
{
logger.LogInformation("Creating a test subscription");

string[] directoryArg = !string.IsNullOrEmpty(sourceDirectory) ?
["--source-directory", sourceDirectory] :
["--target-directory", targetDirectory!];
string[] directoryArg = (sourceDirectory?.Length, targetDirectory?.Length) switch
{
(> 0, _) => ["--source-directory", sourceDirectory],
(_, > 0) => ["--target-directory", targetDirectory],
_ => []
};

string[] excludedAssetsParameter = excludedAssets != null ?
[ "--excluded-assets", string.Join(';', excludedAssets) ] :
Expand All @@ -157,7 +160,7 @@ public async Task<AsyncDisposableValue<string>> CreateSubscriptionAsync(
"--target-branch", targetBranch,
"-q",
"--no-trigger",
"--source-enabled", "true",
"--source-enabled", directoryArg.Length > 0 ? "true" : "false",
"--update-frequency", "none",
.. directoryArg,
.. excludedAssetsParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,33 @@ internal override async Task RunAsync()
Channel? channel = channels.FirstOrDefault(c => c.Name == _options.Channel)
?? await _localPcsApi.Channels.CreateChannelAsync("test", _options.Channel);

var subscriptions = await _localPcsApi.Subscriptions.ListSubscriptionsAsync(
channelId: channel.Id,
sourceRepository: _options.SourceRepository,
targetRepository: _options.TargetRepository,
sourceEnabled: true);

var (repoName, owner) = GitRepoUrlUtils.GetRepoNameAndOwner(_options.SourceRepository);

var isBackflow = false;
bool? isBackflow = null;
try
{
(repoName, owner) = GitRepoUrlUtils.GetRepoNameAndOwner(_options.TargetRepository);
await _ghClient.Repository.Content.GetAllContents(owner, repoName, SourceMappingsPath);
isBackflow = true;
isBackflow = false;
}
catch { }

var mappingName = (isBackflow ? _options.TargetRepository : _options.SourceRepository).TrimEnd('/').Split('/').Last();
if (!isBackflow.HasValue)
{
try
{
(repoName, owner) = GitRepoUrlUtils.GetRepoNameAndOwner(_options.SourceRepository);
await _ghClient.Repository.Content.GetAllContents(owner, repoName, SourceMappingsPath);
isBackflow = true;
}
catch { }
}

var subscriptions = await _localPcsApi.Subscriptions.ListSubscriptionsAsync(
channelId: channel.Id,
sourceRepository: _options.SourceRepository,
targetRepository: _options.TargetRepository,
sourceEnabled: isBackflow.HasValue);

Subscription subscription = subscriptions.FirstOrDefault(s => s.TargetBranch == _options.TargetBranch)
?? await _localPcsApi.Subscriptions.CreateAsync(
Expand All @@ -79,9 +89,9 @@ internal override async Task RunAsync()
},
null)
{
SourceEnabled = true,
SourceDirectory = isBackflow ? mappingName : null,
TargetDirectory = isBackflow ? null : mappingName,
SourceEnabled = isBackflow.HasValue,
SourceDirectory = isBackflow.HasValue && isBackflow.Value ? repoName : null,
TargetDirectory = isBackflow.HasValue && !isBackflow.Value ? repoName : null,
});

var commit = (await _ghClient.Repository.Branch.Get(owner, repoName, _options.SourceBranch)).Commit;
Expand All @@ -103,6 +113,14 @@ internal override async Task RunAsync()
{
GitHubRepository = _options.SourceRepository,
GitHubBranch = _options.SourceBranch,
Assets =
[
.._options.Packages.Select(p => new AssetData(true)
{
Name = p,
Version = $"1.0.0-{Guid.NewGuid().ToString().Substring(0, 8)}",
})
],
});

await using var _ = await _darc.AddBuildToChannelAsync(build.Id, channel.Name, skipCleanup: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ internal class FlowCommitOptions : Options
[Option("target-branch", HelpText = "Branch to flow the commit into", Required = true)]
public required string TargetBranch { get; init; }

[Option("package", HelpText = "Name(s) of package(s) to include in the flown build", Required = false)]
public IEnumerable<string> Packages { get; init; } = [];

internal override Operation GetOperation(IServiceProvider sp)
=> ActivatorUtilities.CreateInstance<FlowCommitOperation>(sp, this);
}