on:
  push:
    branches: [ main, auto, canary ]
  pull_request:
    branches:
      - main

name: Test coverage
env:
  CARGO_TERM_COLOR: always


jobs:
  coverage:
    name: Collect test coverage
    runs-on: ubuntu-latest
    # nightly rust might break from time to time
    continue-on-error: true
    env:
      RUSTFLAGS: -D warnings
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview
      - uses: Swatinem/rust-cache@v2

      - name: Install latest nextest release
        uses: taiki-e/install-action@nextest
      - name: Install cargo-llvm-cov
        uses: taiki-e/install-action@cargo-llvm-cov
      - name: Update Cargo.lock
        run: cargo update
      - name: Collect coverage data
        run: cargo llvm-cov nextest --all-features --lcov --output-path lcov.info
      - name: Upload coverage data to codecov
        uses: codecov/codecov-action@v3
        with:
          files: lcov.info
