name: coverage

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test-and-coverage:
    runs-on: ubuntu-latest
    environment: codecov

    steps:
      - name: Checkout source code
        uses: actions/checkout@v5

      - name: Install Rust stable toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Install llvm-tools + cargo-llvm-cov
        run: |
          rustup component add llvm-tools-preview
          cargo install cargo-llvm-cov

      - name: Run tests with coverage
        run: |
          cargo llvm-cov --workspace --lcov --output-path lcov.info

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: lcov.info
          fail_ci_if_error: false
          slug: FromTheRags/rsnake
