on:
  pull_request:
  push:
    branches:
      - main

name: Test with Code Coverage

jobs:
  coverage:
    name: Test Coverage
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          override: true
          components: llvm-tools-preview
      - name: cargo install cargo-llvm-cov
        uses: taiki-e/install-action@cargo-llvm-cov
      - name: cargo llvm-cov
        uses: actions-rs/cargo@v1
        with:
          command: llvm-cov
          args: --all-features --lcov --output-path lcov.info
        env:
          TRYBUILD: overwrite

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v4.0.1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: true
