---
name: Test Coverage

permissions: {}

on:
  push:
    branches:
      - master
    paths:
      - .github/workflows/codecov.yml
      - src/**/*.rs
      - tests/**/*.rs
  pull_request:
    branches:
      - master
    paths:
      - .github/workflows/codecov.yml
      - src/**/*.rs
      - tests/**/*.rs

concurrency:
  group: ${{ github.workflow }}-${{ github.ref || github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  coverage:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: dtolnay/rust-toolchain@nightly
        with:
          components: llvm-tools-preview
      - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
      - uses: taiki-e/install-action@65851e10cd6c377f11a60e600abc07cb08643468 # v2.79.3
        with:
          tool: cargo-tarpaulin
      - name: Run instrumented tests
        run: cargo tarpaulin --all-targets --skip-clean --out xml
        env:
          RUST_LOG: cargo_tarpaulin=error
      - name: Upload codecov
        uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
        with:
          fail_ci_if_error: true
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
