Skip to content

Refactors CI workflows for tutorial testing #1

Refactors CI workflows for tutorial testing

Refactors CI workflows for tutorial testing #1

name: Test code
on:
# Trigger the workflow on push
push:
# Every branch
branches:
- '**'
# But do not run this workflow on creating a new tag starting with 'v', e.g. 'v1.0.3' (see pypi-publish.yml)
tags-ignore:
- 'v*'
# Trigger the workflow on pull request
pull_request:
branches:
- '**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allow only one concurrent workflow, skipping runs queued between the run in-progress and latest queued.
# And cancel in-progress runs.
concurrency:
group:
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test-code:
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, windows-2022, macos-13, macos-14]
python-version: ['3.12']
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade package installer for Python
shell: bash
run: python -m pip install --upgrade pip
- name: Install Python dependencies
shell: bash
run: python -m pip install -r requirements.txt
# Check if tutorials as python scripts run without errors
# Run all Python scripts in the folder tutorials/ in parallel
# -n 1: run one script per Python invocation
# -P 0: run as many in parallel as you have cores (auto mode)
- name: Run tutorials as python scripts
shell: bash
run: |
export PYTHONPATH=$(pwd)/src:$PYTHONPATH
find tutorials/ -name "*.py" | xargs -n 1 -P 0 python
# Check if tutorials as Jupyter Notebooks run without errors
# Convert all Python scripts in the folder tutorials/ to Jupyter Notebooks
# Run all Jupyter Notebooks in the folder tutorials/ in parallel
# -n=auto: run as many in parallel as you have cores (auto mode)
# --nbmake-timeout=300: set timeout to 300 seconds
- name: Run tutorials as Jupyter Notebooks
shell: bash
run: |
export PYTHONPATH=$(pwd)/src:$PYTHONPATH
jupytext tutorials/*.py --to ipynb
python -m pytest --nbmake tutorials/ --nbmake-timeout=300 --color=yes -n=auto