Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Glob Pattern Matching #35

Merged
merged 4 commits into from Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/release-build.yml
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/CodeCoverageSummary/CodeCoverageSummary.csproj
Expand Up @@ -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>

Expand Down
21 changes: 17 additions & 4 deletions 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;
Expand All @@ -19,8 +21,19 @@ private static int Main(string[] args)
{
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))
{
Expand All @@ -31,13 +44,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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CodeCoverageSummary/Properties/launchSettings.json
Expand Up @@ -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",
Expand Down