name: Test and docs

on:
  push:
    branches:
      - '*'

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
    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 dependencies
        run: |
          pip install --upgrade pytest coverage mypy
          pip install --upgrade -r requirements.txt
      - name: Run mypy
        run: mypy updater
      - name: Run tests with coverage
        run: |
          coverage run --source . --omit conf.py -m pytest --junitxml=report.xml
          coverage report
          coverage xml
      - name: Upload test reports
        uses: actions/upload-artifact@v4
        with:
          name: test-reports-${{ matrix.python-version }}
          path: |
            report.xml
            coverage.xml

  build-docs:
    runs-on: ubuntu-latest
    container: python:latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: Install dependencies
        run: |
          pip install --upgrade sphinx
          pip install --upgrade -r requirements.txt
      - name: Build docs
        run: |
          make html
          mv -f _build/html public
      - name: Upload docs
        uses: actions/upload-artifact@v4
        with:
          name: built-docs
          path: public
          retention-days: 1
