|
5 | 5 | using System.Collections.Concurrent; |
6 | 6 | using System.Diagnostics; |
7 | 7 | using Actions.Core.Extensions; |
| 8 | +using Actions.Core.Services; |
8 | 9 | using ConsoleAppFramework; |
9 | 10 | using Documentation.Assembler; |
10 | 11 | using Documentation.Assembler.Cli; |
|
38 | 39 | await using var serviceProvider = services.BuildServiceProvider(); |
39 | 40 | ConsoleApp.ServiceProvider = serviceProvider; |
40 | 41 |
|
41 | | - |
42 | 42 | var app = ConsoleApp.Create(); |
43 | 43 | app.UseFilter<StopwatchFilter>(); |
44 | 44 | app.UseFilter<CatchExceptionFilter>(); |
45 | 45 |
|
46 | | -app.Add<LinkCommands>(); |
47 | | - |
48 | | -// would love to use libgit2 so there is no git dependency but |
49 | | -// libgit2 is magnitudes slower to clone repositories https://github.com/libgit2/libgit2/issues/4674 |
50 | | -app.Add("clone-all", async Task (CancellationToken ctx) => |
51 | | -{ |
52 | | - Console.WriteLine(config.Repositories.Count); |
53 | | - var dict = new ConcurrentDictionary<string, Stopwatch>(); |
54 | | - await Parallel.ForEachAsync(config.Repositories, new ParallelOptions |
55 | | - { |
56 | | - CancellationToken = ctx, |
57 | | - MaxDegreeOfParallelism = Environment.ProcessorCount / 4 |
58 | | - }, async (kv, c) => |
59 | | - { |
60 | | - await Task.Run(() => |
61 | | - { |
62 | | - var name = kv.Key; |
63 | | - var repository = kv.Value; |
64 | | - var checkoutFolder = Path.Combine(Paths.Root.FullName, $".artifacts/assembly/{name}"); |
| 46 | +app.Add<LinkCommands>("link"); |
| 47 | +app.Add<RepositoryCommands>("repo"); |
65 | 48 |
|
66 | | - var sw = Stopwatch.StartNew(); |
67 | | - dict.AddOrUpdate(name, sw, (_, _) => sw); |
68 | | - Console.WriteLine($"Checkout: {name}\t{repository}\t{checkoutFolder}"); |
69 | | - var branch = repository.Branch ?? "main"; |
70 | | - var args = new StartArguments( |
71 | | - "git", "clone", repository.Origin, checkoutFolder, "--depth", "1" |
72 | | - , "--single-branch", "--branch", branch |
73 | | - ); |
74 | | - Proc.StartRedirected(args, new ConsoleLineHandler(name)); |
75 | | - sw.Stop(); |
76 | | - }, c); |
77 | | - }).ConfigureAwait(false); |
78 | | - |
79 | | - foreach (var kv in dict.OrderBy(kv => kv.Value.Elapsed)) |
80 | | - Console.WriteLine($"-> {kv.Key}\ttook: {kv.Value.Elapsed}"); |
81 | | -}); |
82 | | -app.Add("list", async Task (CancellationToken ctx) => |
83 | | -{ |
84 | | - |
85 | | - var assemblyPath = Path.Combine(Paths.Root.FullName, $".artifacts/assembly"); |
86 | | - var dir = new DirectoryInfo(assemblyPath); |
87 | | - var dictionary = new Dictionary<string, string>(); |
88 | | - foreach (var d in dir.GetDirectories()) |
89 | | - { |
90 | | - var checkoutFolder = Path.Combine(assemblyPath, d.Name); |
91 | | - |
92 | | - var capture = Proc.Start( |
93 | | - new StartArguments("git", "rev-parse", "--abbrev-ref", "HEAD") |
94 | | - { |
95 | | - WorkingDirectory = checkoutFolder |
96 | | - } |
97 | | - ); |
98 | | - dictionary.Add(d.Name, capture.ConsoleOut.FirstOrDefault()?.Line ?? "unknown"); |
99 | | - } |
100 | | - foreach (var kv in dictionary.OrderBy(kv => kv.Value)) |
101 | | - Console.WriteLine($"-> {kv.Key}\tbranch: {kv.Value}"); |
102 | | - |
103 | | - await Task.CompletedTask; |
104 | | -}); |
| 49 | +var githubActions = ConsoleApp.ServiceProvider.GetService<ICoreService>(); |
| 50 | +var command = githubActions?.GetInput("command"); |
| 51 | +if (!string.IsNullOrEmpty(command)) |
| 52 | + args = command.Split(' '); |
105 | 53 |
|
106 | 54 | await app.RunAsync(args); |
107 | | - |
108 | | -namespace Documentation.Assembler |
109 | | -{ |
110 | | - public class ConsoleLineHandler(string prefix) : IConsoleLineHandler |
111 | | - { |
112 | | - public void Handle(LineOut lineOut) => lineOut.CharsOrString( |
113 | | - r => Console.Write(prefix + ": " + r), |
114 | | - l => Console.WriteLine(prefix + ": " + l)); |
115 | | - |
116 | | - public void Handle(Exception e) { } |
117 | | - } |
118 | | -} |
0 commit comments