1+ using System . Text ;
2+ using SimpleStateMachine . StructuralSearch . Action ;
3+ using System . Web ;
4+ using CommandLine ;
5+ using Microsoft . Extensions . DependencyInjection ;
6+ using Microsoft . Extensions . FileSystemGlobbing ;
7+ using Microsoft . Extensions . Hosting ;
8+ using Microsoft . Extensions . Logging ;
9+ using static CommandLine . Parser ;
10+
11+ using IHost host = Host . CreateDefaultBuilder ( args )
12+ . ConfigureServices ( ( _ , services ) =>
13+ {
14+
15+ } )
16+ . Build ( ) ;
17+
18+ static TService Get < TService > ( IHost host )
19+ where TService : notnull =>
20+ host . Services . GetRequiredService < TService > ( ) ;
21+
22+ static async Task StartAnalysisAsync ( ActionInputs inputs , IHost host )
23+ {
24+ // using ProjectWorkspace workspace = Get<ProjectWorkspace>(host);
25+ using CancellationTokenSource tokenSource = new ( ) ;
26+
27+ Console . CancelKeyPress += delegate { tokenSource . Cancel ( ) ; } ;
28+
29+ // var projectAnalyzer = Get<ProjectMetricDataAnalyzer>(host);
30+
31+ Matcher matcher = new ( ) ;
32+ matcher . AddIncludePatterns ( new [ ] { "**/*.csproj" , "**/*.vbproj" } ) ;
33+
34+ // Dictionary<string, CodeAnalysisMetricData> metricData = new(StringComparer.OrdinalIgnoreCase);
35+ var projects = matcher . GetResultsInFullPath ( inputs . Directory ) ;
36+
37+ foreach ( var project in projects )
38+ {
39+ // var metrics =
40+ // await projectAnalyzer.AnalyzeAsync(
41+ // workspace, project, tokenSource.Token);
42+ //
43+ // foreach (var (path, metric) in metrics)
44+ // {
45+ // metricData[path] = metric;
46+ // }
47+ }
48+
49+ // var updatedMetrics = false;
50+ // var title = "";
51+ // StringBuilder summary = new();
52+ // if (metricData is { Count: > 0 })
53+ // {
54+ // var fileName = "CODE_METRICS.md";
55+ // var fullPath = Path.Combine(inputs.Directory, fileName);
56+ // var logger = Get<ILoggerFactory>(host).CreateLogger(nameof(StartAnalysisAsync));
57+ // var fileExists = File.Exists(fullPath);
58+ //
59+ // logger.LogInformation(
60+ // $"{(fileExists ? "Updating" : "Creating")} {fileName} markdown file with latest code metric data.");
61+ //
62+ // summary.AppendLine(
63+ // title =
64+ // $"{(fileExists ? "Updated" : "Created")} {fileName} file, analyzed metrics for {metricData.Count} projects.");
65+ //
66+ // foreach (var (path, _) in metricData)
67+ // {
68+ // summary.AppendLine($"- *{path}*");
69+ // }
70+ //
71+ // var contents = metricData.ToMarkDownBody(inputs);
72+ // await File.WriteAllTextAsync(
73+ // fullPath,
74+ // contents,
75+ // tokenSource.Token);
76+ //
77+ // updatedMetrics = true;
78+ // }
79+ // else
80+ // {
81+ // summary.Append("No metrics were determined.");
82+ // }
83+ //
84+ // // https://docs.github.com/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter
85+ // Console.WriteLine($"::set-output name=updated-metrics::{updatedMetrics}");
86+ // Console.WriteLine($"::set-output name=summary-title::{title}");
87+ // Console.WriteLine($"::set-output name=summary-details::{summary}");
88+
89+ Environment . Exit ( 0 ) ;
90+ }
91+
92+ var parser = Default . ParseArguments ( ( ) => new ActionInputs ( ) , args ) ;
93+ parser . WithNotParsed (
94+ errors =>
95+ {
96+ Get < ILoggerFactory > ( host )
97+ . CreateLogger ( "DotNet.GitHubAction.Program" )
98+ . LogError (
99+ string . Join ( Environment . NewLine , errors . Select ( error => error . ToString ( ) ) ) ) ;
100+
101+ Environment . Exit ( 2 ) ;
102+ } ) ;
103+
104+ await parser . WithParsedAsync ( options => StartAnalysisAsync ( options , host ) ) ;
105+ await host . RunAsync ( ) ;
0 commit comments