name: Coverage

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

jobs:
  code-coverage:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.13"]
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Debug file and directory state
        run: |
          echo "Debugging file and directory state..."
          ls -la
          echo "Environment state..."
          env
          echo "Git status..."
          git status

      - name: Install the latest version of uv
        uses: astral-sh/setup-uv@v3
        with:
          version: "latest"

      - name: Print the installed uv version
        run: echo "Installed uv version is ${{ steps.setup-uv.outputs.uv-version }}"

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install dependencies with uv
        run: |
          uv venv .venv
          uv sync

      - name: Create coverage directory
        run: |
          mkdir -p coverage
          ls -la coverage

      - name: Run tests with coverage
        run: |
          uv run pytest --cov=src/samplics --cov-report=xml:coverage/coverage.xml --cov-report=term -v tests
          ls -la coverage

      - name: Verify coverage report exists
        run: |
          ls -lh coverage/coverage.xml || echo "⚠️ Warning: coverage.xml not found!"
          ls -la coverage

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ./coverage/coverage.xml
          flags: unittests
          env_vars: OS,PYTHON
          name: codecov-umbrella
          fail_ci_if_error: true
          verbose: true
