Giter Club home page Giter Club logo

codacy-coverage-reporter's Introduction

Codacy Coverage Reporter

Codacy Badge Codacy Badge Build Status Maven Central

Multi-language coverage reporter for Codacy https://www.codacy.com

Setup

  1. Copy a Project API Token. You can find the token within a repository SettingsIntegrationsProject API.
  2. Set the Project API Token in your terminal, replacing %Project_Token% with your own:
export CODACY_PROJECT_TOKEN=%Project_Token%

⚠️ You should keep your API token well protected, as it grants owner permissions to your projects.

If you'd like to automate this process for multiple repositories you can authenticate using an Account API Token.

Self-hosted

To upload coverage to a self-hosted installation of Codacy you need to set your installation URL:

export CODACY_API_BASE_URL=<Codacy_instance_URL>:16006

Or use the flag: --codacy-api-base-url <Codacy_instance_URL>:16006.

Running Codacy Coverage Reporter

Requirements

  • bash or sh (Use bash on Ubuntu)
  • curl or wget
  • glibc

Using curl

bash <(curl -Ls https://coverage.codacy.com/get.sh)

Using wget

bash <(wget -q -O - https://coverage.codacy.com/get.sh)

On Alpine Linux

wget -qO - https://coverage.codacy.com/get.sh | sh

On Alpine Linux passsing command line options

wget -qO - https://coverage.codacy.com/get.sh | sh -s report -l Java -r report1.xml --partial

Choose a specific version

The script uses by default the latest version.

If you want to specify a coverage reporter version, use CODACY_REPORTER_VERSION environment variable.

You can find all versions in the Releases tab.

Manual Installation

Using GitHub Actions? Check out the codacy/coverage-coverage-reporter action.

If the automated script does not cover your use case, check the manual installation methods.

CircleCI Orb

Using CircleCI? Check out the codacy/coverage-reporter orb.

Supported formats

The following table contains the formats supported and which coverage tools generate them:

Language Coverage tools (examples) Formats Filename
Java JaCoCo
Cobertura
JaCoCo
Cobertura
jacoco*.xml
cobertura.xml
Scala sbt-jacoco
scoverage
JaCoCo
Cobertura
jacoco*.xml
cobertura.xml
Javascript Istanbul
Poncho
Mocha + Blanket.js
LCOV lcov.info, lcov.dat, *.lcov
Python Coverage.py Cobertura cobertura.xml
PHP PHPUnit PHPUnit XML
Clover
coverage-xml/index.xml
clover.xml
Ruby SimpleCov Cobertura
LCOV
cobertura.xml
lcov.info, lcov.dat, *.lcov
C# OpenCover
DotCover CLI
OpenCover
DotCover-DetailedXML
opencover.xml
dotcover.xml
Swift/Objective-C XCode Coverage Check here information about reports for this language

The reporter assumes the coverage reports filename follow the name convention. Otherwise, you must define the report's location with the flag -r.

If your coverage reports are in a different format you can use a format converter, such as ReportGenerator, to generate a supported format.

Unsuported Languages

If your language is not in the list of supported languages, you can still send coverage to Codacy. You can do it by providing the correct --language name and then add the --force-language flag.

Commit SHA hash detection

Codacy automatically detects a commit SHA hash from CI workflows, the git repository or command line arguments. See all supported environments.

Multiple coverage reports for the same language

In order to send multiple reports for the same language, you need to upload each report separately with the flag --partial and then notify Codacy, after all reports were sent, with the final command.

Example

  1. codacy-coverage-reporter report -l Java -r report1.xml --partial
  2. codacy-coverage-reporter report -l Java -r report2.xml --partial
  3. codacy-coverage-reporter final

Using the script

  1. bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l Java -r report1.xml --partial
  2. bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l Java -r report2.xml --partial
  3. bash <(curl -Ls https://coverage.codacy.com/get.sh) final

If you are sending reports with the partial flag for a certain language you should use it in all reports for that language to ensure the correct calculation of the coverage.

It might also be possible to merge the reports before uploading them to Codacy, since most coverage tools support merge/aggregation, example: http://www.eclemma.org/jacoco/trunk/doc/merge-mojo.html.

Other commands

For a complete list of commands and options: --help

Troubleshooting

Failed to upload report: Not Found

Error when running the command, then you'll probably have codacy-coverage-reporter 1.0.3 installed. Make sure you install version 1.0.4, that fixes that error.

Example (issue: #11) :

codacy-coverage-reporter report -l Java -r PATH_TO_COVERAGE/coverage.xml
2015-11-20 04:06:58,887 [info]  com.codacy Parsing coverage data...
2015-11-20 04:06:59,506 [info]  com.codacy Uploading coverage data...

2015-11-20 04:07:00,639 [error] com.codacy Failed to upload report: Not Found

Even after doing all of the above troubleshooting steps in case you still encounter the same error

2015-11-20 04:07:00,639 [error] com.codacy Failed to upload report: Not Found

Please try running the command with a --prefix option with path to your code as shown below , it helps to locate the files for which code coverage is desired

codacy-coverage-reporter report -l Java -r PATH_TO_COVERAGE/coverage.xml --prefix PATH_TO_THE_DIRECTORY

Example

codacy-coverage-reporter report -l Java -r api/target/site/jacoco/jacoco.xml --prefix api/src/main/java/

SubstrateSegfaultHandler caught signal 11

If you are experiencing segmentation faults uploading the coverage (due to oracle/graal#624), do this before running the reporter, as a workaround:

echo "$(dig +short api.codacy.com | tail -n1) api.codacy.com" >> /etc/hosts

What is Codacy?

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features:

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

codacy-coverage-reporter's People

Contributors

rtfpessoa avatar josemiguelmelo avatar mrfyda avatar machadoit avatar ljmf00 avatar lolgab avatar pedrorijo91 avatar dreigada avatar andreatp avatar ritagrilo avatar igfcoimbra avatar bmbferreira avatar caxaria avatar nmatpt avatar xplosunn avatar vzhd1701 avatar tobilarscheid avatar valfirst avatar thaddeusdiamond avatar koppor avatar ram042 avatar cog avatar gjsduarte avatar franciscodua avatar bjgill avatar amitmawkin avatar aharonha avatar bascoe10 avatar

Watchers

James Cloos avatar

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.