UCL/snappysonic

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
# CI for this library is a bit tricky, as an working display/GFX card is
# expected to do the rendering. We use a fake display for Windows/Linux, and
# don't run CI on Mac. Running tests locally is simpler!
on: push

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        python-ver: [3.7, 3.8]
        experimental: [false]
        include:
          - python-ver: 3.9
            os: ubuntu-latest
            experimental: true
          - python-ver: 3.9
            os: windows-latest
            experimental: true
          - python-ver: 3.9
            os: macos-latest
            experimental: true

    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.experimental }}

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-ver }}

      # VTK uses OpenGL 2.0, but the windows Server version used on
      # GitHub actions only has 1.1, so need to setup software rendering
      # with Mesa.
      # https://github.com/pal1000/mesa-dist-win
      - name: Setup Mesa (Windows)
        if: matrix.os == 'windows-latest'
        run: |
          curl --output mesa.7z -L https://github.com/pal1000/mesa-dist-win/releases/download/20.1.1-2/mesa3d-20.1.1-release-mingw.7z
          7z x mesa.7z -omesa -y

          # The script requires user input (choice of options) so need to
          # fiddle to get it to run automatically. Not a clean way to do it,
          # but works.
          sed -i 's/@echo Please make a deployment choice:/@GOTO desktopgl/g' mesa\systemwidedeploy.cmd
          sed -i 's/@echo Desktop OpenGL drivers deploy complete./@exit/g' mesa\systemwidedeploy.cmd
          mesa\systemwidedeploy.cmd

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

      - name: Run tests using xvfb (Ubuntu)
        if: startsWith(matrix.os, 'ubuntu')
        run: |
          sudo apt-get install xvfb libxkbcommon-x11-0
          sudo Xvfb :1 -screen 0 1024x768x24 </dev/null &
          export DISPLAY=":1"
          export LD_LIBRARY_PATH=$pythonLocation"/lib/python3.6/site-packages/PySide2/Qt/plugins/platfoms"
          coverage erase
          coverage run -a --source ./snappysonic -m pytest
          coverage report -m

      - name: Run tests Windows/Mac
        if: contains(matrix.os, 'o')
        run: |
          coverage erase
          coverage run -a --source ./snappysonic -m pytest
          coverage report -m

      - name: Linting
        run: |
          pylint --rcfile=tests/pylintrc snappysonic

      - name: Run coveralls
        run: |
          coveralls

  deploy:
    runs-on: ubuntu-latest
    needs: test
    steps:
      - uses: actions/checkout@v2
      - uses: actions/checkout@master
      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          # TODO: python version for deploy?
          python-version: 3.9

      - name: Install dependencies
        run: python -m pip install wheel twine setuptools

      - name: Build wheel
        run: |
          python setup.py sdist bdist_wheel

      - name: Publish package if tagged release
        if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
        uses: pypa/gh-action-pypi-publish@master
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}