From 0d078db7ccf0f1fa5f01ba64968f698f432e0384 Mon Sep 17 00:00:00 2001 From: irongut Date: Sat, 19 Feb 2022 01:08:32 +0000 Subject: [PATCH 1/4] added Microsoft.Extensions.FileSystemGlobbing #31 --- src/CodeCoverageSummary/CodeCoverageSummary.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CodeCoverageSummary/CodeCoverageSummary.csproj b/src/CodeCoverageSummary/CodeCoverageSummary.csproj index 374920c..32e884c 100644 --- a/src/CodeCoverageSummary/CodeCoverageSummary.csproj +++ b/src/CodeCoverageSummary/CodeCoverageSummary.csproj @@ -19,6 +19,7 @@ + From 009a5455b81a26e5c901bb89c3e38f1917fe37ee Mon Sep 17 00:00:00 2001 From: irongut Date: Sat, 19 Feb 2022 01:35:28 +0000 Subject: [PATCH 2/4] use glob pattern matching #31 --- src/CodeCoverageSummary/Program.cs | 15 +++++++++++---- .../Properties/launchSettings.json | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index 3473a89..1e922db 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -1,5 +1,7 @@ using CommandLine; +using Microsoft.Extensions.FileSystemGlobbing; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -19,8 +21,13 @@ private static int Main(string[] args) { try { + // use glob patterns to match files + Matcher matcher = new(); + matcher.AddIncludePatterns(o.Files.ToArray()); + IEnumerable matchingFiles = matcher.GetResultsInFullPath("."); + // check files exist - foreach (var file in o.Files) + foreach (var file in matchingFiles) { if (!File.Exists(file)) { @@ -31,13 +38,13 @@ private static int Main(string[] args) // parse code coverage file CodeSummary summary = new(); - foreach (var file in o.Files) + foreach (var file in matchingFiles) { Console.WriteLine($"Code Coverage File: {file}"); summary = ParseTestResults(file, summary); } - summary.LineRate /= o.Files.Count(); - summary.BranchRate /= o.Files.Count(); + summary.LineRate /= matchingFiles.Count(); + summary.BranchRate /= matchingFiles.Count(); if (summary.Packages.Count == 0) { diff --git a/src/CodeCoverageSummary/Properties/launchSettings.json b/src/CodeCoverageSummary/Properties/launchSettings.json index 68bac46..25a681a 100644 --- a/src/CodeCoverageSummary/Properties/launchSettings.json +++ b/src/CodeCoverageSummary/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "CodeCoverageSummary": { "commandName": "Project", - "commandLineArgs": "--files ../../../../coverage.cobertura.xml,../../../../coverage.cobertura.xml --format=text --badge true --thresholds=\"85 90\" --fail true" + "commandLineArgs": "--files **/coverage.*.xml --format=text --badge true --thresholds=\"85 90\" --fail true" }, "Docker": { "commandName": "Docker", From ce279ec14b40788e2b5b95800a35b887e1767012 Mon Sep 17 00:00:00 2001 From: irongut Date: Sat, 19 Feb 2022 01:40:00 +0000 Subject: [PATCH 3/4] error if no files match glob pattern #31 --- src/CodeCoverageSummary/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index 1e922db..e1e2ca3 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -26,6 +26,12 @@ private static int Main(string[] args) matcher.AddIncludePatterns(o.Files.ToArray()); IEnumerable matchingFiles = matcher.GetResultsInFullPath("."); + if (matchingFiles?.Any() == false) + { + Console.WriteLine("Error: No files found matching glob pattern."); + return -2; // error + } + // check files exist foreach (var file in matchingFiles) { From bc2adc7690eaaf8041c28b49502017e525d33e2e Mon Sep 17 00:00:00 2001 From: irongut Date: Sat, 19 Feb 2022 01:46:18 +0000 Subject: [PATCH 4/4] use glob pattern in workflows #31 --- .github/workflows/ci-build.yml | 2 +- .github/workflows/release-build.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index b1b6a5c..e0e45be 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -26,4 +26,4 @@ jobs: run: dotnet build src/CodeCoverageSummary.sln --configuration Release --no-restore - name: Test with sample file - run: dotnet src/CodeCoverageSummary/bin/Release/net6.0/CodeCoverageSummary.dll --files src/coverage.cobertura.xml --badge true + run: dotnet src/CodeCoverageSummary/bin/Release/net6.0/CodeCoverageSummary.dll --files **/coverage.*.xml --badge true diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index f49ae90..eb1e12c 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -30,7 +30,7 @@ jobs: run: dotnet build src/CodeCoverageSummary.sln --configuration Release --no-restore - name: Test with sample file - run: dotnet src/CodeCoverageSummary/bin/Release/net6.0/CodeCoverageSummary.dll --files src/coverage.cobertura.xml --badge true + run: dotnet src/CodeCoverageSummary/bin/Release/net6.0/CodeCoverageSummary.dll --files **/coverage.*.xml --badge true deploy: name: Deploy to GHCR