From 1c2edd923012b513ebef2b972469274a875232f4 Mon Sep 17 00:00:00 2001 From: irongut Date: Sun, 14 Nov 2021 23:51:30 +0000 Subject: [PATCH 1/4] support multiple cobertura files in CLI #19 --- src/CodeCoverageSummary/CodeSummary.cs | 5 +-- src/CodeCoverageSummary/CommandLineOptions.cs | 5 ++- src/CodeCoverageSummary/Program.cs | 43 +++++++++++-------- .../Properties/launchSettings.json | 2 +- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/CodeCoverageSummary/CodeSummary.cs b/src/CodeCoverageSummary/CodeSummary.cs index b73296c..d94906b 100644 --- a/src/CodeCoverageSummary/CodeSummary.cs +++ b/src/CodeCoverageSummary/CodeSummary.cs @@ -31,9 +31,6 @@ namespace CodeCoverageSummary public List Packages { get; set; } - public CodeSummary() - { - Packages = new List(); - } + public CodeSummary() => Packages = new(); } } diff --git a/src/CodeCoverageSummary/CommandLineOptions.cs b/src/CodeCoverageSummary/CommandLineOptions.cs index b277fd8..dbc64b5 100644 --- a/src/CodeCoverageSummary/CommandLineOptions.cs +++ b/src/CodeCoverageSummary/CommandLineOptions.cs @@ -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 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; } diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index b907318..f29e17d 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -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,9 @@ namespace CodeCoverageSummary _ => -1); // invalid arguments } - private static CodeSummary ParseTestResults(string filename) + private static CodeSummary ParseTestResults(string filename, CodeSummary summary) { - CodeSummary summary = new(); + //CodeSummary summary = new(); try { string rss = File.ReadAllText(filename); @@ -118,34 +129,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") diff --git a/src/CodeCoverageSummary/Properties/launchSettings.json b/src/CodeCoverageSummary/Properties/launchSettings.json index 25f7867..736ad24 100644 --- a/src/CodeCoverageSummary/Properties/launchSettings.json +++ b/src/CodeCoverageSummary/Properties/launchSettings.json @@ -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", From 60646036b507aa91b6bb1d9318daaa4ea910c7d1 Mon Sep 17 00:00:00 2001 From: irongut Date: Mon, 15 Nov 2021 00:18:30 +0000 Subject: [PATCH 2/4] support multiple cobertura files in action definition #19 --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f86cdab..4979b45 100644 --- a/action.yml +++ b/action.yml @@ -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 }} From 4ae964bab0b2ee5fa53ea39e57e1bcf24641b5de Mon Sep 17 00:00:00 2001 From: irongut Date: Mon, 15 Nov 2021 00:24:46 +0000 Subject: [PATCH 3/4] update ci build test command line #19 --- .github/workflows/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 8d75a7c..3e53b58 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/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 From 6e12bd152f1ba5f73b2c37a85bde7ab29b793341 Mon Sep 17 00:00:00 2001 From: irongut Date: Mon, 15 Nov 2021 00:33:15 +0000 Subject: [PATCH 4/4] removed commented line --- src/CodeCoverageSummary/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index f29e17d..3473a89 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -116,7 +116,6 @@ namespace CodeCoverageSummary private static CodeSummary ParseTestResults(string filename, CodeSummary summary) { - //CodeSummary summary = new(); try { string rss = File.ReadAllText(filename);