Skip to content

lucassabreu/comment-coverage-clover

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Note

GitHub Marketplace may not show all the avaliable releases, check the repository for the newest release.

Comment Coverage (Clover)

This action reads a Clover Coverage Report and creates one (and only one) comment on the Pull Request related to the run with a summary of the report.

It was highly inspired on the project: danhunsaker/clover-reporter-action, but with expanded configuration to better suit the needs on our projects.

PR Comment Example

Coverage report for commit: 9f99ed3

File: clover.example.base.xml

Summary - Lines: 87.97% 🔽 | Methods: 81.05% 🔼
FilesLinesMethodsBranches
src/main/php/PHPMD
   AbstractNode.php86.05%70.59%-
   AbstractRenderer.php100.00%100.00%-
   AbstractRule.php80.00%72.00%-
   PHPMD.php90.32%75.00%-
   Parser.php89.19%92.86%-
   ParserFactory.php90.63%71.43%-
   ProcessingError.php100.00%100.00%-
   Report.php100.00%100.00%-
   RuleSet.php87.10%71.43%-
   RuleSetFactory.php96.32%86.36%-
   RuleViolation.php73.33%33.33%-
src/main/php/PHPMD/Baseline
   BaselineFileFinder.php100.00%100.00%-
   BaselineSet.php100.00%100.00%-
   BaselineSetFactory.php100.00%100.00%-
   BaselineValidator.php100.00%100.00%-
   ViolationBaseline.php100.00%100.00%-
src/main/php/PHPMD/Exception
   RuleClassFileNotFoundException.php100.00%100.00%-
   RuleClassNotFoundException.php100.00%100.00%-
   RuleSetNotFoundException.php100.00%100.00%-
src/main/php/PHPMD/Node
   ASTNode.php100.00%100.00%-
   AbstractCallableNode.php100.00%100.00%-
   AbstractNode.php100.00%100.00%-
   AbstractTypeNode.php100.00%100.00%-
   Annotation.php100.00%100.00%-
   Annotations.php100.00%100.00%-
   ClassNode.php100.00%100.00%-
   FunctionNode.php50.00%50.00%-
   InterfaceNode.php100.00%100.00%-
   MethodNode.php100.00%100.00%-
   TraitNode.php100.00%100.00%-
src/main/php/PHPMD/Renderer
   BaselineRenderer.php100.00%100.00%-
   GitHubRenderer.php100.00%100.00%-
   HTMLRenderer.php85.71%63.64%-
   JSONRenderer.php100.00%100.00%-
   RendererFactory.php100.00%100.00%-
   SARIFRenderer.php98.36%80.00%-
   TextRenderer.php100.00%100.00%-
   XMLRenderer.php100.00%100.00%-
src/main/php/PHPMD/Rule
   AbstractLocalVariable.php87.32%69.23%-
   CyclomaticComplexity.php100.00%100.00%-
   ExcessivePublicCount.php100.00%100.00%-
   UnusedFormalParameter.php100.00%100.00%-
   UnusedLocalVariable.php96.92%84.62%-
   UnusedPrivateField.php97.67%88.89%-
   UnusedPrivateMethod.php100.00%100.00%-
src/main/php/PHPMD/Rule/CleanCode
   DuplicatedArrayKey.php84.38%50.00%-
   ElseExpression.php90.00%66.67%-
   ErrorControlOperator.php100.00%100.00%-
   IfStatementAssignment.php95.00%80.00%-
   MissingImport.php93.75%66.67%-
   StaticAccess.php100.00%100.00%-
   UndefinedVariable.php88.00%64.29%-
src/main/php/PHPMD/Rule/Controversial
   CamelCaseMethodName.php100.00%100.00%-
   CamelCaseParameterName.php100.00%100.00%-
   CamelCasePropertyName.php100.00%100.00%-
   CamelCaseVariableName.php93.75%50.00%-
src/main/php/PHPMD/Rule/Design
   CountInLoopExpression.php93.33%80.00%-
   CouplingBetweenObjects.php100.00%100.00%-
   DepthOfInheritance.php92.86%0.00%-
   DevelopmentCodeFragment.php100.00%100.00%-
   EmptyCatchBlock.php100.00%100.00%-
   EvalExpression.php100.00%100.00%-
   ExitExpression.php100.00%100.00%-
   GotoStatement.php100.00%100.00%-
   LongClass.php100.00%100.00%-
   LongMethod.php100.00%100.00%-
   LongParameterList.php100.00%100.00%-
   NpathComplexity.php100.00%100.00%-
   NumberOfChildren.php100.00%100.00%-
   TooManyFields.php100.00%100.00%-
   TooManyMethods.php100.00%100.00%-
   TooManyPublicMethods.php100.00%100.00%-
   WeightedMethodCount.php100.00%100.00%-
src/main/php/PHPMD/Rule/Naming
   BooleanGetMethodName.php100.00%100.00%-
   ConstantNamingConventions.php100.00%100.00%-
   ConstructorWithNameAsEnclosingClass.php88.89%0.00%-
   LongClassName.php100.00%100.00%-
   LongVariable.php100.00%100.00%-
   ShortClassName.php100.00%100.00%-
   ShortMethodName.php100.00%100.00%-
   ShortVariable.php96.92%92.31%-
src/main/php/PHPMD/TextUI
   Command.php100.00%100.00%-
   CommandLineOptions.php71.43%77.42%-
src/main/php/PHPMD/Utility
   Paths.php100.00%100.00%-
   Strings.php100.00%100.00%-
🤖 comment via lucassabreu/comment-coverage-clover

from here

Configuration

Input Description
file The location of the clover file.
Required
base-file The location of the clover file with a previous state of the coverage to compare
dir-prefix Section of the file on clover report to remove
Default: github.workspace
Required
dir-prefix-keep Section of the dir-prefix to keep when creating link to file.
Example: if your php application is at "$REPO/backend", then you should set this to "backend"
only-with-cover Should only list files with at least one line covered.
only-with-coverable-lines Should only list files with at least one "coverable" line of code
Example: interfaces or abstract classes with no implementation
lang In which language to format the numbers
Default: en-US
chart-size How many characters to use on chart's bar
Default: 23
with-chart Add a chart with the distribution of coverage on files
Default: true
max-line-coverage-decrease How much the line coverage percentage can decrease without failing
max-method-coverage-decrease How much the method coverage percentage can decrease without failing
min-line-coverage Minimum percentage acceptable for line coverage
Default: 0
min-method-coverage Minimum percentage acceptable for method coverage
Default 0
with-table Add a table with a list of files and its coverage
Default: true
with-branches Adds the column "Branches" with the branching coverage
Default: true
show-percentage-change-on-table Show in percentage how much the file coverage changed per file
table-type-coverage Which of the coverage percentages to filter
Default: "lines"
table-below-coverage Show only files below or equal to this coverage percentage
Default: 100
table-above-coverage Show only files above or equal to this coverage percentage
Default: 0
table-coverage-change Show only files which their coverage changed equal or above this percentage
Default: 0
signature Custom signature to be used at the bottom of the comment.
If you need multiple comments per pull request each step needs to have a unique signature
github-token Custom PAT to be used instead of the default action token, should have the repo scope
skip-comments-on-forks Should skip trying to comment on pull requests created from forks
Default: false

Example usage

Simple comment

name: Unit Tests with coverage

on:
  pull_request:

jobs:
  php-tests:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    env:
      COMPOSER_NO_INTERACTION: 1

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.0
          coverage: none
          tools: composer:v2

      - name: Install dependencies
        run: composer install --prefer-dist --no-progress

      - name: Execute Unit Tests
        run: phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml

      - name: Coverage Report as Comment (Clover)
        uses: lucassabreu/comment-coverage-clover@main
        with:
          file: coverage.xml

Using artifacts to compare coverage changes

name: Unit Tests with coverage

on:
  pull_request:
  push:
    branches:
      - main

jobs:
  php-tests:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    env:
      COMPOSER_NO_INTERACTION: 1

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.0
          coverage: none
          tools: composer:v2

      - name: Install dependencies
        run: composer install --prefer-dist --no-progress

      - name: Execute Unit Tests
        run: phpdbg -qrr vendor/bin/phpunit --coverage-clover=tests/coverage.xml

      - if: ${{ github.event_name == 'pull_request' }}
        name: Download artifact
        uses: dawidd6/[email protected]
        continue-on-error: true
        with:
          workflow: .github/workflows/coverage-report.yml # this file
          branch: main
          name: coverage-report
          path: tests/base

      - if: ${{ github.event_name != 'pull_request' }}
        uses: actions/upload-artifact@v2
        with:
          name: coverage-report
          path: tests/coverage.xml

      - if: ${{ github.event_name == 'pull_request' }}
        name: Coverage Report as Comment (Clover)
        uses: lucassabreu/comment-coverage-clover@main
        with:
          file: coverage.xml
          base-file: tests/base/coverage.xml

Restrictions on Forks

Github Actions imposes higher Restrictions on workflows triggered from forks in public repositories, where the default token generated will have only read permissions.

Because of that when this Action is run on pull requests from forks no comment will be created with the coverage report, instead the report will only be shown at the steps summary.

example of step summary with the report

If comments on pull request from forks are required for your workflow a PAT can be used, but be aware that doing that may open the owner of the PAT to the malicious intentions of the internet.