ci: add coverage job

Uses the new llvm source-base coverage from nightly to generate coverage
reports:
- full html report as artifact
- cobertura report for gitlab MR integration
- output coverage summary for gitlab parsing

Here is the regexp to set in gitlab as "Test coverage parsing":
\s*lines\.*:\s*([\d\.]+%)

Resources:
- https://github.com/marco-c/rust-code-coverage-sample
- https://github.com/mozilla/grcov/issues/468#issuecomment-691615245
- https://www.greycastle.se/how-to-show-flutter-test-coverage-in-gitlab-ci/
This commit is contained in:
Guillaume Desmottes 2021-01-11 16:26:57 +01:00 committed by Sebastian Dröge
parent 70d3eecbc5
commit b92360db37

View file

@ -216,3 +216,28 @@ outdated:
- if: '$CI_PIPELINE_SOURCE == "schedule"' - if: '$CI_PIPELINE_SOURCE == "schedule"'
script: script:
- cargo outdated --root-deps-only --exit-code 1 -v - cargo outdated --root-deps-only --exit-code 1 -v
coverage:
extends:
- .img-nightly
stage: 'extras'
rules:
- when: 'always'
variables:
RUSTFLAGS: "-Zinstrument-coverage"
LLVM_PROFILE_FILE: "gst-plugins-rs-%p-%m.profraw"
script:
- cargo test --locked --color=always --all-features
# generate html report
- grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing --ignore "*target*" -o ./coverage/
# generate cobertura report for gitlab integration
- grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "*target*" -o lcov
- python3 /usr/local/lib/python3.7/dist-packages/lcov_cobertura.py lcov
# output coverage summary for gitlab parsing
- lcov -r lcov "/*" 2&> out
- grep lines out
artifacts:
paths:
- 'coverage'
reports:
cobertura: coverage.xml