name: Coverage

on:
  push:
    branches: [master]

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
        with:
          components: llvm-tools-preview

      - name: Install cargo-llvm-cov
        uses: taiki-e/install-action@v2.13.4
        with:
          tool: cargo-llvm-cov

      - name: Generate code coverage
        run: cargo llvm-cov --workspace --all-features --codecov --output-path codecov.json

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v3.1.4
        with:
          files: codecov.json
          fail_ci_if_error: true