Codacy Coverage Reports
How to forward coverage reports to Codacy
Codacy is a code review tool that allows for automatic analysis, code coverage tracking, and extensive reports to allow you and your team to improve your code quality over time.
Analysis reports displayed within Codacy dashboard:
Prerequisites for using Codacy
- A simple Codefresh pipeline up and running
- A Codacy account (free, pro or enterprise)
- A testing tool added to your project that produces coverage reports
Codacy supports over 30 different language integrations. Depending on the programming language used, it requires little to no set-up.
Create an Account with Codacy
Codacy has a free version, a pro version, and an on-premises version. The latter two have a free trial, which allows you to test all features over the course of two weeks. You can sign-up via GitHub, Bitbucket, or GitLab.
When you log into Codacy for the first time, it will ask you to provide access to a repository. At this stage, Codacy will not download any code from your repository but merely access its names. You can then either provide access to selective repositories or your entire git account.
Generate Project API token
To use Codacy, we need a project API token. To generate the token, select your project => go to settings => integrations => add integration => select “Project API”. Make sure that you select the API token from here and not your general project settings.
In case the project that you want to use Codacy in does not have a pipeline, create a new pipeline.
This step is based on our TypeScript application. Before we are going to set-up our pipeline, we are going to add our Project API token as our environment variable. Note that we have specified our token in the variables section on the right, like displayed in the following screenshot.
Once the variable is called through the Codefresh yml syntax, it will automatically use the value provided within the variables section. If you are using this example as your pipeline, please delete anything in your pipeline. We can then add the following pipeline to our Inline YAML within the Workflow section in our UI:
The last two steps, ’tests’ and ’codacy’, are used to run our tests, create our coverage reports and forward those to Codacy. If you are using your own project and existing pipeline, add those two steps to your pipeline. In case you are using your own application, make sure to adapt the commands within the test step to run the tests of your application. Additionally, ensure that both the ’repo’ and the ’image_name’ point to your integrations.
Once you run the pipeline the steps will create the coverage report and forward it to Codacy.
This will allow you to view the updated coverage reports within Codacy’s UI every time you make a commit and/or run the Codefresh pipeline directly.
You can access further information on the coverage report by opening the file tab and accessing a specific file from your repository.