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

Add title option to Code Coverage Summary output #362

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

permissions:
contents: read
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ jobs:
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8

- name: Install Cosign
uses: sigstore/cosign-installer@9becc617647dfa20ae7b1151972e9b3a2c338a2b
with:
cosign-release: 'v1.9.0'
uses: sigstore/[email protected]

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325
Expand Down Expand Up @@ -117,4 +115,4 @@ jobs:
- name: Sign the Docker image
env:
COSIGN_EXPERIMENTAL: "true"
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ jobs:
indicators: true
output: both
thresholds: '60 80'
title: "Code Coverage Summary"

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
68 changes: 37 additions & 31 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,70 @@
name: 'Code Coverage Summary'
author: 'Irongut <murray.dave@outlook.com>'
description: 'A GitHub Action that reads Cobertura format code coverage files and outputs a text or markdown summary.'
name: "Code Coverage Summary with Title"
author: "syed-farazahmed <faraz313ahmed@emumba.com>"
description: "A GitHub Action that reads Cobertura format code coverage files and outputs a text or markdown summary."
branding:
icon: book-open
color: purple
inputs:
filename:
description: 'A comma separated list of code coverage files to analyse. Also supports using glob patterns to match multiple files.'
description: "A comma separated list of code coverage files to analyse. Also supports using glob patterns to match multiple files."
required: true
badge:
description: 'Include a Line Rate coverage badge in the output using shields.io - true / false (default).'
description: "Include a Line Rate coverage badge in the output using shields.io - true / false (default)."
required: false
default: 'false'
default: "false"
fail_below_min:
description: 'Fail if overall Line Rate below lower threshold - true / false (default).'
description: "Fail if overall Line Rate below lower threshold - true / false (default)."
required: false
default: 'false'
default: "false"
format:
description: 'Output Format - markdown or text (default).'
description: "Output Format - markdown or text (default)."
required: false
default: 'text'
default: "text"
hide_branch_rate:
description: 'Hide Branch Rate values in the output - true / false (default).'
description: "Hide Branch Rate values in the output - true / false (default)."
required: false
default: 'false'
default: "false"
hide_complexity:
description: 'Hide Complexity values in the output - true / false (default).'
description: "Hide Complexity values in the output - true / false (default)."
required: false
default: 'false'
default: "false"
indicators:
description: 'Include health indicators in the output - true (default) / false.'
description: "Include health indicators in the output - true (default) / false."
required: false
default: 'true'
default: "true"
output:
description: 'Output Type - console (default), file or both.'
description: "Output Type - console (default), file or both."
required: false
default: 'console'
default: "console"
thresholds:
description: 'Threshold percentages for badge and health indicators, lower threshold can also be used to fail the action.'
description: "Threshold percentages for badge and health indicators, lower threshold can also be used to fail the action."
required: false
default: '50 75'
default: "50 75"
title:
description: "Title to use in the output."
required: false
default: "Code Coverage Summary"
runs:
using: 'docker'
image: 'docker://ghcr.io/irongut/codecoveragesummary:v1.3.0'
using: "docker"
image: "docker://ghcr.io/syed-farazahmed/codecoveragesummary:v1.0.1"
args:
- '--files'
- "--files"
- ${{ inputs.filename }}
- '--badge'
- "--badge"
- ${{ inputs.badge }}
- '--fail'
- "--fail"
- ${{ inputs.fail_below_min }}
- '--format'
- "--format"
- ${{ inputs.format }}
- '--hidebranch'
- "--hidebranch"
- ${{ inputs.hide_branch_rate }}
- '--hidecomplexity'
- "--hidecomplexity"
- ${{ inputs.hide_complexity }}
- '--indicators'
- "--indicators"
- ${{ inputs.indicators }}
- '--output'
- "--output"
- ${{ inputs.output }}
- '--thresholds'
- "--thresholds"
- ${{ inputs.thresholds }}
- "--title"
- ${{ inputs.title }}
3 changes: 3 additions & 0 deletions src/CodeCoverageSummary/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ public class CommandLineOptions

[Option(longName: "thresholds", Required = false, HelpText = "Threshold percentages for badge and health indicators, lower threshold can also be used to fail the action.", Default = "50 75")]
public string Thresholds { get; set; }

[Option(longName: "title", Required = false, HelpText = "Title for the output.", Default = "Code Coverage Summary")]
public string Title { get; set; }
}
}
22 changes: 17 additions & 5 deletions src/CodeCoverageSummary/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ private static int Main(string[] args)
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
{
fileExt = "txt";
output = GenerateTextOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity);
output = GenerateTextOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity, o.Title);
if (o.FailBelowThreshold)
output += $"Minimum allowed line rate is {lowerThreshold * 100:N0}%{Environment.NewLine}";
}
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
{
fileExt = "md";
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity);
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity, o.Title);
if (o.FailBelowThreshold)
output += $"{Environment.NewLine}_Minimum allowed line rate is `{lowerThreshold * 100:N0}%`_{Environment.NewLine}";
}
Expand Down Expand Up @@ -299,13 +299,19 @@ private static string GenerateHealthIndicator(double rate)
}
else
{
return "";
return "";
}
}

private static string GenerateTextOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity)
private static string GenerateTextOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity, string title)
{
StringBuilder textOutput = new();
if (!string.IsNullOrWhiteSpace(title))
{
textOutput.AppendLine(title)
.AppendLine(new string('=', title.Length))
.AppendLine();
}

if (!string.IsNullOrWhiteSpace(badgeUrl))
{
Expand All @@ -329,10 +335,16 @@ private static string GenerateTextOutput(CodeSummary summary, string badgeUrl, b
return textOutput.ToString();
}

private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity)
private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity, string title)
{
StringBuilder markdownOutput = new();

if (!string.IsNullOrWhiteSpace(title))
{
markdownOutput.AppendLine($"# {title}")
.AppendLine();
}

if (!string.IsNullOrWhiteSpace(badgeUrl))
{
markdownOutput.AppendLine($"![Code Coverage]({badgeUrl})")
Expand Down