diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml new file mode 100644 index 0000000..9d56747 --- /dev/null +++ b/.github/workflows/code_coverage.yml @@ -0,0 +1,49 @@ +name: Code Coverage + +on: [push, pull_request] + +permissions: + contents: read + pull-requests: write + +jobs: + Coverage: + name: Code Coverage + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + persist-credentials: false + - name: Install Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: nightly-2026-04-09 + override: true + cache: true + components: llvm-tools-preview + - name: Install cargo-llvm-cov + run: if [[ ! -e ~/.cargo/bin/cargo-llvm-cov ]]; then cargo install cargo-llvm-cov; fi + - name: Make coverage directory + run: mkdir coverage + - name: Test and export lcov coverage + run: cargo llvm-cov -q --branch --all --ignore-filename-regex "(examples/|tests/)" --all-features --lcov --output-path ./coverage/lcov.info + env: + RUSTFLAGS: "--cfg coverage_nightly" + - name: Generate HTML coverage report + run: cargo llvm-cov -q --branch --all --ignore-filename-regex "(examples/|tests/)" --all-features --html + env: + RUSTFLAGS: "--cfg coverage_nightly" + - name: Codecov upload + uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 + with: + files: ./coverage/lcov.info + flags: rust + name: codecov-bdk-tx + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: coverage-report + path: target/llvm-cov/html diff --git a/Cargo.toml b/Cargo.toml index 6016fde..8693aaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,9 @@ description = "Bitcoin transaction building library." license = "MIT OR Apache-2.0" readme = "README.md" +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] } + [dependencies] miniscript = { version = "12.3.5", default-features = false } bdk_coin_select = "0.4.0" diff --git a/src/finalizer.rs b/src/finalizer.rs index 2e05e7c..cffa850 100644 --- a/src/finalizer.rs +++ b/src/finalizer.rs @@ -162,6 +162,7 @@ impl FinalizeMap { } } +#[cfg_attr(coverage_nightly, coverage(off))] #[cfg(test)] mod tests { use crate::{Finalizer, Output, PsbtParams, Selection, Signer}; diff --git a/src/lib.rs b/src/lib.rs index 2699fc3..46866f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ //! `bdk_tx` +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] #![warn(missing_docs)] #![no_std] diff --git a/src/selection.rs b/src/selection.rs index 1010a86..4169a9c 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -316,6 +316,7 @@ impl Selection { } } +#[cfg_attr(coverage_nightly, coverage(off))] #[cfg(test)] mod tests { use super::*; diff --git a/src/signer.rs b/src/signer.rs index f28aefe..d0866c3 100644 --- a/src/signer.rs +++ b/src/signer.rs @@ -66,6 +66,7 @@ impl GetKey for Signer { } } +#[cfg_attr(coverage_nightly, coverage(off))] #[cfg(test)] mod test { use crate::bitcoin::bip32::ChildNumber;