Giter Site home page Giter Site logo

lucassabreu / comment-coverage-clover Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 4.0 486 KB

Github Action that automatically adds a comment with a summary of coverage reports (clover)

Home Page: https://github.com/marketplace/actions/coverage-report-as-comment-clover

JavaScript 3.21% TypeScript 96.66% Vim Script 0.12%
github-actions coverage pull-requests

comment-coverage-clover's Introduction

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.

comment-coverage-clover's People

Contributors

dennislammers avatar dependabot[bot] avatar jacekk avatar lucassabreu avatar sertxudev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

comment-coverage-clover's Issues

Spelling branchs

Screenshot 2023-05-24 at 16 20 54

In two different places, both in summary and table heading text.

Don't show empty files

Hi, thanks to this GitHub Action I'm able to review the coverage of my projects.

I was wondering if there's a way to hide the empty files from the report comment.

For example, those four files have no content inside.

image

image

On the other hand, this file has some code but no line is being tested.

image

image

As you can see both examples are shown in the table report.
I'm currently hiding files with more than 95% tested, and I wanted to hide the four files without code.


MergesPdfs.php

<file name="/var/www/html/app/Actions/Utilities/MergesPdfs.php">
  <class name="App\Actions\Utilities\MergesPdfs" namespace="global">
    <metrics complexity="2" methods="1" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="0" elements="11" coveredelements="0"/>
  </class>
  <line num="16" type="method" name="mergePdfs" visibility="protected" complexity="2" crap="6" count="0"/>
  <line num="17" type="stmt" count="0"/>
  <line num="19" type="stmt" count="0"/>
  <line num="21" type="stmt" count="0"/>
  <line num="22" type="stmt" count="0"/>
  <line num="25" type="stmt" count="0"/>
  <line num="26" type="stmt" count="0"/>
  <line num="27" type="stmt" count="0"/>
  <line num="28" type="stmt" count="0"/>
  <line num="30" type="stmt" count="0"/>
  <line num="34" type="stmt" count="0"/>
  <metrics loc="37" ncloc="31" classes="1" methods="1" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="0" elements="11" coveredelements="0"/>
</file>

RepositoryNotFoundException.php

<file name="/var/www/html/app/Exceptions/RepositoryNotFoundException.php">
  <class name="App\Exceptions\RepositoryNotFoundException" namespace="global">
    <metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
  </class>
  <metrics loc="11" ncloc="10" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</file>

Maybe the action could check if the values classes, methods, conditionals, statements and/or elements are 0, to know if the file is indeed empty.

Error: this action requires a pull request context to be able to comment https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request

from @AnmolSaxenaVodafone at here


I am using the below step to generate a Clover report:

      # Generate Clover Report
      - name: Generate Clover Report
        uses: lucassabreu/comment-coverage-clover@main
        with:
          file: target/site/clover/clover.xml
          with-chart: false

After this commit, I have started getting below exception when I merge the change to the main branch:

Error: this action requires a pull request context to be able to comment
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request Stack: undefined
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Generate Clover Report

Can you advise if the Generate Clover Report step needs to be updated?

Feature Request: Scope for Comments

Hey 👋🏼 It's me again.

I wanted to request a feature that would come in pretty handy: Scoped PR Comments.

In my organization, we're using monorepos that contain backend and frontend code. They are tested by separate frameworks in separate workflows, and thus generate two different coverage reports. We don't want to combine them because different teams work on Frontend/Backend.

My request is to add a feature that allows to set a scope for the PR comment so that multiple comments per PR are possible. In our case that would be one comment for backend coverage and one for frontend coverage.

feature request: combine multiple clover reports into a single segmented pr comment

Screenshot 2023-06-05 at 14 46 56

I work in a javascript monorepo with lots of workspaces. Each workspaces has their own test suite and their own coverage (distributed ownership).

Now, if a PR touches multiple workspaces, comment-coverage-clover will create a PR comment for each of the workspace touched. See screenshot. It then works correctly and keeps updating individual comments with corresponding changes with the associated workspace.

The HTML of the comments are in (react) high level pseudo code:

files.forEach((filename) => 
  <Comment key={filename}>    // One comment for each workspace
    <CommitSummary /> // Same commit sha for all comments!
    <FileSummary filename={filename} />
    <AsciiGraph />
    <Foldable>
      <Summary />
    </Foldable>
  </Comment>
);

I want to raise the discussion asking if it would it be nicer to have the option of getting one single comment? Pseudo code:

<Comment>  // NEW: One single comment for all workspaces
  <CommitSummary /> // NEW: One single commit summary since it is always "latest"
  files.forEach((filename) => 
    <div id={filename}>
      <FileSummary filename={filename} />
      <Foldable> // NEW: Fold each workspace summary as to not have a huge graph expanded for each of them
        <AsciiGraph />
        <Foldable>
          <Summary />
        </Foldable>
      </Foldable>
    </div>
  );
</Comment>

To summarize:

  • One single comment per commit and workspace
  • In case there are a many workspaces, it might be better to fold ALL of them individually so the AsciiGraph doesnt eat up so much space

I guess the challenge is when posting many comments to keep updating the same PR comment (concurrently?) and only updating the relevant section. Perhaps not even possible? I mean, sure, it is possible but might require a server or comment locking due to concurrency or something else that makes it totally unfeasible.

WDYT?

How to handle base-file

I just started using GitHub Actions and so far I love it. And I would like to use this action. But it's not really clear to me how to handle the base-file.

In my case the base-file should be the coverage report from the main branch. But how do I access that from an action running in a PR?

  • Committing the base coverage report and automating that seems a little strange
  • I cannot access artifacts that weren't created in the same workflow

The only option I see would be to use a cache for that. With the only downside being that the cache will be deleted when it's not being accessed for 7 days in a row.

Or is there a better way to handle this?

Error: HttpError: Resource not accessible by integration Stack: HttpError: Resource not accessible by integration

When people open up Pull Requests from a fork my unit testing step fails with the following error. Pull requests opened from branches within the same repository work fine.

Error: HttpError: Resource not accessible by integration Stack: HttpError: Resource not accessible by integration
    at /home/runner/work/_actions/lucassabreu/comment-coverage-clover/main/bin/index.js:85179:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Table links to wrong file (folder missing)

I have a clover coverage xml on this format

<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1684932596677" clover="3.2.0">
  <project timestamp="1684932596677" name="All files">
    <metrics statements="794" coveredstatements="716" conditionals="252" coveredconditionals="178" methods="130" coveredmethods="106" elements="1176" coveredelements="1000" complexity="0" loc="794" ncloc="794" packages="8" files="24" classes="24"/>
    <package name="create-server">
      <metrics statements="39" coveredstatements="33" conditionals="14" coveredconditionals="7" methods="5" coveredmethods="5"/>
      <file name="response-cache-plugin.ts" path="/Users/MKLIPPIN/repos/graphql-federation-mono/dgs/environmental/create-server/response-cache-plugin.ts">
        <metrics statements="23" coveredstatements="23" conditionals="6" coveredconditionals="5" methods="2" coveredmethods="2"/>

I am running the GH Action with this config:

    - name: Coverage Report as Comment (Clover)
      uses: lucassabreu/[email protected]
      with:
        github-token: '${{ secrets.GH_PAT }}'
        file: ./dgs/${{ inputs.service_name }}/coverage/clover.xml
        dir-prefix-keep: dgs/${{ inputs.service_name }}

So if we consider the path in clover which in my example is /Users/MKLIPPIN/repos/graphql-federation-mono then on CI it should be whatever, maybe it is /home/runner/work/graphql-federation-mono.

But when it generates the table all the links are wrong, it is completely missing folder:

https://github.com/%COMPANY%/graphql-federation-mono/blob/%sha%/dgs/environmental//response-cache-plugin.ts

, in this case it is missing the path segment create-server.

But if there are multiple levels of folder, it removes them all and replaces with emty string.

What's wrong? Something unexpected in my clover xml?

I have also tried experimenting with dir-prefix but not found anything that works.

Screenshot 2023-05-24 at 16 22 18

This is how my table looks, there is no folder information here either, perhaps a clue? It just appears as a flat structure, which is confusing when a lot of files are called index.ts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.