name: Coverage
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
coverage:
name: Code coverage
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-tarpaulin
uses: taiki-e/install-action@cargo-tarpaulin
- name: Run coverage (all features)
run: |
cargo tarpaulin \
--all-features \
--out Json Lcov \
--output-dir coverage/ \
--timeout 120 \
--exclude-files "argot-cmd-derive/*" \
--exclude-files "examples/*"
- name: Check coverage threshold
run: |
python3 - <<'EOF'
import json, sys
with open("coverage/tarpaulin-report.json") as f:
data = json.load(f)
pct = float(data.get("coverage", 0))
print(f"Coverage: {pct:.1f}%")
if pct < 75:
print(f"ERROR: coverage {pct:.1f}% is below the 75% threshold", file=sys.stderr)
sys.exit(1)
EOF
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}