Skip to content

Commit

Permalink
ci: Use codecov for coverage reports (#632)
Browse files Browse the repository at this point in the history
The slack reporting can be added later with codecov's slack app
  • Loading branch information
aborgna-q committed Oct 31, 2023
1 parent cb4bf6a commit fd30ae7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,29 @@ jobs:
- name: Tests with no features
run: cargo test --verbose --no-default-features
- name: Tests with all features
run: cargo test --verbose --all-features
run: cargo test --verbose --all-features

coverage:
if: github.event_name != 'merge_group'
needs: [tests, check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mozilla-actions/sccache-action@v0.0.3
- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run tests with coverage instrumentation
run: |
cargo llvm-cov clean --workspace
cargo llvm-cov --doctests
- name: Generate coverage report
run: cargo llvm-cov report --codecov --output-path coverage.json
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
with:
files: coverage.json
name: ubuntu
token: ${{ secrets.CODECOV_TOKEN }}
32 changes: 14 additions & 18 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
schedule:
# 04:00 daily
- cron: '0 4 * * *'
workflow_dispatch: {}

jobs:
check-coverage:
Expand All @@ -12,12 +13,12 @@ jobs:
msg: ${{ steps.make_msg.outputs.msg }}
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install llvm
uses: KyleMayes/install-llvm-action@v1
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@nightly
with:
version: "16.0" # should match version used by rustc
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Download previous summary
uses: dawidd6/action-download-artifact@v2
with:
Expand All @@ -26,19 +27,13 @@ jobs:
name: coverage-summary
- name: Rename file
run: mv coverage-summary.txt coverage-summary-prev.txt
- name: Run tests with coverage instrumentation
run: |
cargo llvm-cov clean --workspace
cargo llvm-cov --doctests
- name: Generate coverage report and summary
env:
RUSTFLAGS: "-C instrument-coverage"
run: |
TGT=`cargo test --tests 2>&1 | grep Running | awk -F'[()]' '{print $2}'`
llvm-profdata merge -sparse default_*.profraw -o hugr.profdata
llvm-cov show --format=html --ignore-filename-regex='/.cargo/registry' --instr-profile=hugr.profdata --output-dir coverage --object ${TGT}
llvm-cov report --ignore-filename-regex='/.cargo/registry' --instr-profile=hugr.profdata --object ${TGT} | grep TOTAL | awk '{print $10}' | tr -dc '[:digit:].' > coverage-summary.txt
- name: Upload full report
uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage/
cargo llvm-cov report --summary-only | grep TOTAL | awk '{print $10}' | tr -dc '[:digit:].' > coverage-summary.txt
- name: Upload summary
uses: actions/upload-artifact@v3
with:
Expand All @@ -48,11 +43,12 @@ jobs:
id: make_msg
run: |
change="`cat coverage-summary-prev.txt`% --> `cat coverage-summary.txt`%"
codecov="https://codecov.io/gh/${{ github.repository }}?search=&trend=7%20days"
if (( $(echo "`cat coverage-summary-prev.txt` < `cat coverage-summary.txt` + 0.04" | bc -l) ))
then
echo "msg=Coverage check for hugr shows no regression (${change}). ✅ ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> "$GITHUB_OUTPUT"
echo "msg=Coverage check for hugr shows no regression (${change}). ✅ ${codecov}" >> "$GITHUB_OUTPUT"
else
echo "msg=Coverage check for hugr shows regression (${change}). ❌ ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> "$GITHUB_OUTPUT"
echo "msg=Coverage check for hugr shows regression (${change}). ❌ ${codecov}" >> "$GITHUB_OUTPUT"
fi
notify-slack:
needs: check-coverage
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ quantinuum-hugr

[![build_status][]](https://github.com/CQCL/hugr/actions)
[![msrv][]](https://github.com/CQCL/hugr)
[![codecov][]](https://codecov.io/gh/CQCL/hugr)

The Hierarchical Unified Graph Representation (HUGR, pronounced _hugger_) is the
common representation of quantum circuits and operations in the Quantinuum
Expand Down Expand Up @@ -38,4 +39,5 @@ This project is licensed under Apache License, Version 2.0 ([LICENSE][] or http:

[build_status]: https://github.com/CQCL/hugr/workflows/Continuous%20integration/badge.svg?branch=main
[msrv]: https://img.shields.io/badge/rust-1.70.0%2B-blue.svg
[codecov]: https://img.shields.io/codecov/c/gh/CQCL/hugr?logo=codecov
[LICENSE]: LICENCE

0 comments on commit fd30ae7

Please sign in to comment.