name: CI

# On every pull request, but only on push to main
on:
  push:
    branches:
    - main
    tags:
    - '*'
  pull_request:
env:
  LATEST_PY_VERSION: '3.14'

jobs:
  tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - '3.8'
          - '3.9'
          - '3.10'
          - '3.11'
          - '3.12'
          - '3.13'
          - '3.14'

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Install uv
        uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
        with:
          version: "0.9.*"
          enable-cache: true
          python-version: ${{ matrix.python-version }}

      - name: Install dependencies
        run: uv sync

      - name: Run pre-commit
        if: ${{ matrix.python-version == env.LATEST_PY_VERSION }}
        run: |
          uv run pre-commit run --all-files

      - name: Run tests
        run: uv run pytest --cov stac_pydantic --cov-report term-missing --cov-report xml

      - name: Upload Results
        if: ${{ matrix.python-version == env.LATEST_PY_VERSION }}
        uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
        with:
          files: ./coverage.xml
          flags: unittests
          fail_ci_if_error: false
          token: ${{ secrets.CODECOV_TOKEN }}
