Skip to content

Test Matrix

Test Matrix #3

Workflow file for this run

name: Test Matrix
on:
pull_request:
paths:
- '**/*.py'
- '**/*.cpp'
- '**/*.hpp'
- '**/*.ipynb'
- '**/*.c'
- '**/*.h'
- '**/*.toml'
- '.github/workflows/test-matrix.yml' # run if this file is changed
- '!docs/conf.py'
workflow_dispatch:
inputs:
skip_coverage:
default: true
required: false
type: boolean
permissions:
contents: read
jobs:
test-all-versions-oses:
strategy:
fail-fast: false
matrix:
version: ["3.9", "3.10", "3.11", "3.12"]
os: [windows-latest, macOS-13, macOS-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Setup | Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.codecov.io:443
api.github.com:443
cli.codecov.io:443
codecov.io:443
files.pythonhosted.org:443
github.com:443
pypi.org:443
storage.googleapis.com:443
uploader.codecov.io:443
- name: Setup | Check out the commit
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup | Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.version }}
- name: Setup | Install dependencies
run: |
python3 -m pip install --upgrade pip
- name: Action | Test editable build
run: python3 -m pip install -e .[formats,examples,tests]
- name: Action | Test without coverage on Python 3.9 or if requested
if: ${{ (github.event == 'workflow_dispatch' && inputs.skip_coverage) || (matrix.os != 'ubuntu-latest' && matrix.version == '3.9') }}
run: |
python3 -m pytest --nbmake --disable-warnings --no-header --color=auto examples/ tests/ >> $GITHUB_STEP_SUMMARY
- name: Action | Coverage and testing Linux - Python and C++ coverage
if: ${{ (github.event == 'pull_request' || ! inputs.skip_coverage ) && matrix.os == 'ubuntu-latest' && matrix.version != '3.9'}}
run: |
export CPPFLAGS="-coverage"
python3 -m pip install setuptools pybind11 gcovr
python3 setup.py build_ext --inplace --force
echo '### Run tests' >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
python3 -m pytest --nbmake --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ | tee -a $GITHUB_STEP_SUMMARY
find src -type f -name '*.cpp' | xargs -I{} gcov -o build/temp*/src/ext_modules/libsansmic {}
gcovr --txt | tee -a $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Action | Coverage and testing on MacOS - Python coverage only
if: ${{ (github.event == 'pull_request' || ! inputs.skip_coverage ) && matrix.os != 'windows-latest' && matrix.os != 'ubuntu-latest' }}
run: |
echo '### Run tests' >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
python3 -m pytest --nbmake --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ | tee -a $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Action | Coverage and testing on Windows - Python coverage only
if: ${{ (github.event == 'pull_request' || ! inputs.skip_coverage ) && matrix.os == 'windows-latest' }}
shell: powershell
run: |
echo '### Run tests' >> $Env:GITHUB_STEP_SUMMARY
echo '```bash' >> $Env:GITHUB_STEP_SUMMARY
python3 -m pytest --nbmake --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ >> $Env:GITHUB_STEP_SUMMARY
echo '```' >> $Env:GITHUB_STEP_SUMMARY
- name: Action | Upload coverage reports to Codecov
if: ${{ (github.event == 'pull_request' || ! inputs.skip_coverage) && success() || failure() }}
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: ${{ matrix.os }}
- name: Action | Test uninstall process
if: success() || failure()
# Allow upload to codecov to fail but not fail all tests
run: python3 -m pip uninstall -y sansmic