Skip to content

Commit e93a816

Browse files
committed
stage
1 parent a5178a7 commit e93a816

File tree

3 files changed

+227
-2803
lines changed

3 files changed

+227
-2803
lines changed

src/docs-assembler/AssemblyConfiguration.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Documentation.Builder;
88

99
[YamlStaticContext]
1010
[YamlSerializable(typeof(AssemblyConfiguration))]
11+
[YamlSerializable(typeof(Repository))]
1112
public partial class YamlStaticContext;
1213

1314
public record AssemblyConfiguration
@@ -20,10 +21,29 @@ public static AssemblyConfiguration Deserialize(string yaml)
2021
.IgnoreUnmatchedProperties()
2122
.Build();
2223

23-
var config = deserializer.Deserialize<AssemblyConfiguration>(input);
24-
return config;
24+
try
25+
{
26+
var config = deserializer.Deserialize<AssemblyConfiguration>(input);
27+
return config;
28+
}
29+
catch (Exception e)
30+
{
31+
Console.WriteLine(e);
32+
Console.WriteLine(e.InnerException);
33+
throw;
34+
}
2535
}
2636

2737
[YamlMember(Alias = "repos")]
28-
public Dictionary<string, string> Repositories { get; set; } = new();
38+
public Dictionary<string, Repository> Repositories { get; set; } = new();
39+
}
40+
41+
public record Repository
42+
{
43+
[YamlMember(Alias = "repo")]
44+
public string Origin { get; set; } = string.Empty;
45+
46+
[YamlMember(Alias = "branch")]
47+
public string? Branch { get; set; }
48+
2949
}

src/docs-assembler/Program.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// See https://aka.ms/new-console-template for more information
22

3+
using System.Collections.Concurrent;
34
using System.Diagnostics;
45
using ConsoleAppFramework;
56
using Documentation.Assembler.Cli;
@@ -20,6 +21,7 @@
2021
app.Add("clone-all", async Task (CancellationToken ctx) =>
2122
{
2223
Console.WriteLine(config.Repositories.Count);
24+
var dict = new ConcurrentDictionary<string, Stopwatch>();
2325
await Parallel.ForEachAsync(config.Repositories, new ParallelOptions
2426
{
2527
CancellationToken = ctx,
@@ -33,14 +35,43 @@ await Task.Run(() =>
3335
var checkoutFolder = Path.Combine(Paths.Root.FullName, $".artifacts/assembly/{name}");
3436

3537
var sw = Stopwatch.StartNew();
38+
dict.AddOrUpdate(name, sw, (_, _) => sw);
3639
Console.WriteLine($"Checkout: {name}\t{repository}\t{checkoutFolder}");
37-
//, "--single-branch", "--branch", "main"
38-
var args = new StartArguments("git", "clone", repository, checkoutFolder, "--depth", "1");
40+
var branch = repository.Branch ?? "main";
41+
var args = new StartArguments(
42+
"git", "clone", repository.Origin, checkoutFolder, "--depth", "1"
43+
, "--single-branch", "--branch", branch
44+
);
3945
Proc.StartRedirected(args, new ConsoleLineHandler(name));
4046
sw.Stop();
41-
Console.WriteLine($"-> {name}\ttook: {sw.Elapsed}");
4247
}, c);
4348
}).ConfigureAwait(false);
49+
50+
foreach(var kv in dict.OrderBy(kv => kv.Value.Elapsed))
51+
Console.WriteLine($"-> {kv.Key}\ttook: {kv.Value.Elapsed}");
52+
});
53+
app.Add("list", async Task (CancellationToken ctx) =>{
54+
55+
var assemblyPath = Path.Combine(Paths.Root.FullName, $".artifacts/assembly");
56+
var dir = new DirectoryInfo(assemblyPath);
57+
var dictionary = new Dictionary<string, string>();
58+
foreach (var d in dir.GetDirectories())
59+
{
60+
var checkoutFolder = Path.Combine(assemblyPath, d.Name);
61+
62+
var consoleOut = new NoopConsoleLineHandler();
63+
var capture = Proc.StartRedirected(
64+
new StartArguments("git", "rev-parse", "--abbrev-ref", "HEAD")
65+
{
66+
WorkingDirectory = checkoutFolder
67+
}
68+
, consoleOut);
69+
dictionary.Add(d.Name, consoleOut.Lines.FirstOrDefault()?.Line ?? "unknown");
70+
}
71+
foreach(var kv in dictionary.OrderBy(kv => kv.Value))
72+
Console.WriteLine($"-> {kv.Key}\tbranch: {kv.Value}");
73+
74+
await Task.CompletedTask;
4475
});
4576

4677
await app.RunAsync(args);
@@ -54,3 +85,11 @@ public void Handle(LineOut lineOut) => lineOut.CharsOrString(
5485
public void Handle(Exception e) {}
5586
}
5687

88+
public class NoopConsoleLineHandler : IConsoleLineHandler
89+
{
90+
public List<LineOut> Lines { get; } = new();
91+
92+
public void Handle(LineOut lineOut) => Lines.Add(lineOut);
93+
94+
public void Handle(Exception e) {}
95+
}

0 commit comments

Comments
 (0)