merge PR #35 Glob Pattern Matching

PR: Glob Pattern Matching
This commit is contained in:
irongut
2022-02-19 02:03:05 +00:00
committed by GitHub
5 changed files with 21 additions and 7 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
@@ -19,6 +19,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
</ItemGroup>
+17 -4
View File
@@ -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,19 @@ namespace CodeCoverageSummary
{
try
{
// use glob patterns to match files
Matcher matcher = new();
matcher.AddIncludePatterns(o.Files.ToArray());
IEnumerable<string> 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 o.Files)
foreach (var file in matchingFiles)
{
if (!File.Exists(file))
{
@@ -31,13 +44,13 @@ namespace CodeCoverageSummary
// 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)
{
@@ -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",