Skip to content

Add additional tests and code refactoring #5

Add additional tests and code refactoring

Add additional tests and code refactoring #5

name: CI (Build universal wheel + Test + Publish)
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
release:
types: [ published ]
workflow_dispatch:
jobs:
# 1) Build sdist + universal wheel (pure Python)
build_dist:
name: Build distributions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install build tooling
run: |
python -m pip install --upgrade pip
pip install build
- name: Build sdist and wheel
run: python -m build --sdist --wheel --outdir dist
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dists
path: dist/*
# 2) Test from source on all OS/Python
test_source:
name: Test (source) py${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: "pip"
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '11'
- name: Install package (from source)
run: |
python -m pip install --upgrade pip
pip install .
- name: Install test deps
run: pip install pytest==8.3.3
- name: Run tests (unittest)
run: python -m unittest discover tests
# 3) Test the built wheel on all OS/Python
test_wheel:
name: Test (wheel) py${{ matrix.python-version }} on ${{ matrix.os }}
needs: [ build_dist ]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: "pip"
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '11'
- name: Download built dists
uses: actions/download-artifact@v4
with:
name: dists
path: dists
- name: Install built wheel
shell: bash
run: |
python -m pip install --upgrade pip
# Prefer wheel; fall back to sdist if needed
WHEEL=$(ls dists/*.whl | head -n 1 || true)
if [ -n "$WHEEL" ]; then
pip install "$WHEEL"
else
pip install dists/*.tar.gz
fi
- name: Install test deps
run: pip install pytest==8.3.3
- name: Run tests (against installed wheel)
run: python -m unittest discover tests
# 4) (Optional) Publish to PyPI on Release
publish-to-pypi:
name: Publish to PyPI
needs: [ build_dist, test_source, test_wheel ]
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dists
path: upload
# Choose ONE of the two publishing approaches:
# A) API token (simple)
- name: Publish (PyPI via API token)
if: env.USE_OIDC != '1'
uses: pypa/gh-action-pypi-publish@v1.10.3
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: upload
# B) Trusted Publisher / OIDC (recommended)
- name: Publish (PyPI via OIDC)
if: env.USE_OIDC == '1'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: upload