Skip to content

Add flat flow test functionality to the ReproTool #4559

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 13 commits into from
Apr 3, 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
14 changes: 0 additions & 14 deletions tools/FlatFlowMigrationCli/Constants.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.DarcLib;
using Microsoft.DotNet.ProductConstructionService.Client;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Tools.Common;
using GitHubClient = Octokit.GitHubClient;

namespace ProductConstructionService.ReproTool.Operations;

internal class ForwardFlowTestOperation(
VmrDependencyResolver vmrDependencyResolver,
ILogger<ForwardFlowTestOperation> logger,
GitHubClient ghClient,
DarcProcessManager darcProcessManager,
IBarApiClient prodBarClient,
[FromKeyedServices("local")] IProductConstructionServiceApi localPcsApi) : Operation(logger, ghClient, localPcsApi)
{
internal override async Task RunAsync()
{
await darcProcessManager.InitializeAsync();

var vmrRepos = await vmrDependencyResolver.GetVmrRepositoriesAsync(
"https://github.com/dotnet/dotnet",
"https://github.com/dotnet/sdk",
"main");

var vmrTestBranch = await PrepareVmrForkAsync("main", skipCleanup: true);

var channelName = $"repro-{Guid.NewGuid()}";
await using var channel = await darcProcessManager.CreateTestChannelAsync(channelName, true);

foreach (var vmrRepo in vmrRepos)
{
var productRepoForkUri = $"{ProductRepoFormat}{vmrRepo.Mapping.DefaultRemote.Split('/', StringSplitOptions.RemoveEmptyEntries).Last()}";
var latestBuild = await prodBarClient.GetLatestBuildAsync(vmrRepo.Mapping.DefaultRemote, vmrRepo.Channel.Channel.Id);

var productRepoTmpBranch = await PrepareProductRepoForkAsync(vmrRepo.Mapping.DefaultRemote, productRepoForkUri, latestBuild.GetBranch(), false);

var testBuild = await CreateBuildAsync(
productRepoForkUri,
productRepoTmpBranch.Value,
latestBuild.Commit,
[]);

await UpdateVmrSourceFiles(
vmrTestBranch.Value,
vmrRepo.Mapping.DefaultRemote,
productRepoForkUri);

await using var testSubscription = await darcProcessManager.CreateSubscriptionAsync(
channel: channelName,
sourceRepo: productRepoForkUri,
targetRepo: VmrForkUri,
targetBranch: vmrTestBranch.Value,
sourceDirectory: null,
targetDirectory: vmrRepo.Mapping.Name,
skipCleanup: true);

await darcProcessManager.AddBuildToChannelAsync(testBuild.Id, channelName, skipCleanup: true);

await TriggerSubscriptionAsync(testSubscription.Value);
}
}
}
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 Microsoft.DotNet.DarcLib;
using Microsoft.DotNet.ProductConstructionService.Client;
using Microsoft.DotNet.ProductConstructionService.Client.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ProductConstructionService.ReproTool.Options;
using Tools.Common;
using GitHubClient = Octokit.GitHubClient;

namespace ProductConstructionService.ReproTool.Operations;
internal class FullBackflowTestOperation : Operation
{
private readonly IBarApiClient _prodBarClient;
private readonly FullBackflowTestOptions _options;
private readonly DarcProcessManager _darcProcessManager;
private readonly VmrDependencyResolver _vmrDependencyResolver;

public FullBackflowTestOperation(
ILogger<Operation> logger,
GitHubClient ghClient,
[FromKeyedServices("local")] IProductConstructionServiceApi localPcsApi,
IBarApiClient prodBarClient,
FullBackflowTestOptions options,
DarcProcessManager darcProcessManager,
VmrDependencyResolver vmrDependencyResolver)
: base(logger, ghClient, localPcsApi)
{
_prodBarClient = prodBarClient;
_options = options;
_darcProcessManager = darcProcessManager;
_vmrDependencyResolver = vmrDependencyResolver;
}

internal override async Task RunAsync()
{
await _darcProcessManager.InitializeAsync();
Build vmrBuild = await _prodBarClient.GetBuildAsync(_options.BuildId);

Build testBuild = await CreateBuildAsync(
VmrForkUri,
_options.VmrBranch,
_options.Commit,
[ ..CreateAssetDataFromBuild(vmrBuild).Take(1000)]);

var channelName = $"repro-{Guid.NewGuid()}";
await using var channel = await _darcProcessManager.CreateTestChannelAsync(channelName, skipCleanup: true);
await _darcProcessManager.AddBuildToChannelAsync(testBuild.Id, channelName, skipCleanup: true);

var vmrRepos = (await _vmrDependencyResolver.GetVmrRepositoriesAsync(
"https://github.com/dotnet/dotnet",
"https://github.com/dotnet/sdk",
"main"));

foreach (var vmrRepo in vmrRepos)
{
var productRepoForkUri = $"{ProductRepoFormat}{vmrRepo.Mapping.DefaultRemote.Split('/', StringSplitOptions.RemoveEmptyEntries).Last()}";
string targetBranch = _options.TargetBranch is null ?
(await PrepareProductRepoForkAsync(vmrRepo.Mapping.DefaultRemote, productRepoForkUri, vmrRepo.Mapping.DefaultRef, skipCleanup: true)).Value :
_options.TargetBranch;

var subscription = await _darcProcessManager.CreateSubscriptionAsync(
channel: channelName,
sourceRepo: VmrForkUri,
targetRepo: productRepoForkUri,
targetBranch: targetBranch,
sourceDirectory: vmrRepo.Mapping.Name,
targetDirectory: null,
skipCleanup: true);

await _darcProcessManager.TriggerSubscriptionAsync(subscription.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CommandLine;
using Microsoft.Extensions.DependencyInjection;
using ProductConstructionService.ReproTool.Operations;

namespace ProductConstructionService.ReproTool.Options;
[Verb("forward-flow-test", HelpText = "Test full flat flow in the maestro-auth-test org")]
internal class ForwardFlowTestOptions : Options
{
internal override Operation GetOperation(IServiceProvider sp)
=> ActivatorUtilities.CreateInstance<ForwardFlowTestOperation>(sp);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CommandLine;
using Microsoft.Extensions.DependencyInjection;
using ProductConstructionService.ReproTool.Operations;

namespace ProductConstructionService.ReproTool.Options;

[Verb("backflow-test", HelpText = "Flows an existing VMR build to all repos in maestro-auth-test")]
internal class FullBackflowTestOptions : Options
{
[Option("build", HelpText = "Real VMR build from which we'll take assets from", Required = true)]
public required int BuildId { get; init; }

[Option("target-branch", HelpText = "Branch to target in all repos, if missing, will create a new branch", Required = true)]
public string? TargetBranch { get; set; }

[Option("vmr-branch", HelpText = "Vmr branch from which to backflow", Required = true)]
public required string VmrBranch { get; init; }

[Option("commit", HelpText = "maestro-auth-test/dotnet commit to flow", Required = true)]
public required string Commit { get; init; }

internal override Operation GetOperation(IServiceProvider sp)
=> ActivatorUtilities.CreateInstance<FullBackflowTestOperation>(sp, this);
}
2 changes: 2 additions & 0 deletions tools/ProductConstructionService.ReproTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
Type[] options =
[
typeof(ReproOptions),
typeof(ForwardFlowTestOptions),
typeof(FullBackflowTestOptions),
typeof(FlowCommitOptions),
];

Expand Down
Loading