From b92360db374ae70e3b031b9e520722c41e401b40 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 11 Jan 2021 16:26:57 +0100 Subject: [PATCH] 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/ --- .gitlab-ci.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7fe0c732..9467ffc3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -216,3 +216,28 @@ outdated: - if: '$CI_PIPELINE_SOURCE == "schedule"' script: - 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