Skip to content

Merge branch 'main' into dependabot/uv/maturin-gte-1.14.1-and-lt-2.0 #803

Merge branch 'main' into dependabot/uv/maturin-gte-1.14.1-and-lt-2.0

Merge branch 'main' into dependabot/uv/maturin-gte-1.14.1-and-lt-2.0 #803

Workflow file for this run

# This workflow will install Python dependencies,
# run tests with a variety of Python versions,
# and upload a new build to TestPyPI.
#
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Unit tests
on:
push:
branches-ignore:
- 'gh-pages' # GitHub Pages do not trigger all tests
tags-ignore:
- 'v*' # Avoid re-running existing commit on release
permissions:
contents: read
env:
FORCE_COLOR: 1
jobs:
generate-matrix:
name: Derive Python version matrix from pyproject.toml
runs-on: ubuntu-latest
outputs:
python-versions: ${{ steps.python-versions.outputs.python-versions }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Read supported versions from classifiers
id: python-versions
run: |
python - <<'EOF' >> "$GITHUB_OUTPUT"
import json
import tomllib
with open("pyproject.toml", "rb") as f:
classifiers = tomllib.load(f)["project"]["classifiers"]
prefix = "Programming Language :: Python :: 3."
versions = [
classifier.rsplit("::", 1)[-1].strip()
for classifier in classifiers
if classifier.startswith(prefix)
]
print(f"python-versions={json.dumps(versions)}")
EOF
test-and-build:
needs: generate-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ${{ fromJson(needs.generate-matrix.outputs.python-versions) }}
env:
PYTHON_VERSION: ${{ matrix.python-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
cache-dependency-glob: "uv.lock"
enable-cache: false
python-version: ${{ matrix.python-version }}
- name: Install library and dependencies
run: |
uv sync --frozen
uvx maturin develop
- name: Run tests (Pytest + Coverage)
run: |
uv run --frozen pytest
uv run --frozen coverage report
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PLATFORM: ${{ matrix.os }}
- name: Upload Results to CodeCov
if: success()
uses: codecov/codecov-action@v7
with:
env_vars: PYTHON_VERSION
fail_ci_if_error: false
files: ./tests/reports/coverage-html/index.html,./tests/reports/coverage.xml
flags: unittests
name: "${{ matrix.os }} - Python ${{ matrix.python-version }}"
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build binaries for ${{ matrix.os }}-${{ matrix.python-version }}
run: |
uv build
- name: Upload builds
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.os }}-${{ matrix.python-version }}
path: dist/
testpypi-deploy:
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
environment: testpypi
permissions:
id-token: write
runs-on: ubuntu-latest
needs: test-and-build
steps:
- name: Download Artifacts
uses: actions/download-artifact@v8
with:
merge-multiple: true
path: dist/
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
continue-on-error: true
with:
print-hash: true
repository-url: https://test.pypi.org/legacy/
skip-existing: true