Skip to content

Precompile Wheels for Different OS and Python Versions Before Publishing to PyPI #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 73 additions & 12 deletions .github/workflows/publish-to-pypi.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,93 @@
name: Publish python PyPI
name: Publish to PyPI

on:
push:
tags:
- v*

jobs:
build-release:
name: Build and publish PyPI
runs-on: ubuntu-latest
# First job is to build the wheels on different OS
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
fetch-depth: 0
python-version: "3.12"

- name: Upgrade pip and install cibuildwheel
run: |
python -m pip install --upgrade pip
pip install cibuildwheel

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: "cp310-* cp311-* cp312-*"
CIBW_SKIP: "pp* *musllinux*"
CIBW_TEST_SKIP: "*"
CIBW_ARCHS_MACOS: "universal2"
CIBW_ARCHS_LINUX: "x86_64 aarch64"

- name: Upload built wheels
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}
path: wheelhouse/*.whl

# Then just build the source distribution as normal
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.12"

- name: Install build tools
- name: Upgrade pip and install build
run: |
pip install --upgrade pip setuptools wheel build setuptools_scm
python -m pip install --upgrade pip
pip install build

- name: Build sdist
run: python -m build --sdist --outdir dist

- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: sdist
path: dist/*.tar.gz

# Finally publish all files to PyPI
publish:
name: Publish to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: dist

- name: Build Package
- name: Merge all distributions
run: |
python -m build --no-isolation
mkdir -p final_dist
find dist -name '*.whl' -exec cp {} final_dist/ \;
find dist -name '*.tar.gz' -exec cp {} final_dist/ \;

- name: Publish package to PyPI
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: final_dist
Loading