Giter VIP home page Giter VIP logo

cicirello / jacoco-badge-generator Goto Github PK

View Code? Open in Web Editor NEW
93.0 93.0 42.0 668 KB

Coverage badges, and pull request coverage checks, from JaCoCo reports in GitHub Actions

Home Page: https://actions.cicirello.org/jacoco-badge-generator/

License: MIT License

Dockerfile 0.08% Python 99.92%
badge-generator badges branches-coverage c0-coverage c1-coverage coverage coverage-report github-actions instructions-coverage jacoco java pull-request-check testing

jacoco-badge-generator's Introduction

Vincent A Cicirello

Vincent A. Cicirello

Sites where you can find me or my work
Web and social media Personal Website LinkedIn DEV Profile Stack Overflow profile StackExchange profile
Software development Github Maven Central PyPI Docker Hub
Publications Google Scholar ORCID DBLP ACM Digital Library IEEE Xplore ResearchGate arXiv

My bibliometrics

My GitHub Activity

If you want to generate the equivalent to the above for your own GitHub profile, check out the cicirello/user-statistician GitHub Action.

jacoco-badge-generator's People

Contributors

cicirello avatar dependabot[bot] avatar divinenickname avatar eransamo avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

jacoco-badge-generator's Issues

Add ability to Fail the pipeline if the code coverage was decreased

I want to implement the code coverage check as a required verification step for the PR's to the master branch.
I think that it is possible to implement it as an additional feature for the jacoco-badge-generator.
example:

      - name: Generate JaCoCo Badge
        id: jacoco
        uses: cicirello/[email protected]
        with:
          fail-on-decrese: true

Also, it will be great to have such option as:

    fail-when-coverage-lessThan: 60

Which will fail the pipeline when coverage is less than provided argument.

Feature Req: Generate badges from JaCoCo reports in xml format

Is your feature request related to a problem? Please describe.
The Pester PowerShell testing framework allows users to output code coverage reports as JaCoCo xml files. However, this action requires input in the form of csv files.

Describe the solution you'd like
A new input option jacoco-xml-file that works for JaCoCo xml files.

Describe alternatives you've considered
I could not find any simple way to convert from csv to xml. I could also request that the Pester framework add an option to output as csv, but I think it makes more sense to start here.

Additional context
N/A

Thank you for your consideration!

No Jacoco report with Java 17

Describe the bug
After upgrading to Jdk17 from 11 the jacoco badge github action failing with the below error.

  • name: Generate JaCoCo Badge
    id: jacoco
    uses: cicirello/jacoco-badge-generator@v2
    with:
    badges-directory: badges
    generate-branches-badge: true
    generate-summary: true
    • name: Log coverage percentage
      run: |
      echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
      echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"
    • name: Upload JaCoCo coverage report
      uses: actions/upload-artifact@v3
      with:
      name: jacoco-report
      path: target/site/jacoco/
    • name: Upload JaCoCo coverage badge
      uses: actions/upload-artifact@v3
      with:
      name: codecoverage-badge
      path: ./badges
    • name: List files in target
      run: |
      ls -l ./badges
    • name: Comment on PR with coverage percentages
      if: ${{ github.event_name == 'pull_request' }}
      run: |
      REPORT=$(<badges/coverage-summary.json)
      COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
      BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
      NEWLINE=$'\n'
      BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* Coverage: ${COVERAGE}${NEWLINE}* Branches: ${BRANCHES}"
      gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
      continue-on-error: true
      env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

generate-branches-badge: true
generate-summary: true
jacoco-csv-file: target/site/jacoco/jacoco.csv
coverage-badge-filename: jacoco.svg
branches-badge-filename: branches.svg
generate-coverage-badge: true
coverage-label: coverage
branches-label: branches
on-missing-report: fail
fail-if-coverage-less-than: 0
fail-if-branches-less-than: 0
fail-on-coverage-decrease: false
fail-on-branches-decrease: false
intervals: 100 90 80 70 60 0
colors: #4c1 #97ca00 #a4a61d #dfb317 #fe7d37 #e05d44
generate-coverage-endpoint: false
generate-branches-endpoint: false
coverage-endpoint-filename: jacoco.json
branches-endpoint-filename: branches.json
summary-filename: coverage-summary.json
env:
DOCKER_REGISTRY: https://packages.aa.com
DOCKER_REPOSITORY_DEV: packages.aa.com/docker-dev/dotcwebappimage
REPO_NAME: pcs-dotcras-webapp
JAVA_HOME: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.7-7/x64
JAVA_HOME_17_X64: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.7-7/x64
/usr/bin/docker run --name c9a4a5cf7c06edd4384493bf0d4f88f418a56b_6564cb --label c9a4a5 --workdir /github/workspace --rm -e "DOCKER_REGISTRY" -e "DOCKER_REPOSITORY_DEV" -e "REPO_NAME" -e "JAVA_HOME" -e "JAVA_HOME_17_X64" -e "INPUT_BADGES-DIRECTORY" -e "INPUT_GENERATE-BRANCHES-BADGE" -e "INPUT_GENERATE-SUMMARY" -e "INPUT_JACOCO-CSV-FILE" -e "INPUT_COVERAGE-BADGE-FILENAME" -e "INPUT_BRANCHES-BADGE-FILENAME" -e "INPUT_GENERATE-COVERAGE-BADGE" -e "INPUT_COVERAGE-LABEL" -e "INPUT_BRANCHES-LABEL" -e "INPUT_ON-MISSING-REPORT" -e "INPUT_FAIL-IF-COVERAGE-LESS-THAN" -e "INPUT_FAIL-IF-BRANCHES-LESS-THAN" -e "INPUT_FAIL-ON-COVERAGE-DECREASE" -e "INPUT_FAIL-ON-BRANCHES-DECREASE" -e "INPUT_INTERVALS" -e "INPUT_COLORS" -e "INPUT_GENERATE-COVERAGE-ENDPOINT" -e "INPUT_GENERATE-BRANCHES-ENDPOINT" -e "INPUT_COVERAGE-ENDPOINT-FILENAME" -e "INPUT_BRANCHES-ENDPOINT-FILENAME" -e "INPUT_SUMMARY-FILENAME" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/pcs-dotcras-webapp/pcs-dotcras-webapp":"/github/workspace" c9a4a5:cf7c06edd4384493bf0d4f88f418a56b "target/site/jacoco/jacoco.csv" "badges" "jacoco.svg" "branches.svg" "true" "true" "fail" "0" "0" "false" "false" "100 90 80 70 60 0" "#4c1 #97ca00 #a4a61d #dfb317 #fe7d37 #e05d44" "false" "false" "jacoco.json" "branches.json" "true" "coverage-summary.json" "coverage" "branches"
WARNING: Report file target/site/jacoco/jacoco.csv does not exist or glob target/site/jacoco/jacoco.csv is empty.
WARNING: No JaCoCo csv reports found.

Feature Req: Add documentation to execute without github actions or docker

Is not an issue. Is just the requirement to generate the badge images without github actions

Describe the solution you'd like
Just a couple of lines showing how to run the python code to generate the images

Describe alternatives you've considered
I reviewed the tests and with some intuition I created this sentence:

python JacocoBadgeGenerator.py jacoco.csv /home coverage.png branch.png true true fail 50 50 true true '100, 90, 80, 70, 60, 0' "#ffffff" true true 50 50 true summary.txt

Also it would be appreciated a markdown table in the readme explaining the parameters.

Can I make you a PR to your readme?

Feature request: absolute path for jacoco-csv-file

Describe the bug / To Reproduce
specifiying an absolute path for jacoco-csv-file results in:
WARNING: Report file /home/runner/work/soot-reloaded/soot-reloaded/report/target/jacoco-aggregate/jacoco.csv does not exist.
WARNING: No JaCoCo csv reports found.

The file exists (checked with stat).

Expected behavior
As with a relative path - which i am using now and it works.

Replace the use of GitHub Action's deprecated set-output

Describe the bug
GitHub Actions has deprecated the set-output workflow command, which we are currently using for workflow outputs of the action. See https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/. That same link indicates the replacement.

To Reproduce
Steps to reproduce the behavior:

  1. Run the action.
  2. Inspect the workflow run.
  3. Notice the deprecation warning.

Expected behavior
No deprecation warning.

BUG: Maven multi-module project can't find 'target/site/jacoco/jacoco.csv'

Describe the bug
I manage a multi-module maven project and when it comes to run cicirello/[email protected], I got the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'target/site/jacoco/jacoco.csv'

Indeed, the parent artefact has no target/site/jacoco directory whereas modules have.

To Reproduce
Steps to reproduce the behavior:

  1. First, create a dummy mutli-module project like this one
  2. Then define at least one test in each sub-project
  3. Finally define GH actions including cicirello/[email protected]
  4. See error

Expected behavior
I suppose the default behavior should scan for all target directories, from parent to children to look for all CSV files.

Relevant System Info (please complete the following information):

Best regards,
CP

Matrix testing Python versions for unit tests and CLI mode

Summary

Revise GitHub Actions workflow for matrix testing of Python versions supported by the CLI mode (for the unit tests and for the CLI mode of the tool itself). Note: this is not necessary for the GitHub Actions mode since as an Action it runs within a Docker container with the current version of Python.

BUG: file not found in Multi-module

I have a two-module project and I use TestNG as testing framework, which allows (like JUnit I believe) to declare groups.
I declared 8 groups, (a) some are tagged in both modules, (b) some in only one of them.
I configured this GitHub action in order to list jacoco-csv files but in (b) case only one exists.

When I run the action, it throws FileNotFoundError: [Errno 2] No such file or directory: 'solver/target/site/jacoco/jacoco.csv' which is expected. But I wonder whether it is possible to add something like:

if os.path. exists(filename):

just before JacocoBadgeGenerator.py#L90.

Feature Req: Support glob to find jacoco csv files in multi module projects

Hi @cicirello,

thanks for this great action, I think it is very useful.

I have one question/suggestion related to maven multi module projects.

Is your feature request related to a problem? Please describe.

In your example, all modules are listed. This works for a small number of modules, but introduces the risk that when a new module is added to the project, it is not added here.

Describe the solution you'd like

I think it would be nice if a glob pattern could be provided here instead of the full list like **/jacoco.csv.

Describe alternatives you've considered

It is possible to use this workaround, which is a bit verbose:

      - name: Find JaCoCo reports of modules
        run: |
          find . -name jacoco.csv
          echo "jacoco_csv_files=`find . -name jacoco.csv | tr '\n' ' '`" >> "$GITHUB_OUTPUT"
        id: find_jacoco
      - name: Generate JaCoCo Badge
        id: jacoco
        uses: cicirello/jacoco-badge-generator@v2
        with:
          generate-branches-badge: true
          jacoco-csv-file: >
            ${{ steps.find_jacoco.outputs.jacoco_csv_files }}

Additional context

Just an additional thought:
Maybe it would even be nice to have a glob pattern as the default as opposed to 'target/site/jacoco/jacoco.csv', which should work for single and multi module projects. I don't see much downsides, except maybe that searching using the glob pattern will be a little slower as the hard coded default path.

Best,
Florian

Question: Badges was not generated

Describe the bug
Maybe it's a beginner question and I'm doing something wrong, but I have a workflow running your action and I can't see the badge in the read.me file.

To Reproduce
Steps to reproduce the behavior:

  1. Run the workflow build
  2. Add the read.me code like the example ![Coverage](https://github.com/pablobaldez/test-coverage-sample/actions/workflows/pr-build.yml/jacoco.svg)

Expected behavior
I was expecting to see the badge such as the build badge

Screenshots
here is how my read me is
Screenshot 2022-06-30 at 21 16 24

Additional context
here is my GitHub repository if you want to check more details https://github.com/pablobaldez/test-coverage-sample

Getting ZeroDivisionError: division by zero

Hey, first of all thank you for this helpful plugin.

When I'm running the plugin "cicirello/[email protected]" in my workflow I'm getting this error:

Traceback (most recent call last):
File "/JacocoBadgeGenerator.py", line 189, in
cov, branches = computeCoverage(jacocoCsvFile)
File "/JacocoBadgeGenerator.py", line 96, in computeCoverage
return covered / (covered + missed), coveredBranches / (coveredBranches + missedBranches)
ZeroDivisionError: division by zero

I opened my csv file and yes I can see zeros in the data, specifically I see BRANCH_MISSED and BRANCH_COVERED in some tests are both 0. So is it the problem from jacoc for not filling those columns with data or the script can omit these tests cases if both covered and missed are 0?

Workflow to publish package to PyPi during release for CLI usage

Summary

Add a workflow that runs on release events as well as workflow_dispatch events that publishes the package on PyPI. This way whenever a GitHub release is created to release the Action to the GitHub Marketplace, the command-line utility is simultaneously released to PyPI.

Feature Req: Change coverage badge text

We have multiple workfows in a single repository creating different coverages. We'd like to set the label text on the badge to show which coverage was calculated. E.g. instead of

coverage: 70,4%

we'd like to change the text to

coverage (product.core): 70,4%

I found no possible solutions to this problem in your documentation, maybe there is none yet!

Replacement for set-output may break some self-hosted cases

Problem

Unfortunately, this is going to break usage for self-hosted GHES enterprise organizations that are not on the bleeding edge. I am still on GHES 3.5, which uses runner version 2.294.0 while this requires at least 2.297.0. I am going to have to pin to 2.7.0 if reverting is not possible.

Originally posted by @erodewald in #84 (comment)

Possible Solution

Use set-output if GITHUB_OUTPUT env variable doesn't exist.

Refactor main block to extract a main function

Summary

Currently, the entrypoint of the action is an if __name__ == "__main__" block. This works fine. However, one user requested the ability to use outside of GitHub Actions as a command line utility (see #40). In order to enable such functionality, parameters will need to be processed differently than they are as a GitHub Action.

To Do

  1. Extract most of the current if __name__ == "__main__" block to a main function, except for the parameter processing.
  2. Process parameters for the GitHub Action context in the existing block, and pass to the new main function.

Future

This issue does not actually fully address the command line utility use-case. However, the proposed new main function will greatly simplify future support. This issue is a pre-requisite to #40.

Feature Req: How to use directly without github action?

Is your feature request related to a problem? Please describe.
Is not related to a problem. Is just the request of a piece of documentation in which you show us how to use it directly without github actions

Describe the solution you'd like
Maybe on a direct usage section in readme, you could add something like this:

python3 JacocoBadgeGenerator.py \
/foo/project/target/site/jacoco/jacoco.csv \
badges \
coverage.svg \
branches.svg \
true \
true \
fail \
0.1 \
0.1 \
false \
false \
"10,30,50,70,90,100" \
'#4c1 #97ca00 #a4a61d #dfb317 #fe7d37 #e05d44' \
true \
true \
coverage.json \
branches.json \
true \
summary.json

There were many attempts to figure out the relationship between 12 and 13 args (colors and intervals). Maybe this comments could be
improved to highlight that relationship

Describe alternatives you've considered
Maybe an extra test on https://github.com/cicirello/jacoco-badge-generator/blob/main/tests/tests.py with this direct usage.

Thanks!

Feature Req: edit workflow summary values

Is your feature request related to a problem? Please describe.
Not related to a problem, more of an improvement to the summary that is generated after a workflow run.

Describe the solution you'd like
I've would like to be able to change the values of the workflow summary. See attached screenshot.

We are generating multiple badges in one workflow, by using cicirello/jacoco-badge-generator@v2 multiple times on one workflow. And when the workflow is complete it posts a workflow summary with default values, but they all look the same since there is currently no way of customize the summary.

Describe alternatives you've considered
Have considered just using separate workflows for generating each badge, but we would still like to customize the values. And we can only find the option to completely turn it off.

Additional context
Screenshot:
image

Feature Req: add exact coverage value, with virtually infinite precision into some hidden field of JSON and SVG for future comparisons

In a huuge projects, 0.1% might include a couple of factories implementations plus minor bugfixes. Therefore, one decimal place precision is counterproductive - someone might spend significant effort, adding coverage by 0.04%, and someone else might just add some non-covered reducing overall coverage by 0.05%. After rounding to the first decimal place, the initial value, the value after the first contributor, and reduced value after the second one are undistinguishable. That discourages the first contributor from writing any more tests.

Please, add the input parameter "rounding" to the plugin.

Option to generate Shields.io JSON endpoints instead of SVG badges

Summary
The badges currently generated are styled in a way that is based on Shields's "flat" style, although no actual dependency on Shields (generated entirely within the action). Some users of this GitHub action may use other shields badges in their repos using one of their other styles, and may prefer all of their repo badges to have a common style. Although one potential solution would be to replicate all of the shields styles within the action. that would seem overly redundant.

Proposed Solution
Keep the default behavior as the default (generate badges directly within the action including the way they are currently styled). Add an option via action inputs to generate JSON endpoints with the fields expected by shields, either instead of or in addition to generating the badges directly.

Users who like the default style can continue to use as is, keeping the performance benefit of serving the badge directly from the repo (e.g., already generated, and one http request directly to the badge). Users who want to match other shields styles can opt-in to generating a JSON endpoint instead, using shields to generate the badge (e.g., use shields's endpoint badge, passing url to JSON to Shields to generate the badge). That would also enable those users to pass Shields's query parameters to change style, etc.

Sample badges not showing in GitHub Marketplace listing

Summary

The sample badges in the README are visible when viewing the repository, but not when viewing the action in the GitHub Marketplace. They previously appeared there. It is likely a bug in the GitHub Marketplace for links to images relative within the repository.

BUG: An extra __pycache__ file with root permission will break the workflow

Describe the bug
A clear and concise description of what the bug is.

The newest version 2.6 will generate a __pycache__ folder which has a root permission and this will break the next step to remove it without sudo permission.

To Reproduce
Steps to reproduce the behavior:

  1. First, '....'
  2. Then '....'
  3. Finally '....'
  4. See error or incorrect behavior, etc.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

image

Relevant System Info (please complete the following information):

  • OS
  • Version
  • etc

Additional context
Add any other context about the problem here.

Feature Req: Badge for multi-module Maven project

I have a multi-module Maven project with 4 sub modules. Each of them have its own tests and produce a separate Jacoco report.
I would like to present in my README,md a badge with %coverage of all the Jacoco results together.

Instead of passing a single 'jacoco-csv-file' argument, it would be great to pass a list of files so the badge will present an average coverage weighted by the lines number of each sub module.

Since Jacoco 0.7.7, a goal of 'jacoco:report-aggregate' is supported, which create a single Jacoco report from multiple sub modules.
My problem with this alternative is that it requires an addition dummy sub module which depends on all the other sub modules, and the aggregated Jacoco report is actually the dummy sub module report.
This solution seems a bit messy to me and I want to avoid creating an additional sub module and keep my library cleaner.
Also I do want the reports themselves to be separate, as I prefer each sub module to test itself properly.

Thanks a lot of the tool, love it!

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.