Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reusable workflows for plugins test #112

Open
Czaki opened this issue Apr 29, 2022 · 0 comments
Open

Use reusable workflows for plugins test #112

Czaki opened this issue Apr 29, 2022 · 0 comments
Labels
task Future tasks and discussion items

Comments

@Czaki
Copy link
Contributor

Czaki commented Apr 29, 2022

Github actions do not provide a template with a list of steps but provide reusable workflows. A reusable workflow could live in the same repository but also in another public repository on GitHub.

Some time ago there was a problem with GabrielBB/xvfb-action that stop working on the windows host after the runner update. Solving this issue need multiple PR to different repositories. Using reusable workflows allows performing fixes in one repository that will store this action.

Limitations:

  1. people using such action cannot add any step
  2. you cannot pass any environment variable inside the test
  3. matrix could live only inside the reusable workflow.

But two first limitations may be used to increase the quality of plugins.
Problem with matrix could be workaround using fromJson(inputs.variable)

A simple reusable workflow could look like this:

on:
  workflow_call:
    inputs:
      python_version:
        required: true
        type: string
      os:
        required: true
        type: string
      tox_args:
        required: false
        type: string
        default: ""
      qt_backend:
        required: false
        type: string
        default: >-
          ["PyQt5", "PySide2"]

jobs:
  test:
    name: ${{ matrix.os }} py ${{ matrix.python_version }} ${{ matrix.napari }} ${{ matrix.qt_backend }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: ${{fromJson(inputs.os)}}
        python_version: ${{fromJson(inputs.python_version)}}
        napari_version: ${{fromJson(inputs.napari)}}
        qt_backend: ${{fromJson(inputs.qt_backend)}}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
        name: Install Python ${{ matrix.python_version }}
        with:
          python-version: ${{ matrix.python_version }}

      - name: Install ubuntu libraries
        if: runner.os == 'Linux'
        run: |
          sudo apt-get install -y libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0
      - name: Install Windows OpenGL
        if: runner.os == 'Windows'
        run: |
          git clone --depth 1 git://github.com/pyvista/gl-ci-helpers.git
          powershell gl-ci-helpers/appveyor/install_opengl.ps1
          if (Test-Path -Path "C:\Windows\system32\opengl32.dll" -PathType Leaf) {Exit 0} else {Exit 1}

      - name: Install dependencies
        run: |
          python -m pip install tox tox-gh-actions
      - name: Test with tox
        uses: GabrielBB/xvfb-action@v1
        timeout-minutes: 60
        with:
          run: python -m tox ${{ inputs.tox_args }}
        env:
          PYVISTA_OFF_SCREEN: True  # required for opengl on windows
          BACKEND: ${{ matrix.qt_backend }}

And its usage could look like

name: napari widgets

on:
  push:
    branches:
      - develop
      - main
  pull_request:
    branches:
      - '**'

jobs:
  test:
    name: Test napari plugin
    uses: napari/cookiecutter-napari-plugin/.github/workflows/plugin_test_workflow.yml
    with:
      python_version: >-
        ["3.7", "3.8", "3.9", "3.10"]
      os: >-
        ["windows-2019", "ubuntu-20.04", "macos-11"]

The longer example with code coverage, using test data (downloaded in previous steep), etc could be found here: https://github.com/4DNucleome/PartSeg/blob/c76cc26579a287b42c546a2b9531463723a8b90d/.github/workflows/base_test_workflow.yml

@tlambert03 tlambert03 added the task Future tasks and discussion items label May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Future tasks and discussion items
Projects
None yet
Development

No branches or pull requests

2 participants