name: CI

on:
  push:
    branches:
      - main
  pull_request:

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

jobs:
  build:
    name: build
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python-version:
          - "3.10"
          - "3.11"
          - "3.12"
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
        with:
          python-version: ${{ matrix.python-version }}
      - name: Sync
        run: uv sync
      - name: Run pre-commit
        run: uv run pre-commit run --all-files
      - name: Run pytest
        run: uv run pytest -Werror -s --block-network --cov pystac_client --cov-report term-missing
      - name: Run coverage
        run: uv run coverage xml
      - uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ./coverage.xml
          fail_ci_if_error: false

  min-versions:
    name: min-versions
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
        with:
          activate-environment: true
          python-version: "3.10"
      - name: Install with min requirements
        run: uv sync --no-dev --resolution=lowest-direct
      - name: Run smoke test
        run: stac-client search https://landsatlook.usgs.gov/stac-server -c landsat-c2l2-sr --max-items 1

  pre-release:
    name: pre-release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
      - name: Sync
        run: uv sync
      - name: Install any pre-releases of pystac
        run: uv pip install -U --pre pystac
      - name: Run pytest
        run: uv run pytest -Werror -s --block-network

  upstream:
    name: upstream
    runs-on: ubuntu-latest
    if: github.event_name != 'pull_request'
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
      - name: Sync
        run: uv sync
      - name: Install pystac from main
        run: uv pip install --force-reinstall git+https://github.com/stac-utils/pystac.git
      - name: Run pytest
        run: uv run pytest -Werror -s --block-network

  docs:
    name: docs
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash -el {0}
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
      - name: Install pandoc
        run: sudo apt-get install -y pandoc
      - name: Sync
        run: uv sync --group docs
      - name: Build docs
        run: ./scripts/build-docs
