# Copyright 2026 H0llyW00dzZ
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: 🧪 Test Coverage

on:
  push:
    branches: [ master ]
    paths-ignore:
      - '**/*.md'
      - 'LICENSE'
      - '.gitignore'
      - '.ignore'
      - '.github/dependabot.yml'
  pull_request:
    branches: [ master ]
    paths-ignore:
      - '**/*.md'
      - 'LICENSE'
      - '.gitignore'
      - '.ignore'
      - '.github/dependabot.yml'

jobs:
  coverage:
    name: 🔢 Test Coverage on ${{ matrix.os }} (Rust ${{ matrix.rust }})
    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.rust == 'nightly' }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, ubuntu-22.04, ubuntu-24.04-arm, ubuntu-22.04-arm, macos-latest, windows-latest, windows-2022, windows-11-arm]
        rust: [stable, beta, nightly, '1.70']

    steps:
    - name: Checkout code
      uses: actions/checkout@v6

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@master
      with:
        toolchain: ${{ matrix.rust }}
        components: llvm-tools-preview

    - name: Cache cargo registry and build artifacts
      uses: Swatinem/rust-cache@v2

    - name: Install cargo-llvm-cov
      uses: taiki-e/install-action@v2
      with:
        tool: cargo-llvm-cov
      if: ${{ matrix.os != 'windows-11-arm' && matrix.rust != '1.70' }}

    - name: Run tests with coverage
      if: ${{ matrix.os != 'windows-11-arm' && matrix.rust != '1.70' }}
      run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info

    - name: Run tests (no coverage on windows-11-arm)
      if: ${{ matrix.os == 'windows-11-arm' && matrix.rust != '1.70' }}
      run: cargo test --all-features

    # MSRV check: only verify the library itself compiles on 1.70.
    # `cargo build` does NOT resolve dev-dependencies, so newer dev-deps
    # (e.g. criterion's transitive clap_builder) cannot affect this job.
    - name: MSRV build check
      if: ${{ matrix.rust == '1.70' }}
      run: cargo build --all-features --verbose

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v6
      if: ${{ matrix.os == 'ubuntu-latest' && matrix.rust == 'stable' }}
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      with:
        files: ./lcov.info
        flags: unittests
        name: codecov-umbrella
