name: testing

on:
  push:
    branches:
      - main
    paths-ignore:
      - 'docs/CHANGELOG.md'

  pull_request:
    branches:
      - main

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

jobs:
  lint:
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 1
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: 3.11
          cache: pip
      - name: Run pre-commit
        run: |
          pip install pre-commit
          pre-commit run --all-files

  test:
    needs: lint
    services:
      local_mongodb:
        image: mongo:4.0
        ports:
          - 27017:27017

      azurite:
        image: mcr.microsoft.com/azure-storage/azurite
        ports:
          - 10000:10000

    strategy:
      max-parallel: 6
      matrix:
        os: [ubuntu-latest]
        python-version: ["3.9", "3.10", "3.11", "3.12"]

    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v4

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

    - name: Install Python dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements/${{ matrix.os }}_py${{ matrix.python-version }}_extras.txt

    - name: Test with pytest
      env:
        CONTINUOUS_INTEGRATION: True
        MONGODB_SRV_URI: ${{ secrets.MONGODB_SRV_URI }}
      run: |
        pip install -e .
        pytest --cov=maggma --cov-report=xml
    - uses: codecov/codecov-action@v5.4.0
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        file: ./coverage.xml

  docs:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - uses: actions/setup-python@v5
      with:
        python-version: "3.10"

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e .[docs]

    - name: Build
      run: mkdocs build
