From 2fa8196105f6459c7e868d7cebf4ce97f11a637d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 13:56:48 +0000 Subject: [PATCH] Replace bash scripts with C# build targets for benchmark display and comparison Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- .github/workflows/performance-benchmarks.yml | 20 +--- build/Program.cs | 98 ++++++++++++++++++++ 2 files changed, 100 insertions(+), 18 deletions(-) diff --git a/.github/workflows/performance-benchmarks.yml b/.github/workflows/performance-benchmarks.yml index d15333ac..907a96e9 100644 --- a/.github/workflows/performance-benchmarks.yml +++ b/.github/workflows/performance-benchmarks.yml @@ -36,27 +36,11 @@ jobs: - name: Display Benchmark Results if: always() - run: | - echo "## Benchmark Results" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - if [ -d "benchmark-results/results" ]; then - for file in benchmark-results/results/*-report-github.md; do - if [ -f "$file" ]; then - cat "$file" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - fi - done - fi + run: dotnet run --project build/build.csproj -- display-benchmark-results - name: Compare with Baseline if: always() - run: | - echo "## Comparison with Baseline" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "Baseline results are stored in tests/SharpCompress.Performance/baseline-results.md" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Baseline Results" >> $GITHUB_STEP_SUMMARY - cat tests/SharpCompress.Performance/baseline-results.md >> $GITHUB_STEP_SUMMARY || echo "Baseline file not found" >> $GITHUB_STEP_SUMMARY + run: dotnet run --project build/build.csproj -- compare-benchmark-results - name: Upload Benchmark Results if: always() diff --git a/build/Program.cs b/build/Program.cs index 1ad21f50..c6c70cec 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -19,6 +19,8 @@ const string Publish = "publish"; const string DetermineVersion = "determine-version"; const string UpdateVersion = "update-version"; const string PushToNuGet = "push-to-nuget"; +const string DisplayBenchmarkResults = "display-benchmark-results"; +const string CompareBenchmarkResults = "compare-benchmark-results"; Target( Clean, @@ -210,6 +212,102 @@ Target( } ); +Target( + DisplayBenchmarkResults, + () => + { + var githubStepSummary = Environment.GetEnvironmentVariable("GITHUB_STEP_SUMMARY"); + var resultsDir = "benchmark-results/results"; + + if (!Directory.Exists(resultsDir)) + { + Console.WriteLine("No benchmark results found."); + return; + } + + var markdownFiles = Directory + .GetFiles(resultsDir, "*-report-github.md") + .OrderBy(f => f) + .ToList(); + + if (markdownFiles.Count == 0) + { + Console.WriteLine("No benchmark markdown reports found."); + return; + } + + var output = new List { "## Benchmark Results", "" }; + + foreach (var file in markdownFiles) + { + Console.WriteLine($"Processing {Path.GetFileName(file)}"); + var content = File.ReadAllText(file); + output.Add(content); + output.Add(""); + } + + // Write to GitHub Step Summary if available + if (!string.IsNullOrEmpty(githubStepSummary)) + { + File.AppendAllLines(githubStepSummary, output); + Console.WriteLine($"Benchmark results written to GitHub Step Summary"); + } + else + { + // Write to console if not in GitHub Actions + foreach (var line in output) + { + Console.WriteLine(line); + } + } + } +); + +Target( + CompareBenchmarkResults, + () => + { + var githubStepSummary = Environment.GetEnvironmentVariable("GITHUB_STEP_SUMMARY"); + var baselinePath = "tests/SharpCompress.Performance/baseline-results.md"; + + var output = new List + { + "## Comparison with Baseline", + "", + "Baseline results are stored in tests/SharpCompress.Performance/baseline-results.md", + "", + "### Baseline Results", + }; + + if (File.Exists(baselinePath)) + { + Console.WriteLine($"Reading baseline from {baselinePath}"); + var baselineContent = File.ReadAllLines(baselinePath); + output.AddRange(baselineContent); + } + else + { + Console.WriteLine("Baseline file not found"); + output.Add("Baseline file not found"); + } + + // Write to GitHub Step Summary if available + if (!string.IsNullOrEmpty(githubStepSummary)) + { + File.AppendAllLines(githubStepSummary, output); + Console.WriteLine("Baseline comparison written to GitHub Step Summary"); + } + else + { + // Write to console if not in GitHub Actions + foreach (var line in output) + { + Console.WriteLine(line); + } + } + } +); + Target("default", [Publish], () => Console.WriteLine("Done!")); await RunTargetsAndExitAsync(args);