Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document GitLab CI integration #405

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This is a wrapper around rustc [`-C instrument-coverage`][instrument-coverage] a
- [Exclude file from coverage](#exclude-file-from-coverage)
- [Exclude code from coverage](#exclude-code-from-coverage)
- [Continuous Integration](#continuous-integration)
- [GitHub Actions and Codecov](#github-actions-and-codecov)
- [GitLab CI](#gitlab-ci)
- [Display coverage in VS Code](#display-coverage-in-vs-code)
- [Environment variables](#environment-variables)
- [Additional JSON information](#additional-json-information)
Expand Down Expand Up @@ -535,6 +537,8 @@ cargo-llvm-cov excludes code contained in the directory named `tests` from the r

### Continuous Integration

#### GitHub Actions and Codecov

Here is an example of GitHub Actions workflow that uploads coverage to [Codecov].

```yaml
Expand Down Expand Up @@ -580,6 +584,40 @@ By using `--codecov` flag instead of `--lcov` flag, you can use region coverage

Note that [the way Codecov shows region/branch coverage is not very good](https://github.com/taiki-e/cargo-llvm-cov/pull/255#issuecomment-1513318191).

#### GitLab CI

First of all, when running the CI you need to make sure `cargo-llvm-cov` is available
in the execution script. Whether you add it to a custom image, or run `cargo install` as part
of your pipeline, it should be available and in `PATH`. Once done, it's simple:

```yaml
unit_tests:
artifacts:
reports:
junit: target/nextest/default/junit.xml
coverage_report:
coverage_format: cobertura
path: target/llvm-cov-target/cobertura.xml
# this uses region for coverage summary
coverage: '/TOTAL\s+(\d+\s+)+(\d+\.\d+\%)/'
script:
- cargo llvm-cov nextest
- cargo llvm-cov report --cobertura --output-path target/llvm-cov-target/cobertura.xml
```

> [!CAUTION]
> GitLab has certain [limits for Cobertura reports](https://docs.gitlab.com/ee/ci/testing/test_coverage_visualization/cobertura.html#limits)
> make sure you obey them.

> [!NOTE]
> Note that this example uses [`cargo-nextest`](https://nexte.st/) to run the tests (which must
> similarly be available), with the following `.config/nextest.toml`:
>
> ```toml
> [profile.default.junit]
> path = "junit.xml"
> ```

### Display coverage in VS Code

You can display coverage in VS Code using [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters).
Expand Down
Loading