name: CI

on:
  # any time someone pushes a new branch to origin
  push:

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:

  mypy:
    name: 'MyPy'
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: '3.10'

      - name: Install dependencies
        run: pip install -U . --upgrade-strategy eager -r requirements-test.txt

      - name: Run MyPy check
        run: mypy tractor/ --ignore-missing-imports

  sdist-linux:
    name: 'sdist'
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: '3.10'

      - name: Build sdist
        run: python setup.py sdist --formats=zip

      - name: Install sdist from .zips
        run: python -m pip install dist/*.zip


  testing-linux:
    name: '${{ matrix.os }} Python ${{ matrix.python }} - ${{ matrix.spawn_backend }}'
    timeout-minutes: 10
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        python: ['3.9', '3.10']
        spawn_backend: ['trio', 'mp']

    steps:

      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: '${{ matrix.python }}'

      - name: Install dependencies
        run: pip install -U . -r requirements-test.txt -r requirements-docs.txt --upgrade-strategy eager

      - name: Run tests
        run: pytest tests/ --spawn-backend=${{ matrix.spawn_backend }} -rs

  # We skip 3.10 on windows for now due to
  # https://github.com/pytest-dev/pytest/issues/8733
  # some kinda weird `pyreadline` issue..

  # TODO: use job filtering to accomplish instead of repeated
  # boilerplate as is above XD:
  # - https://docs.github.com/en/actions/learn-github-actions/managing-complex-workflows
  # - https://docs.github.com/en/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
  # - https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idif
  testing-windows:
    name: '${{ matrix.os }} Python ${{ matrix.python }} - ${{ matrix.spawn_backend }}'
    timeout-minutes: 12
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest]
        python: ['3.9', '3.10']
        spawn_backend: ['trio', 'mp']

    steps:

      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: '${{ matrix.python }}'

      - name: Install dependencies
        run: pip install -U . -r requirements-test.txt -r requirements-docs.txt --upgrade-strategy eager

      - name: Run tests
        run: pytest tests/ --spawn-backend=${{ matrix.spawn_backend }} -rs