CI Integration / Uploader
Integrating code coverage reporting into your CI pipeline ensures that coverage data is consistently collected and reported for every build.
Qlty is compatible with every major CI provider.
Qlty offers CI-specific packages for GitHub Actions (GitHub Action) and CircleCI (CircleCI Orb), but works just as well without them.
Qlty provides environment detection for most CI providers, making integration simpler, but offers simple instructions for those without it.
CI Provider Integration
GitHub Actions
Integrate with Qlty using our GitHub Action.
While integration can be done without our GitHub Action, using it allows you to take advantage of OIDC support.
CircleCI
Qlty offers a CircleCI Orb for easy integration.
Travis CI
Add Qlty coverage reporting to your .travis.yml
:
Make sure to add your QLTY_COVERAGE_TOKEN
in the Travis CI repository settings.
GitLab CI
Add coverage reporting to your .gitlab-ci.yml
:
Add your QLTY_COVERAGE_TOKEN
as a CI/CD variable in your GitLab project settings.
Buildkite
Export your QLTY_COVERAGE_TOKEN as an environment variable. (See Buildkite’s documentation on managing secrets.
One option is to export QLTY_COVERAGE_TOKEN
in an environment agent hook):
Then update your pipeline.yaml appropriately. Here’s an example with Ruby test coverage:
Other CI Providers
As long as your CI environment meets the system requirements to install the Qlt CLI, you can publish coverage.
Publishing coverage on any CI provider follows the same procedure:
- Ensure a
QLTY_COVERAGE_TOKEN
is available in the environment - Install the Qlty CLI
- Execute
qlty coverage publish
command with the correct arguments
For example:
The Qlty CLI coverage commands leverage as much information from its environment as possible to ease integration. This includes environment variables as well as git metadata from the current working directory. However, sometimes, such as when attempting to publish coverage from a CI provider not listed above, Qlty is unable to detect this information from its environment. In these cases, you will need to provide the missing metadata to qlty coverage publish
as additional arguments. Because usually no more than 2 - 4 arguments are needed, we recommend a trial and error process, following the instructions provided by the command when it errors.
Below are some common scenarios you may run into.
Path Validation Failures
qlty coverage publish
validates that the source files specified in your coverage data files match the source files in your repository. This ensures that we’re able to properly associate coverage with your source files in Qlty Cloud.
If we’re unable to validate that a majority (up to a configurable threshold) of the source files referenced exist in your repository, qlty coverage publish
will error.
Usually these validate failures this can be addressed with the --add-prefix
and/or --strip-prefix
arguments. See Path Fixing for more information.
Commit SHA Missing
A commit sha is always required when sending coverage data to Qlty.sh. The commit sha can be manually specified with:
--override-commit-sha <COMMIT_SHA>
Reference Missing
When publishing coverage, Qlty associates the coverage data with a single reference. The reference can be one of:
- a branch
- a pull request
- a git tag
If not inferred, provide one of the following:
- pull request:
--override-pr-number <PR_NUMBER>
- branch:
--override-branch <BRANCH_NAME>
(can be used alongside--override-pr-number
) - git tag:
--override-git-tag <TAG_NAME>
(cannot be combined with either--override-pr-number
or--override-branch
)
Commit Time Missing
A timestamp associated with the commit is also required. This can be specified with:
--override-commit-time <OVERRIDE_COMMIT_TIME>
The commit time can be a Unix timestamp (seconds since epoch) or a date in RFC3339/ISO8601 format.
Examples
Advanced CI Configuration
Parallelized Tests
When running tests in parallel, you’ll need to merge the coverage reports before uploading. Qlty supports both client-side and server-side merging.
Client-side Merging
Collect all coverage reports into a single location and upload them together:
Server-side Merging
Upload each part separately and specify the total number of parts:
Learn more about Coverage Merging.
Multiple Test Suites
If you have different types of tests (unit, integration, e2e), you can track them separately using coverage tags:
Learn more about Coverage Tags.
Environment Detection
What is environment detection?
Environment detection is Qlty CLI’s ability to infer, without user input, metadata about your build from CI provider-specific environment variables. For example, CircleCI exposes the commit being built in an environment variable CIRCLE_SHA1
.
Without specific environment detection, you can still use our coverage publisher with a few extra command line arguments. See our documentation below on Other CI Providers.
Adding Environment Detection
If you want automatic environment detection:
- Double check our Qlty repository for the most up to date list of supported CI providers.
- Our coverage publisher is open source and you can add support by following the other provider examples in under an hour. (Provide an LLM with the other examples and a link to your CI provider’s list of available environment variables)
Troubleshooting
Common Issues
- Authentication failures: Check that your token is correctly set as an environment variable
- Report format not recognized: Make sure you’re using a supported coverage format
- Path mismatches: Use the
--strip-prefix
and--add-prefix
options to fix file paths - Missing metadata: Use
--override-branch
,--override-commit
and--override-build-id
if CI detection fails
See Also
- Coverage Merging - Combine multiple coverage reports
- Coverage Tags - Track different test suites separately