Skip to content

Commit

Permalink
Refactor coverage CI workflow (#9361)
Browse files Browse the repository at this point in the history
This relaxes the constraint on `coverage` added in #9305.  The issue
there is actually the now unmaintained `coveragepy-lcov` package is not
compatible with Coverage.py 7.0.  However, we only needed
`coveragepy-lcov` to convert Coverage's format into LCOV, which is a
feature Coverage has had itself since version 6.0.

This commit also updates some parts of the coverage workflow that were
old:

- there are new versions of the Actions `checkout` and `setup-python`,
  which swap to using Node 16 rather than Node 12, which is deprecated
  in GHA
- `grcov` is packaged and installable from `cargo` now, rather than
  needing a manual hard-coded pull from GitHub
- we can have `grcov` only keep the parts we care about immediately,
  rather than converting everything and later discarding it

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jakelishman and mergify[bot] authored Jan 11, 2023
1 parent fef0600 commit 7955d92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,54 @@ jobs:
name: Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: default
components: llvm-tools-preview

- name: Install dependencies
run: |
pip install coveragepy-lcov
cargo install grcov
sudo apt-get install lcov
- name: Download grcov for rust coverage
run: curl -L https://github.com/mozilla/grcov/releases/download/v0.8.11/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar xj
- name: Build and install qiskit-terra
run: pip install -e .
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "qiskit-%p-%m.profraw"
SETUPTOOLS_ENABLE_FEATURES: "legacy-editable"

- name: Generate unittest coverage report
run: |
set -e
pip install -r requirements-dev.txt qiskit-aer
stestr run
./grcov . --binary-path ./target/debug/ -s . --llvm --parallel -t lcov --branch --ignore-not-existing --ignore "/*" -o ./rust_unittest.info
rm *profraw
# We set the --source-dir to '.' because we want all paths to appear relative to the repo
# root (we need to combine them with the Python ones), but we only care about `grcov`
# keeping the `src/*` files; we don't care about coverage in dependencies.
grcov . --binary-path target/debug/ --source-dir . --output-type lcov --output-path rust.info --llvm --branch --parallel --keep-only 'src/*'
env:
QISKIT_TEST_CAPTURE_STREAMS: 1
QISKIT_PARALLEL: FALSE
PYTHON: "coverage3 run --source qiskit --parallel-mode"
PYTHON: "coverage run --source qiskit --parallel-mode"

- name: Convert to lcov and combine data
run: |
set -e
coverage3 combine
coveragepy-lcov --output_file_path python.info
lcov --add-tracefile python.info -a rust_unittest.info -o combined.info
lcov --remove combined.info "target/*" -o coveralls.info
coverage combine
coverage lcov -o python.info
lcov --add-tracefile python.info --add-tracefile rust.info --output-file coveralls.info
- name: Coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
5 changes: 0 additions & 5 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,3 @@ jupyter-core==4.11.2
# ipywidgets 8.0.3 started emitting deprecation warnings via a seaborn import.
# This pin can be removed when compatibility with those packages is fixed.
ipywidgets<8.0.3

# coverage 7.0.0 breaks with Python 3.8.15 upon the import
# from coverage.files import FnmatchMatcher
# since this is in Python 3.8 itself and not Qiskit, pinning this for now.
coverage<7.0

0 comments on commit 7955d92

Please sign in to comment.