diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 81b1763..3e11d3c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -265,3 +265,45 @@ jobs: run: cargo miri test --no-fail-fast --all-features env: MIRIFLAGS: -Zmiri-disable-isolation + + coverage: + if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository + + name: Code coverage + runs-on: ubuntu-latest + needs: ["check"] + permissions: + contents: read + id-token: write + steps: + - name: Checkout source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master + with: + # doctest coverage requires nightly + toolchain: nightly + components: llvm-tools-preview + + - name: Cache Cargo registry + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + shared-key: 'rust-ci' + cache-bin: 'false' + save-if: 'false' + + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@8cca0918f8471c33515202b73f56ab27f2bed283 # v2.87.29 + with: + tool: cargo-llvm-cov + + - name: Generate code coverage + run: cargo llvm-cov --all-features --doctests --lcov --output-path lcov.info + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6.0.2 + with: + use_oidc: ${{ !github.event.pull_request.head.repo.fork }} + files: lcov.info + fail_ci_if_error: true diff --git a/README.md b/README.md index 38f4785..b205d94 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Rust CI](https://github.com/google/dtoolkit/actions/workflows/rust.yml/badge.svg)](https://github.com/google/dtoolkit/actions/workflows/rust.yml) [![crates.io](https://img.shields.io/crates/v/dtoolkit.svg)](https://crates.io/crates/dtoolkit) [![Documentation](https://docs.rs/dtoolkit/badge.svg)](https://docs.rs/dtoolkit) +[![codecov](https://codecov.io/gh/google/dtoolkit/graph/badge.svg)](https://codecov.io/gh/google/dtoolkit) A library for parsing and manipulating Flattened Device Tree (FDT) blobs.