name: Python package

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

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

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-11, windows-latest]
        python-version: [3.7, 3.8, 3.9, "3.10"]
        include:
          - os: ubuntu-latest
            path: ~/.cache/pip
          - os: macos-11
            path: ~/Library/Caches/pip
          - os: windows-latest
            path: ~\AppData\Local\pip\Cache
        exclude:
          - os: macos-11
            python-version: 3.7
          - os: windows-latest
            python-version: 3.7

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

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

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip setuptools wheel
          pip install -r requirements.txt

      - name: Install ffmpeg
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            sudo apt-get update
            sudo apt-get install ffmpeg
          elif [ "$RUNNER_OS" == "macOS" ]; then
            brew install ffmpeg
          else
            choco install ffmpeg
          fi
        shell: bash

      - name: Run pytest tests
        run: |
          pip install pytest
          python -m pytest

      - name: Run functional tests
        run: |
          pip install git+https://github.com/${{ github.repository }}.git@${{ github.sha }}
          python examples/testscript.py
          python examples/testscript_multianimal.py
