Publish quantcpp to PyPI #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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-latest | |
| arch: aarch64 | |
| - os: macos-14 # Apple Silicon (M-series). Intel macs deferred. | |
| arch: arm64 | |
| - os: windows-latest | |
| arch: AMD64 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up QEMU (linux aarch64 emulation) | |
| if: matrix.os == 'ubuntu-latest' && matrix.arch == 'aarch64' | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64 | |
| # cibuildwheel mounts only the package-dir into Linux build containers, | |
| # so we must place quant.h INSIDE bindings/python/quantcpp/ before | |
| # invoking it. setup.py refreshes from ../../quant.h in dev tree, but | |
| # that path doesn't exist inside the manylinux container. | |
| - name: Bundle quant.h into package | |
| shell: bash | |
| run: cp quant.h bindings/python/quantcpp/_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: 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 |