| 1 |
name: Build wheels, optionally deploy to PyPI |
| 2 |
|
| 3 |
on: |
| 4 |
workflow_dispatch: |
| 5 |
inputs: |
| 6 |
confirm_ref: |
| 7 |
description: "Confirm chosen branch name to deploy to PyPI (optional):" |
| 8 |
default: "" |
| 9 |
override_version: |
| 10 |
description: "Override version number (optional):" |
| 11 |
default: "" |
| 12 |
|
| 13 |
|
| 14 |
jobs: |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
deploy_test: |
| 25 |
name: Verify PyPI deployment confirmation |
| 26 |
runs-on: ubuntu-latest |
| 27 |
env: |
| 28 |
GITHUB_REF: ${{ github.ref }} |
| 29 |
CONFIRM_REF: ${{ github.event.inputs.confirm_ref }} |
| 30 |
steps: |
| 31 |
- name: Compare confirmation to current reference |
| 32 |
shell: bash |
| 33 |
run: | |
| 34 |
[[ -z $CONFIRM_REF || $GITHUB_REF =~ ^refs/(heads|tags)/$CONFIRM_REF$ || $CONFIRM_REF == "test" ]] |
| 35 |
if [[ $CONFIRM_REF == "test" ]]; then |
| 36 |
echo "Build and deploy to test.pypi.org." |
| 37 |
elif [[ -z $CONFIRM_REF ]]; then |
| 38 |
echo "Build only. Nothing will be uploaded to PyPI." |
| 39 |
else |
| 40 |
echo "Full build and deploy. Wheels and source will be uploaded to PyPI." |
| 41 |
fi |
| 42 |
|
| 43 |
|
| 44 |
build_sdist: |
| 45 |
name: Build sdist on Ubuntu |
| 46 |
needs: deploy_test |
| 47 |
runs-on: ubuntu-latest |
| 48 |
env: |
| 49 |
OVERRIDE_VERSION: ${{ github.event.inputs.override_version }} |
| 50 |
|
| 51 |
steps: |
| 52 |
- uses: actions/checkout@v6 |
| 53 |
|
| 54 |
- uses: actions/setup-python@v6 |
| 55 |
name: Install Python |
| 56 |
with: |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
python-version: '3.11' |
| 61 |
|
| 62 |
- name: Install pip build |
| 63 |
run: | |
| 64 |
python -m pip install 'build' |
| 65 |
|
| 66 |
- name: Build sdist tarball |
| 67 |
shell: bash |
| 68 |
run: | |
| 69 |
if [[ ! -z "$OVERRIDE_VERSION" ]]; then echo "$OVERRIDE_VERSION" > VERSION; fi |
| 70 |
# The build package is the reference PEP 517 package builder. All |
| 71 |
# dependencies are specified by our setup code. |
| 72 |
python -m build --sdist . |
| 73 |
|
| 74 |
|
| 75 |
- name: Create zipfile from tarball |
| 76 |
shell: bash |
| 77 |
working-directory: dist |
| 78 |
run: | |
| 79 |
# First assert that there is exactly one tarball, and find its name. |
| 80 |
shopt -s failglob |
| 81 |
tarball_pattern="*.tar.gz" |
| 82 |
tarballs=($tarball_pattern) |
| 83 |
[[ ${#tarballs[@]} == 1 ]] |
| 84 |
tarball="${tarballs[0]}" |
| 85 |
# Get the stem and make the zipfile name. |
| 86 |
stem="${tarball%.tar.gz}" |
| 87 |
zipfile="${stem}.zip" |
| 88 |
# Extract the tarball and rezip it. |
| 89 |
tar -xzf "$tarball" |
| 90 |
zip "$zipfile" -r "$stem" |
| 91 |
rm -r "$stem" |
| 92 |
|
| 93 |
- uses: actions/upload-artifact@v7 |
| 94 |
with: |
| 95 |
name: sdist |
| 96 |
path: | |
| 97 |
dist/*.tar.gz |
| 98 |
dist/*.zip |
| 99 |
if-no-files-found: error |
| 100 |
|
| 101 |
|
| 102 |
build_wheels: |
| 103 |
name: Build wheels on ${{ matrix.os }} |
| 104 |
needs: deploy_test |
| 105 |
runs-on: ${{ matrix.os }} |
| 106 |
strategy: |
| 107 |
matrix: |
| 108 |
|
| 109 |
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, windows-11-arm, macos-15-intel, macos-latest] |
| 110 |
env: |
| 111 |
|
| 112 |
CIBW_BUILD: "cp3{11,12,13,14}-*" |
| 113 |
|
| 114 |
|
| 115 |
CIBW_SKIP: "*-musllinux* *-manylinux_i686 *-win32" |
| 116 |
|
| 117 |
OVERRIDE_VERSION: ${{ github.event.inputs.override_version }} |
| 118 |
|
| 119 |
steps: |
| 120 |
- uses: actions/checkout@v6 |
| 121 |
|
| 122 |
- uses: actions/setup-python@v6 |
| 123 |
name: Install Python |
| 124 |
with: |
| 125 |
|
| 126 |
python-version: '3.11' |
| 127 |
|
| 128 |
- name: Install cibuildwheel |
| 129 |
run: | |
| 130 |
# cibuildwheel does the heavy lifting for us. >=3 is needed for |
| 131 |
# python 3.14. |
| 132 |
python -m pip install 'cibuildwheel==3.3.*' |
| 133 |
|
| 134 |
- name: Build wheels |
| 135 |
shell: bash |
| 136 |
run: | |
| 137 |
# If the version override was specified, then write it the VERSION |
| 138 |
# file with it. |
| 139 |
if [[ ! -z "$OVERRIDE_VERSION" ]]; then echo "$OVERRIDE_VERSION" > VERSION; fi |
| 140 |
python -m cibuildwheel --output-dir wheelhouse |
| 141 |
|
| 142 |
- uses: actions/upload-artifact@v7 |
| 143 |
with: |
| 144 |
name: wheels-${{ matrix.os }} |
| 145 |
path: ./wheelhouse/*.whl |
| 146 |
|
| 147 |
|
| 148 |
deploy: |
| 149 |
name: "Deploy to PyPI if desired" |
| 150 |
needs: [deploy_test, build_sdist, build_wheels] |
| 151 |
runs-on: ubuntu-latest |
| 152 |
env: |
| 153 |
TWINE_USERNAME: __token__ |
| 154 |
TWINE_NON_INTERACTIVE: 1 |
| 155 |
|
| 156 |
steps: |
| 157 |
- name: Download build artifacts to local runner |
| 158 |
uses: actions/download-artifact@v7 |
| 159 |
with: |
| 160 |
path: wheels |
| 161 |
merge-multiple: true |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
- name: Check wheels |
| 166 |
run: | |
| 167 |
ls -R wheels |
| 168 |
if ! [[ $(ls wheels/*.whl | wc -l) == 24 ]]; then exit 1; fi |
| 169 |
if ! ls wheels/*.tar.gz 1> /dev/null 2>&1; then exit 1; fi |
| 170 |
if ! ls wheels/*.zip 1> /dev/null 2>&1; then exit 1; fi |
| 171 |
|
| 172 |
- uses: actions/setup-python@v6 |
| 173 |
name: Install Python |
| 174 |
with: |
| 175 |
python-version: '3.11' |
| 176 |
|
| 177 |
- name: Verify this is not a dev version |
| 178 |
shell: bash |
| 179 |
run: | |
| 180 |
python -m pip install wheels/*-cp311-cp311-manylinux*_x86_64.whl |
| 181 |
python -c 'import qutip; print(qutip.__version__); assert "dev" not in qutip.__version__; assert "+" not in qutip.__version__' |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
- name: Upload sdist and wheels to PyPI |
| 186 |
run: | |
| 187 |
# The confirmation is tested explicitly in `deploy_test`, so we know |
| 188 |
# it is either a missing confirmation (so we shouldn't run this job), |
| 189 |
# 'test' or a valid confirmation. We don't need to retest the value |
| 190 |
# of the confirmation, beyond checking that one existed. |
| 191 |
if [ '${{ github.event.inputs.confirm_ref }}' == 'test' ]; then |
| 192 |
export TWINE_REPOSITORY=testpypi |
| 193 |
export TWINE_PASSWORD=${{ secrets.TESTPYPI_TOKEN }} |
| 194 |
elif [ '${{ github.event.inputs.confirm_ref }}' != '' ]; then |
| 195 |
export TWINE_REPOSITORY=pypi |
| 196 |
export TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }} |
| 197 |
else |
| 198 |
# Exit without deploying |
| 199 |
echo "Don't update wheels" |
| 200 |
exit 0 |
| 201 |
fi |
| 202 |
echo "Deploy to $TWINE_REPOSITORY" |
| 203 |
python -m pip install "twine" |
| 204 |
python -m twine upload --verbose wheels/*.whl wheels/*.tar.gz |