diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..ad750a0 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,53 @@ +name: Code Coverage + +on: + push: + branches: [main, dev] + pull_request: + branches: [main, dev] + +env: + CARGO_TERM_COLOR: always + +jobs: + coverage: + runs-on: ubuntu-latest + name: Generate Coverage Report + steps: + - uses: actions/checkout@v5 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + + - name: Install cargo-tarpaulin + run: cargo install cargo-tarpaulin + + - name: Generate coverage report + run: | + cargo tarpaulin \ + --workspace \ + --out Xml \ + --output-dir coverage \ + --timeout 300 \ + --exclude-files "tests/*" \ + --ignore-panics + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage/cobertura.xml + flags: rust + name: coverage-report + fail_ci_if_error: false + verbose: true + + - name: Archive coverage report + if: always() + uses: actions/upload-artifact@v5 + with: + name: coverage-report + path: coverage/ diff --git a/.tarpaulin.toml b/.tarpaulin.toml new file mode 100644 index 0000000..30a15fb --- /dev/null +++ b/.tarpaulin.toml @@ -0,0 +1,4 @@ +[coverage] +timeout = 300 +ignore-panics = true +exclude-files = ["tests/*", "benches/*"] diff --git a/README.md b/README.md index 06a3ce0..5decf97 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ![WebARKitLib-rs](./assets/WebARKitLib-Rust-banner.jpg) [![CI](https://github.com/webarkit/WebARKitLib-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/webarkit/WebARKitLib-rs/actions/workflows/ci.yml) +[![codecov](https://codecov.io/gh/webarkit/WebARKitLib-rs/branch/main/graph/badge.svg)](https://codecov.io/gh/webarkit/WebARKitLib-rs) [![Crates.io](https://img.shields.io/crates/v/webarkitlib-rs.svg)](https://crates.io/crates/webarkitlib-rs) [![npm](https://img.shields.io/npm/v/@webarkit/webarkitlib-wasm.svg)](https://www.npmjs.com/package/@webarkit/webarkitlib-wasm) [![GitHub stars](https://img.shields.io/github/stars/webarkit/WebARKitLib-rs.svg?style=social)](https://github.com/webarkit/WebARKitLib-rs/stargazers) @@ -263,6 +264,36 @@ Because it's the `log` crate facade, any compatible backend works: No library code change is needed โ€” pick the backend in your application's entry point. +## ๐Ÿ“ˆ Code Coverage + +Coverage reports are generated automatically on every push and pull request via the [coverage workflow](.github/workflows/coverage.yml) using [cargo-tarpaulin](https://github.com/xd009642/tarpaulin) and uploaded to [Codecov](https://codecov.io/gh/webarkit/WebARKitLib-rs). + +### Generate a Coverage Report Locally + +```bash +# Install tarpaulin (once) +cargo install cargo-tarpaulin + +# Run the helper script โ€” produces coverage/index.html +./scripts/coverage.sh +``` + +Or run tarpaulin directly: + +```bash +cargo tarpaulin --workspace --out Html --output-dir coverage --timeout 300 +``` + +### Coverage Targets + +| Area | Target | +|------|--------| +| Minimum overall | 75 % | +| Desirable overall | 85 %+ | +| Marker tracking (critical path) | 95 %+ | + +--- + ## ๐Ÿ“Š Benchmarking We maintain a strict performance comparison with the original C library to ensure our Rust port remains competitive. diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100755 index 0000000..0ca6ed9 --- /dev/null +++ b/scripts/coverage.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# coverage.sh โ€” Generate a local HTML code coverage report using cargo-tarpaulin. +# +# Usage: +# ./scripts/coverage.sh +# +# Requires cargo-tarpaulin to be installed: +# cargo install cargo-tarpaulin +set -e + +echo "๐Ÿงช Generating Code Coverage Report..." +echo "" + +# Clean previous coverage output +rm -rf coverage/ +mkdir -p coverage/ + +echo "Using Tarpaulin for coverage..." +cargo tarpaulin \ + --workspace \ + --out Html \ + --output-dir coverage \ + --timeout 300 \ + --exclude-files "tests/*" \ + --ignore-panics \ + --verbose + +echo "" +echo "โœ… Coverage report generated!" +echo "" +echo "๐Ÿ“Š Open the report:" +if command -v open &> /dev/null; then + open coverage/index.html # macOS +elif command -v xdg-open &> /dev/null; then + xdg-open coverage/index.html # Linux +else + echo " $(pwd)/coverage/index.html" +fi