
# Adapted from https://github.com/openpifpaf/openpifpaf/blob/main/.github/workflows/test.yml,
#which is: 'Copyright 2019-2021 by Sven Kreiss and contributors. All rights reserved.'
# and licensed under GNU AGPLv3

name: Tests

on:
  push:
    paths:
      - 'monoloco/**'
      - 'test/**'
      - 'docs/00*.png'
      - 'docs/frame0032.jpg'
      - '.github/workflows/tests.yml'

  pull_request:
    paths:
      - 'monoloco/**'
      - 'test/**'
      - 'docs/00*.png'
      - 'docs/frame0032.jpg'
      - '.github/workflows/tests.yml'

jobs:
  build:

    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            python: 3.7
            torch: 1.7.1+cpu
            torchvision: 0.8.2+cpu
            torch-source: https://download.pytorch.org/whl/torch_stable.html
          - os: ubuntu-latest
            python: 3.8
            torch: 1.7.1+cpu
            torchvision: 0.8.2+cpu
            torch-source: https://download.pytorch.org/whl/cpu/torch_stable.html
          - os: macos-latest
            python: 3.7
            torch: 1.7.1
            torchvision: 0.8.2
            torch-source: https://download.pytorch.org/whl/torch_stable.html
          - os: macos-latest
            python: 3.8
            torch: 1.7.1
            torchvision: 0.8.2
            torch-source: https://download.pytorch.org/whl/torch_stable.html
          - os: windows-latest
            python: 3.7
            torch: 1.7.1+cpu
            torchvision: 0.8.2+cpu
            torch-source: https://download.pytorch.org/whl/torch_stable.html

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python }}
      if: ${{ !matrix.conda }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python }}
    - name: Set up Conda
      if: matrix.conda
      uses: s-weigand/setup-conda@v1
      with:
        update-conda: true
        python-version: ${{ matrix.python }}
        conda-channels: anaconda, conda-forge
    - run: conda --version
      if: matrix.conda
    - run: which python
      if: matrix.conda
    - run: python --version
    - name: Install
      run: |
        python -m pip install --upgrade pip setuptools
        python -m pip install -e ".[test]"
    - name: Print environment
      run: |
        python -m pip freeze
        python --version
        python -c "import monoloco; print(monoloco.__version__)"
    - name: Lint monoloco
      run: |
        pylint monoloco --disable=fixme
    - name: Lint tests
      if: matrix.os != 'windows-latest'  # because of path separator
      run: |
        pylint tests/*.py --disable=fixme

    - name: Test
      run: |
        pytest -vv
