merge PR #26 Support multiple cobertura files

PR: Support multiple cobertura files
This commit is contained in:
irongut
2021-11-15 01:21:55 +00:00
committed by GitHub
6 changed files with 33 additions and 26 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/net5.0/CodeCoverageSummary.dll src/coverage.cobertura.xml --badge true
run: dotnet src/CodeCoverageSummary/bin/Release/net5.0/CodeCoverageSummary.dll --files src/coverage.cobertura.xml --badge true
+2 -1
View File
@@ -6,7 +6,7 @@ branding:
color: purple
inputs:
filename:
description: 'Code coverage file to analyse.'
description: 'A comma separated list of code coverage files to analyse.'
required: true
badge:
description: 'Include a Line Rate coverage badge in the output using shields.io - true / false (default).'
@@ -44,6 +44,7 @@ runs:
using: 'docker'
image: 'docker://ghcr.io/irongut/codecoveragesummary:v1.1.0'
args:
- '--files'
- ${{ inputs.filename }}
- '--badge'
- ${{ inputs.badge }}
+1 -4
View File
@@ -31,9 +31,6 @@ namespace CodeCoverageSummary
public List<CodeCoverage> Packages { get; set; }
public CodeSummary()
{
Packages = new List<CodeCoverage>();
}
public CodeSummary() => Packages = new();
}
}
@@ -1,12 +1,13 @@
using CommandLine;
using System;
using System.Collections.Generic;
namespace CodeCoverageSummary
{
public class CommandLineOptions
{
[Value(index: 0, Required = true, HelpText = "Code coverage file to analyse.")]
public string Filename { get; set; }
[Option(longName: "files", Separator = ',', Required = true, HelpText = "A comma separated list of code coverage files to analyse.")]
public IEnumerable<string> Files { get; set; }
[Option(longName: "badge", Required = false, HelpText = "Include a Line Rate coverage badge in the output using shields.io - true or false.", Default = "false")]
public string BadgeString { get; set; }
+25 -17
View File
@@ -19,18 +19,29 @@ namespace CodeCoverageSummary
{
try
{
if (!File.Exists(o.Filename))
// check files exist
foreach (var file in o.Files)
{
Console.WriteLine("Error: Code coverage file not found.");
return -2; // error
if (!File.Exists(file))
{
Console.WriteLine($"Error: Code coverage file not found - {file}.");
return -2; // error
}
}
// parse code coverage file
Console.WriteLine($"Code Coverage File: {o.Filename}");
CodeSummary summary = ParseTestResults(o.Filename);
if (summary == null)
CodeSummary summary = new();
foreach (var file in o.Files)
{
Console.WriteLine("Error: Parsing code coverage file.");
Console.WriteLine($"Code Coverage File: {file}");
summary = ParseTestResults(file, summary);
}
summary.LineRate /= o.Files.Count();
summary.BranchRate /= o.Files.Count();
if (summary.Packages.Count == 0)
{
Console.WriteLine("Error: Parsing code coverage file, no packages found.");
return -2; // error
}
else
@@ -103,9 +114,8 @@ namespace CodeCoverageSummary
_ => -1); // invalid arguments
}
private static CodeSummary ParseTestResults(string filename)
private static CodeSummary ParseTestResults(string filename, CodeSummary summary)
{
CodeSummary summary = new();
try
{
string rss = File.ReadAllText(filename);
@@ -118,34 +128,32 @@ namespace CodeCoverageSummary
var lineR = from item in coverage.Attributes()
where item.Name == "line-rate"
select item;
summary.LineRate = double.Parse(lineR.First().Value);
summary.LineRate += double.Parse(lineR.First().Value);
var linesCovered = from item in coverage.Attributes()
where item.Name == "lines-covered"
select item;
summary.LinesCovered = int.Parse(linesCovered.First().Value);
summary.LinesCovered += int.Parse(linesCovered.First().Value);
var linesValid = from item in coverage.Attributes()
where item.Name == "lines-valid"
select item;
summary.LinesValid = int.Parse(linesValid.First().Value);
summary.LinesValid += int.Parse(linesValid.First().Value);
var branchR = from item in coverage.Attributes()
where item.Name == "branch-rate"
select item;
summary.BranchRate = double.Parse(branchR.First().Value);
summary.BranchRate += double.Parse(branchR.First().Value);
var branchesCovered = from item in coverage.Attributes()
where item.Name == "branches-covered"
select item;
summary.BranchesCovered = int.Parse(branchesCovered.First().Value);
summary.BranchesCovered += int.Parse(branchesCovered.First().Value);
var branchesValid = from item in coverage.Attributes()
where item.Name == "branches-valid"
select item;
summary.BranchesValid = int.Parse(branchesValid.First().Value);
summary.Complexity = 0;
summary.BranchesValid += int.Parse(branchesValid.First().Value);
// test coverage for individual packages
var packages = from item in coverage.Descendants("package")
@@ -2,7 +2,7 @@
"profiles": {
"CodeCoverageSummary": {
"commandName": "Project",
"commandLineArgs": "../../../../coverage.cobertura.xml --format=md --badge true --thresholds=\"85 90\" --fail true"
"commandLineArgs": "--files ../../../../coverage.cobertura.xml,../../../../coverage.cobertura.xml --format=text --badge true --thresholds=\"85 90\" --fail true"
},
"Docker": {
"commandName": "Docker",