diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index c0c3645..bbcbf92 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -5,6 +5,7 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: permissions: contents: read diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index a741b8c..68e26bb 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -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/cosign-installer@v3.8.0 - name: Setup Docker Buildx uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 @@ -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 }} diff --git a/README.md b/README.md index fa9e761..a772796 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index bb3ee76..f2196f4 100644 --- a/action.yml +++ b/action.yml @@ -1,64 +1,70 @@ -name: 'Code Coverage Summary' -author: 'Irongut ' -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 " +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 }} diff --git a/src/CodeCoverageSummary/CommandLineOptions.cs b/src/CodeCoverageSummary/CommandLineOptions.cs index f525a9f..f58b231 100644 --- a/src/CodeCoverageSummary/CommandLineOptions.cs +++ b/src/CodeCoverageSummary/CommandLineOptions.cs @@ -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; } } } diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index f0cc63f..2f1383b 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -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}"; } @@ -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)) { @@ -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})")