name: Test Gnofract 4D

on:
    pull_request:
      types: [opened, reopened, ready_for_review, synchronize]
    push:
      branches: ["master"]

jobs:
  run:

    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-10.15, ubuntu-20.04]
        python: [3.7]
        toxenv: [py]
        include:
          - os: ubuntu-18.04
            python: 3.6
            toxenv: py
          - os: ubuntu-latest
            python: 3.8
            toxenv: pylint

    env:
      # For labelling Codecov report
      OS: ${{ matrix.os }}
      PYTHON: ${{ matrix.python }}

    steps:
      - uses: actions/checkout@v2
      - name: Install MacOS packages
        if: ${{ runner.os == 'macOS' }}
        run: brew install gtk+3 pygobject3
      - name: Install Ubuntu packages
        if: ${{ runner.os == 'Linux' }}
        # libgirepository1.0-dev required to build PyGObject from source
        # gvfs is needed for Gio.AppInfo.launch_default_for_uri()
        run: sudo apt install gir1.2-gtk-3.0 gvfs libgirepository1.0-dev xvfb
      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python }}
      - name: Install Tox and any other PyPI packages
        run: pip install tox
      - name: Build
        run: python setup.py build
      - name: Run Tox (MacOS)
        if: ${{ runner.os == 'macOS' }}
        run: tox -e ${{ matrix.toxenv }}
      - name: Run Tox (Linux)
        if: ${{ runner.os == 'Linux' }}
        run: xvfb-run --auto-servernum tox -e ${{ matrix.toxenv }}
      - name: Upload coverage to Codecov
        if: ${{ matrix.toxenv == 'py' }}
        uses: codecov/codecov-action@v1.0.7
        with:
          file: ./coverage.xml
          env_vars: OS,PYTHON
