Add missing code coverage generation flags #41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rust | |
on: [pull_request, push] | |
defaults: | |
run: | |
shell: bash | |
env: | |
CARGO_TERM_COLOR: always | |
RUSTFLAGS: '-Cinstrument-coverage' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
container: ghcr.io/nnpdf/pineappl-ci:latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set RUSTDOCFLAGS | |
run: | | |
# relative paths sometimes don't work, so use an absolute path | |
echo "RUSTDOCFLAGS=-Cinstrument-coverage -Z unstable-options --persist-doctests $(pwd)/target/debug/doctestbins" >> "$GITHUB_ENV" | |
- name: Run tests | |
run: | | |
# we need stderr, but we can't run test twice because it'll regenerate/modify the binaries which interferes with `llvm-cov` | |
cargo test --no-fail-fast 2> >(tee stderr 1>&2) | |
# from https://stackoverflow.com/a/51141872/812178 | |
sed -i 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' stderr | |
- name: Generate code coverage | |
run: | | |
find . -name '*.profraw' -exec $(rustc --print target-libdir)/../bin/llvm-profdata merge -sparse -o pineappl.profdata {} + | |
( sed -nE 's/[[:space:]]+Running( unittests|) [^[:space:]]+ \(([^)]+)\)/\2/p' stderr && echo target/debug/doctestbins/*/rust_out | tr ' ' "\n" ) | \ | |
xargs printf ' --object %s' | \ | |
xargs $(rustc --print target-libdir)/../bin/llvm-cov export \ | |
--ignore-filename-regex='/.cargo/registry' \ | |
--ignore-filename-regex='/cargo/registry' \ | |
--ignore-filename-regex='rustc' \ | |
--ignore-filename-regex='lhapdf/tests' \ | |
--instr-profile=pineappl.profdata \ | |
--skip-functions \ | |
--object target/debug/pineappl \ | |
--format lcov > lcov.info | |
- name: Upload to codecov.io | |
uses: codecov/codecov-action@v3 | |
with: | |
token: ${{secrets.CODECOV_TOKEN}} |