Skip to content

Publish quantcpp to PyPI #11

Publish quantcpp to PyPI

Publish quantcpp to PyPI #11

Workflow file for this run

name: Publish quantcpp to PyPI
on:
push:
tags:
- 'v*'
- 'pypi-v*'
workflow_dispatch:
inputs:
target:
description: 'Where to publish'
required: true
default: 'testpypi'
type: choice
options:
- testpypi
- pypi
jobs:
# ---------------------------------------------------------------------
# Build platform-specific wheels via cibuildwheel
# ---------------------------------------------------------------------
build_wheels:
name: Wheels on ${{ matrix.os }} (${{ matrix.arch }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: x86_64
- os: ubuntu-24.04-arm # Native ARM runner (free, no QEMU)
arch: aarch64
- os: macos-14 # Apple Silicon (M-series). Intel macs deferred.
arch: arm64
# Windows mingw64 wheel is deferred — quant.h's clock_gettime shim
# conflicts with mingw's native one. Windows users install via sdist
# with MSVC for now. Tracked for v0.8.x.
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# cibuildwheel mounts only the package-dir into Linux build containers,
# so quant.h must already live inside bindings/python/ before invoke.
# We stage it as bindings/python/quant.h (NOT inside quantcpp/, which
# is .gitignore'd and would be excluded by isolated source copies).
- name: Bundle quant.h into package
shell: bash
run: cp quant.h bindings/python/quant.h
- name: Build wheels
uses: pypa/cibuildwheel@v2.21.3
with:
package-dir: bindings/python
output-dir: wheelhouse
env:
CIBW_ARCHS: ${{ matrix.arch }}
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ matrix.arch }}
path: ./wheelhouse/*.whl
if-no-files-found: error
# ---------------------------------------------------------------------
# Build the source distribution
# ---------------------------------------------------------------------
build_sdist:
name: Source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Bundle quant.h into package
shell: bash
run: cp quant.h bindings/python/quant.h
- name: Build sdist
run: |
cd bindings/python
python -m pip install --upgrade pip build
python -m build --sdist
- name: Smoke-test sdist install (clean venv)
run: |
python -m venv /tmp/sdist-test
/tmp/sdist-test/bin/pip install bindings/python/dist/quantcpp-*.tar.gz
cd /tmp
/tmp/sdist-test/bin/python -c "import quantcpp; from quantcpp._binding import get_lib; print('sdist OK:', quantcpp.__version__, get_lib().quant_version().decode())"
- uses: actions/upload-artifact@v4
with:
name: sdist
path: bindings/python/dist/*.tar.gz
if-no-files-found: error
# ---------------------------------------------------------------------
# Publish — Trusted Publishing (OIDC), no API token needed
# ---------------------------------------------------------------------
publish_testpypi:
name: Publish to TestPyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi'
environment:
name: testpypi
url: https://test.pypi.org/p/quantcpp
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: List artifacts
run: ls -la dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
publish_pypi:
name: Publish to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# Auto-publish on tag push, OR manual dispatch with target=pypi
if: |
startsWith(github.ref, 'refs/tags/') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'pypi')
environment:
name: pypi
url: https://pypi.org/p/quantcpp
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: List artifacts
run: ls -la dist/
- uses: pypa/gh-action-pypi-publish@release/v1