Compare commits

...

7 Commits

Author SHA1 Message Date
irongut 0723132cf6 prepare v1.0.3 2021-09-24 20:41:43 +01:00
irongut 758c38f591 removed short params 2021-09-23 02:08:23 +01:00
irongut 24062a1b2a added changelog to release workflow 2021-09-23 01:48:41 +01:00
irongut dcef09e405 merge PR #7 Handle optional complexity attribute 2021-09-22 22:32:30 +01:00
Jonathan Derrough 9cce3f5374 Handle optional complexity attribute 2021-09-22 18:19:21 +07:00
irongut 20025e7e93 formatting + cleanup 2021-09-20 01:00:33 +01:00
irongut 0bcadffdb9 workflow fixes 2021-09-06 15:06:40 +01:00
8 changed files with 128 additions and 98 deletions
+14 -11
View File
@@ -1,15 +1,18 @@
# Assign PR to Author
# https://github.com/samspills/assign-pr-to-author
name: Auto Assign PR
on: [pull_request]
# Disabled due to #14 HttpError: Resource not accessible by integration:
# https://github.com/samspills/assign-pr-to-author/issues/14
jobs:
assignAuthor:
runs-on: ubuntu-latest
steps:
- name: Auto Assign PR
uses: samspills/assign-pr-to-author@v1.0
if: github.event_name == 'pull_request' && github.event.action == 'opened'
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
#name: Auto Assign PR
#on: [pull_request]
#jobs:
# assignAuthor:
# runs-on: ubuntu-latest
# steps:
# - name: Auto Assign PR
# uses: samspills/assign-pr-to-author@v1.0
# if: github.event_name == 'pull_request' && github.event.action == 'opened'
# with:
# repo-token: '${{ secrets.GITHUB_TOKEN }}'
+5 -9
View File
@@ -11,8 +11,10 @@ jobs:
runs-on: ubuntu-latest
name: CI Build
steps:
- uses: actions/checkout@v2
- name: Setup .NET
- name: Checkout
uses: actions/checkout@v2
- name: Setup .Net
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
@@ -23,11 +25,5 @@ jobs:
- name: Build CodeCoverageSummary
run: dotnet build src/CodeCoverageSummary.sln --configuration Release --no-restore
- name: Run CodeCoverageSummary with sample file
- name: Test with sample file
run: dotnet src/CodeCoverageSummary/bin/Release/net5.0/CodeCoverageSummary.dll src/coverage.cobertura.xml --badge true
- name: Test Action
uses: irongut/CodeCoverageSummary@master
with:
filename: '/app/sample.coverage.xml'
badge: 'true'
+24
View File
@@ -15,6 +15,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .Net
uses: actions/setup-dotnet@v1
@@ -30,6 +32,28 @@ jobs:
- name: Test with sample file
run: dotnet src/CodeCoverageSummary/bin/Release/net5.0/CodeCoverageSummary.dll src/coverage.cobertura.xml --badge true
- name: Get Previous Tag
id: get_previous_tag
run: |
PREV_TAG=$(git describe --abbrev=0 --tags "${{ github.ref }}^")
echo "::set-output name=baseRef::${PREV_TAG}"
- name: Generate Changelog
id: generate_changelog
uses: nblagoev/pull-release-notes-action@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
base-ref: ${{ steps.get_previous_tag.outputs.baseRef }}
head-ref: ${{ github.ref }}
- name: Add Changelog to Release
uses: irongut/EditRelease@v1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
id: ${{ github.event.release.id }}
body: ${{ steps.generate_changelog.outputs.result }}
deploy:
name: Deploy to GHCR
needs: [build]
+2 -2
View File
@@ -52,7 +52,7 @@ Company.Example.Library: Line Rate = 27%, Branch Rate = 100%, Complexity = 11
```yaml
name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.0.2
uses: irongut/CodeCoverageSummary@v1.0.3
with:
filename: coverage/coverage.cobertura.xml
```
@@ -94,7 +94,7 @@ jobs:
run: cp coverage/**/coverage.cobertura.xml coverage/coverage.cobertura.xml
- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.0.2
uses: irongut/CodeCoverageSummary@v1.0.3
with:
filename: coverage/coverage.cobertura.xml
badge: true
@@ -6,14 +6,15 @@
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Company>Taranis Software</Company>
<Authors>Irongut</Authors>
<Description>A GitHub Action that reads Cobertura format code coverage files and outputs a summary.</Description>
<Description>A GitHub Action that reads Cobertura format code coverage files and outputs a text or markdown summary.</Description>
<Copyright>Copyright © 2021 Taranis Software</Copyright>
<PackageId>Taranis.CodeCoverageSummary</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/irongut/CodeCoverageSummary</PackageProjectUrl>
<RepositoryUrl>https://github.com/irongut/CodeCoverageSummary</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>code-coverage cobertura coverlet</PackageTags>
<PackageTags>coverage test-coverage cobertura action code-coverage coverlet github-actions</PackageTags>
<Version>1.0.3</Version>
</PropertyGroup>
<ItemGroup>
@@ -7,13 +7,13 @@ namespace CodeCoverageSummary
[Value(index: 0, Required = true, HelpText = "Code coverage file to analyse.")]
public string Filename { get; set; }
[Option(shortName: 'b', longName: "badge", Required = false, HelpText = "Include a badge in the output - true / false.", Default = false)]
[Option(longName: "badge", Required = false, HelpText = "Include a badge reporting the Line Rate coverage in the output using shields.io - true or false.", Default = false)]
public bool Badge { get; set; }
[Option(shortName: 'f', longName: "format", Required = false, HelpText = "Output Format - markdown or text.", Default = "text")]
[Option(longName: "format", Required = false, HelpText = "Output Format - markdown or text.", Default = "text")]
public string Format { get; set; }
[Option(shortName: 'o', longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
public string Output { get; set; }
}
}
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Performance", "RCS1197:Optimize StringBuilder.Append/AppendLine call.", Scope = "type", Target = "~T:CodeCoverageSummary.Program")]
+69 -71
View File
@@ -9,83 +9,81 @@ namespace CodeCoverageSummary
{
internal static class Program
{
// test file: /Dev/Csharp/CodeCoverageSummary/coverage.cobertura.xml
private static int Main(string[] args)
{
return Parser.Default.ParseArguments<CommandLineOptions>(args)
.MapResult(o =>
{
try
{
if (!File.Exists(o.Filename))
{
Console.WriteLine("Error: Code coverage file not found.");
return -2; // error
}
.MapResult(o =>
{
try
{
if (!File.Exists(o.Filename))
{
Console.WriteLine("Error: Code coverage file not found.");
return -2; // error
}
// parse code coverage file
Console.WriteLine($"Code Coverage File: {o.Filename}");
CodeSummary summary = ParseTestResults(o.Filename);
if (summary == null)
{
Console.WriteLine("Error: Parsing code coverage file.");
return -2; // error
}
else
{
// generate badge
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
// parse code coverage file
Console.WriteLine($"Code Coverage File: {o.Filename}");
CodeSummary summary = ParseTestResults(o.Filename);
if (summary == null)
{
Console.WriteLine("Error: Parsing code coverage file.");
return -2; // error
}
else
{
// generate badge
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
// generate output
string output;
string fileExt;
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
{
fileExt = "txt";
output = GenerateTextOutput(summary, badgeUrl);
}
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
{
fileExt = "md";
output = GenerateMarkdownOutput(summary, badgeUrl);
}
else
{
Console.WriteLine("Error: Unknown output format.");
return -2; // error
}
// generate output
string output;
string fileExt;
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
{
fileExt = "txt";
output = GenerateTextOutput(summary, badgeUrl);
}
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
{
fileExt = "md";
output = GenerateMarkdownOutput(summary, badgeUrl);
}
else
{
Console.WriteLine("Error: Unknown output format.");
return -2; // error
}
// output
if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine(output);
}
else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase))
{
File.WriteAllText($"code-coverage-results.{fileExt}", output);
}
else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine(output);
File.WriteAllText($"code-coverage-results.{fileExt}", output);
}
else
{
Console.WriteLine("Error: Unknown output type.");
return -2; // error
}
// output
if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine(output);
}
else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase))
{
File.WriteAllText($"code-coverage-results.{fileExt}", output);
}
else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine(output);
File.WriteAllText($"code-coverage-results.{fileExt}", output);
}
else
{
Console.WriteLine("Error: Unknown output type.");
return -2; // error
}
return 0; // success
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}");
return -3; // unhandled error
}
},
errs => -1); // invalid arguments
return 0; // success
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}");
return -3; // unhandled error
}
},
_ => -1); // invalid arguments
}
private static CodeSummary ParseTestResults(string filename)
@@ -143,7 +141,7 @@ namespace CodeCoverageSummary
Name = item.Attribute("name").Value,
LineRate = double.Parse(item.Attribute("line-rate").Value),
BranchRate = double.Parse(item.Attribute("branch-rate").Value),
Complexity = int.Parse(item.Attribute("complexity").Value)
Complexity = int.Parse(item.Attribute("complexity")?.Value ?? "0")
};
summary.Packages.Add(packageCoverage);
summary.Complexity += packageCoverage.Complexity;