# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

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

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.8', '3.9', '3.10']

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        sudo apt install -y libopenmpi-dev libhdf5-mpi-dev
        python -m pip install --upgrade pip
        pip install .
        pip install .[dev]
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
        CC="mpicc" HDF5_MPI="ON" pip install --upgrade --force-reinstall --no-binary=h5py h5py
    - name: Lint with pylint
      run: |
        # stop the build if there are Python syntax errors or undefined names
        pylint --reports=no --errors-only qp
        # stp the build if there are a lot of messages
        pylint --reports=no --fail-under=9.5 qp
        # exit-zero treats all errors as warnings.
        pylint --exit-zero qp
    - name: Test with pytest
      run: |
        python -m pytest --cov-report=xml
        mpiexec -np 2 python -m pytest --no-cov tests/qp/test_parallel.py
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v1
      with:
        file: ./coverage.xml
        flags: unittests
        env_vars: OS,PYTHON
        name: codecov-umbrella
        fail_ci_if_error: true
