Skip to content

Improve code coverage CI with grcov HTML reports #675

Improve code coverage CI with grcov HTML reports

Improve code coverage CI with grcov HTML reports #675

Workflow file for this run

name: CI
on:
push:
branches:
- master
- 'v*.*'
pull_request:
branches:
- master
- 'v*.*'
schedule:
- cron: '0 0 * * 0'
permissions:
contents: read
pull-requests: write
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.64.0, stable, nightly]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
with:
key: test-${{ matrix.rust }}
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
- run: cargo test
- run: cargo test --features integer128
- run: cargo test --features indexmap
- run: cargo test --all-features
clippy:
name: "Clippy: stable"
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
with:
key: clippy-stable
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
with:
token: ${{ github.token }}
rustfmt:
name: "Format: stable"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
with:
key: rustfmt-stable
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustfmt
override: true
- run: cargo fmt -- --check
coverage:
name: "Coverage: stable"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
with:
key: coverage
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: llvm-tools-preview
override: true
- name: Download grcov
run: |
mkdir -p "${HOME}/.local/bin"
curl -sL https://github.com/mozilla/grcov/releases/download/v0.8.18/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf - -C "${HOME}/.local/bin"
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Generate the coverage data
run: |
cargo test --all-targets
cargo test --features integer128 --all-targets
cargo test --features indexmap --all-targets
cargo test --all-features --all-targets
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -Cinstrument-coverage
RUSTDOCFLAGS: -Cinstrument-coverage
LLVM_PROFILE_FILE: codecov-%p-%m.profraw
- name: Generate the coverage reports
run: |
grcov . -s . --binary-path ./target/debug/deps \
-t lcov -o codecov.lcov --branch \
--keep-only "src/*" \
--keep-only "tests/*" \
--ignore-not-existing \
--excl-line GRCOV_EXCL_LINE \
--excl-start GRCOV_EXCL_START \
--excl-stop GRCOV_EXCL_STOP
grcov . -s . --binary-path ./target/debug/deps \
-t covdir -o covdir.json --branch \
--keep-only "src/*" \
--keep-only "tests/*" \
--ignore-not-existing \
--excl-line GRCOV_EXCL_LINE \
--excl-start GRCOV_EXCL_START \
--excl-stop GRCOV_EXCL_STOP
grcov . -s . --binary-path ./target/debug/deps \
-t html --branch \
--keep-only "src/*" \
--keep-only "tests/*" \
--ignore-not-existing \
--excl-line GRCOV_EXCL_LINE \
--excl-start GRCOV_EXCL_START \
--excl-stop GRCOV_EXCL_STOP
rm -rf html/badges
- name: Upload the code coverage report
uses: actions/upload-artifact@v3
with:
name: coverage
path: html/
if: github.event_name == 'pull_request'
- name: Generate the coverage report summary
uses: ecliptical/[email protected]
with:
file: covdir.json
summary: 'true'
out: coverage.md
if: github.event_name == 'pull_request'
- name: Report coverage summary to the PR
uses: marocchino/sticky-pull-request-comment@v2
with:
hide_and_recreate: true
hide_classify: "OUTDATED"
path: coverage.md
if: github.event_name == 'pull_request'
- name: Summarise the code coverage
uses: romeovs/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: codecov.lcov
if: github.event_name == 'pull_request'
- name: Deploy the code coverage report
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./html
destination_dir: coverage
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'