Terminal
Terminal/Skill
Adds test coverage generation and Codacy upload steps to a repository's CI config, for the languages and frameworks it detects.
By Codacy
Works with
npx skills add codacy/codacy-skills --skill setup-coverageGlossary: See glossary.md for shared definitions of Codacy concepts (issues, findings, severity, coverage, tools, patterns, etc.).
This skill sets up test coverage reporting in a repository and configures automatic upload to Codacy. It detects what exists, identifies what is missing, and fills the gaps.
CODACY_PROJECT_TOKEN or CODACY_API_TOKEN must be available for coverage uploads (see Authentication)Coverage Setup Progress:
- [ ] Step 1: Detect testing setup
- [ ] Step 2: Detect CI/CD pipeline
- [ ] Step 3: Identify coverage gaps
- [ ] Step 4: Add coverage generation
- [ ] Step 5: Add Codacy coverage upload
- [ ] Step 6: Verify the setup
Scan the repository to identify:
createDebugCoverageReportgo testcollectCoverage, pytest.ini coverage settings, JaCoCo plugin in pom.xml/build.gradle, etc.)coverage/, lcov.info, cobertura.xml, jacoco*.xml, etc.)Report findings to the user before proceeding.
Identify which CI/CD system is in use:
| CI/CD | Detection files |
|---|---|
| GitHub Actions | .github/workflows/*.yml |
| GitLab CI | .gitlab-ci.yml |
| CircleCI | .circleci/config.yml |
| Travis CI | .travis.yml |
| Bitbucket Pipelines | bitbucket-pipelines.yml |
| Jenkins | Jenkinsfile |
| Azure DevOps | azure-pipelines.yml |
Read the CI config to understand:
Based on steps 1 and 2, determine what is missing:
Present the gap analysis to the user and confirm the plan before making changes.
Add the minimal configuration to generate coverage reports in a format Codacy supports. Choose the format based on the language and tooling. See references/coverage-formats.md for the full format reference.
JavaScript/TypeScript (Jest):
// In package.json or jest.config.js
{
"collectCoverage": true,
"coverageReporters": ["lcov"]
}
Or run: npx jest --coverage --coverageReporters=lcov
JavaScript/TypeScript (Vitest):
// vitest.config.ts
{ test: { coverage: { reporter: ['lcov'] } } }
Python (pytest + coverage.py):
pip install pytest-cov
pytest --cov --cov-report=xml:cobertura.xml
Java (Maven + JaCoCo):
Add the JaCoCo Maven plugin to pom.xml:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<goals><goal>prepare-agent</goal></goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals><goal>report</goal></goals>
</execution>
</executions>
</plugin>
Java (Gradle + JaCoCo):
plugins { id 'jacoco' }
jacocoTestReport { dependsOn test }
Run: ./gradlew test jacocoTestReport
Kotlin (Gradle + JaCoCo):
plugins { id 'jacoco' }
jacocoTestReport {
dependsOn test
reports { xml.required = true }
}
Run: ./gradlew test jacocoTestReport
Report location: build/reports/jacoco/test/jacocoTestReport.xml
Kotlin (Maven + JaCoCo): Same as Java Maven + JaCoCo setup above — JaCoCo supports Kotlin bytecode natively.
Android (Gradle + JaCoCo):
android {
buildTypes {
debug { testCoverageEnabled true }
}
}
Run: ./gradlew createDebugCoverageReport
Report location: app/build/reports/coverage/debug/report.xml
For multi-module Android projects, use a merged report or partial uploads (see references/coverage-upload.md).
Go:
go test -coverprofile=coverage.out ./...
Ruby (SimpleCov):
# At the top of spec/spec_helper.rb or test/test_helper.rb
require 'simplecov'
SimpleCov.start
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
Requires simplecov and simplecov-cobertura gems.
C#/.NET (Coverlet):
dotnet test --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura
Scala (sbt-jacoco):
Add to project/plugins.sbt:
addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.5.0")
Run: sbt jacoco
PHP (PHPUnit):
phpunit --coverage-clover clover.xml
Add a coverage upload step to the CI/CD pipeline after the test/coverage step.
The upload requires one of:
Option A — Repository token (single repo, simpler):
CODACY_PROJECT_TOKEN as a CI/CD secretOption B — Account token (multiple repos):
CODACY_API_TOKEN — from Codacy > My Account > Access ManagementCODACY_ORGANIZATION_PROVIDER — gh, gl, or bbCODACY_USERNAME — organization or usernameCODACY_PROJECT_NAME — repository nameAlways remind the user to add the appropriate token as a CI/CD secret.
The standard upload command:
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r <coverage-report-file>
For Go coverage, add the parser flag:
bash <(curl -Ls https://coverage.codacy.com/get.sh) report \
--force-coverage-parser go -r coverage.out
For multiple reports (e.g., monorepos or multi-module projects):
bash <(curl -Ls https://coverage.codacy.com/get.sh) report \
-r report1.xml -r report2.xml
Or use partial uploads:
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial -r report1.xml
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial -r report2.xml
bash <(curl -Ls https://coverage.codacy.com/get.sh) final
GitHub Actions:
- name: Upload coverage to Codacy
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r <report-file>
Or use the official action:
- name: Upload coverage to Codacy
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: <report-file>
GitLab CI:
upload-coverage:
stage: test
script:
- bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r <report-file>
variables:
CODACY_PROJECT_TOKEN: $CODACY_PROJECT_TOKEN
CircleCI (using orb):
orbs:
codacy: codacy/coverage-reporter@13
workflows:
main:
jobs:
- test
- codacy/upload_coverage:
requires: [test]
Travis CI:
after_success:
- bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r <report-file>
Bitbucket Pipelines:
- step:
name: Upload coverage
script:
- bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r <report-file>
Alpine Linux (no bash):
wget -qO - https://coverage.codacy.com/get.sh | sh -s -- report -r <report-file>
See references/coverage-upload.md for advanced upload scenarios.
After making changes:
CODACY_PROJECT_TOKEN (or account token variables) as a CI/CD secretAfter pushing, verify:
- [ ] CI pipeline passes (tests run, coverage report generated)
- [ ] Coverage upload step succeeds (no errors in CI logs)
- [ ] Codacy shows coverage data for the commit
Common issues and their solutions:
| Status | Cause | Fix |
|---|---|---|
| Commit Not Found | Webhook not received or wrong commit SHA | Wait 5-10 min; verify the commit SHA matches |
| Pending | File paths in report don't match repo structure | Ensure paths are relative to repo root (e.g., src/index.js, not /home/ci/project/src/index.js) |
| Final Report Not Sent | Used --partial without final | Add bash <(curl -Ls https://coverage.codacy.com/get.sh) final after all partial uploads |
| Branch Not Enabled | Coverage uploaded for unanalyzed branch | Enable the branch in Codacy repository settings |
| No coverage shown on PRs | Missing coverage for common ancestor commit | Ensure coverage runs on all branches, not just PRs |
-l <Language> flags or partial uploads with language specification