1- # This workflow will upload a Python Package using Twine when a release is created
2- # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3-
4- # This workflow uses actions that are not certified by GitHub.
5- # They are provided by a third-party and are governed by
6- # separate terms of service, privacy policy, and support
7- # documentation.
1+ # THis workflow builds wheels and sdist on tag push, and then publishes to PyPI when a release is published. Builds wheels for python >=3.8
2+ # using cibuildwheel.
83
94name : Upload Python Package
105
116on :
7+ push :
8+ tags :
9+ - ' v*'
1210 release :
1311 types : [published]
1412
15- permissions :
16- contents : read
17-
1813jobs :
19- deploy :
20-
21- runs-on : ubuntu-latest
14+ # --- JOB 1: BUILD BINARY WHEELS ---
15+ build_wheels :
16+ name : Build wheels on ${{ matrix.os }}
17+ runs-on : ${{ matrix.os }}
18+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
2219 strategy :
2320 matrix :
24- python-version : ["3.11"]
21+ os : [ubuntu-latest, macos-13, macos-latest]
22+ steps :
23+ - name : Checkout code
24+ uses : actions/checkout@v4
2525
26+ - name : Build wheels
27+ uses : pypa/cibuildwheel@v2.22.0
28+ env :
29+ CIBW_SKIP : " cp36-* cp37-* pp*"
30+ CIBW_ENVIRONMENT : " PIP_ONLY_BINARY=numpy PIP_PREFER_BINARY=1"
31+
32+ - name : Upload wheel artifacts
33+ uses : actions/upload-artifact@v4
34+ with :
35+ name : cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
36+ path : ./wheelhouse/*.whl
37+
38+ # --- JOB 2: NEW! BUILD SOURCE DISTRIBUTION (sdist) ---
39+ build_sdist :
40+ name : Build source distribution
41+ runs-on : ubuntu-latest
42+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
2643 steps :
27- - uses : actions/checkout@v4
28- - name : Set up Python
29- uses : actions/setup-python@v4
30- with :
31- python-version : ${{ matrix.python-version }}
32- - name : Install dependencies
33- run : |
34- python -m pip install --upgrade pip
35- pip install build
36- - name : Build package
37- run : python -m build --sdist --wheel --outdir dist
38- - name : Publish package
39- uses : pypa/gh-action-pypi-publish@release/v1
40- with :
41- user : __token__
42- password : ${{ secrets.PYPI_API_TOKEN }}
44+ - name : Checkout code
45+ uses : actions/checkout@v4
46+
47+ - name : Set up Python
48+ uses : actions/setup-python@v5
49+ with :
50+ python-version : " 3.11"
51+
52+ - name : Install build tool
53+ run : python -m pip install build
54+
55+ - name : Build sdist
56+ run : python -m build --sdist
57+
58+ - name : Upload sdist artifact
59+ uses : actions/upload-artifact@v4
60+ with :
61+ name : cibw-sdist
62+ path : dist/*.tar.gz
63+
64+ # --- JOB 3: PUBLISH TO PYPI (Collects Wheels + Sdist) ---
65+ publish_pypi :
66+ name : Publish to PyPI
67+ # Crucial: Wait for BOTH wheels and sdist to finish building successfully
68+ needs : [build_wheels, build_sdist]
69+ runs-on : ubuntu-latest
70+ if : github.event_name == 'release' && github.event.action == 'published'
71+
72+ environment :
73+ name : pypi
74+ permissions :
75+ id-token : write
76+
77+ steps :
78+ # This downloads ALL artifacts matching 'cibw-*' (both wheels and sdist)
79+ # and merges them cleanly into the ./dist folder
80+ - name : Download all artifacts
81+ uses : actions/download-artifact@v4
82+ with :
83+ path : ./dist
84+ pattern : cibw-*
85+ merge-multiple : true
86+
87+ - name : Publish to PyPI
88+ uses : pypa/gh-action-pypi-publish@release/v1
0 commit comments