forked from qutip/qutip
-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (177 loc) · 7.13 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Build wheels, optionally deploy to PyPI
on:
workflow_dispatch:
inputs:
confirm_ref:
description: "Confirm chosen branch name to deploy to PyPI (optional):"
default: ""
override_version:
description: "Override version number (optional):"
default: ""
jobs:
# The deploy_test job is part of the test of whether we should deploy to PyPI
# or test.PyPI. The job will succeed if either the confirmation reference is
# empty, 'test' or if the confirmation is the selected branch or tag name.
# It will fail if it is nonempty and does not match. All later jobs depend
# on this job, so that they will be immediately cancelled if the confirmation
# is bad. The dependency is currently necessary (2021-03) because GitHub
# Actions does not have a simpler method of cancelling an entire workflow---
# the normal use-case expects to try and run as much as possible despite one
# or two failures.
deploy_test:
name: Verify PyPI deployment confirmation
runs-on: ubuntu-latest
env:
GITHUB_REF: ${{ github.ref }}
CONFIRM_REF: ${{ github.event.inputs.confirm_ref }}
steps:
- name: Compare confirmation to current reference
shell: bash
run: |
[[ -z $CONFIRM_REF || $GITHUB_REF =~ ^refs/(heads|tags)/$CONFIRM_REF$ || $CONFIRM_REF == "test" ]]
if [[ $CONFIRM_REF == "test" ]]; then
echo "Build and deploy to test.pypi.org."
elif [[ -z $CONFIRM_REF ]]; then
echo "Build only. Nothing will be uploaded to PyPI."
else
echo "Full build and deploy. Wheels and source will be uploaded to PyPI."
fi
build_sdist:
name: Build sdist on Ubuntu
needs: deploy_test
runs-on: ubuntu-latest
env:
OVERRIDE_VERSION: ${{ github.event.inputs.override_version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
name: Install Python
with:
# For the sdist we should be as conservative as possible with our
# Python version. This should be the lowest supported version. This
# means that no unsupported syntax can sneak through.
python-version: '3.10'
- name: Install pip build
run: |
python -m pip install 'build'
- name: Build sdist tarball
shell: bash
run: |
if [[ ! -z "$OVERRIDE_VERSION" ]]; then echo "$OVERRIDE_VERSION" > VERSION; fi
# The build package is the reference PEP 517 package builder. All
# dependencies are specified by our setup code.
python -m build --sdist .
# Zip files are not part of PEP 517, so we need to make our own.
- name: Create zipfile from tarball
shell: bash
working-directory: dist
run: |
# First assert that there is exactly one tarball, and find its name.
shopt -s failglob
tarball_pattern="*.tar.gz"
tarballs=($tarball_pattern)
[[ ${#tarballs[@]} == 1 ]]
tarball="${tarballs[0]}"
# Get the stem and make the zipfile name.
stem="${tarball%.tar.gz}"
zipfile="${stem}.zip"
# Extract the tarball and rezip it.
tar -xzf "$tarball"
zip "$zipfile" -r "$stem"
rm -r "$stem"
- uses: actions/upload-artifact@v4
with:
name: sdist
path: |
dist/*.tar.gz
dist/*.zip
if-no-files-found: error
build_wheels:
name: Build wheels on ${{ matrix.os }}
needs: deploy_test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
env:
# Set up wheels matrix. This is CPython 3.10--3.12 for all OS targets.
CIBW_BUILD: "cp3{10,11,12}-*"
# Numpy and SciPy do not supply wheels for i686 or win32 for
# Python 3.10+, so we skip those:
CIBW_SKIP: "*-musllinux* *-manylinux_i686 *-win32"
OVERRIDE_VERSION: ${{ github.event.inputs.override_version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
name: Install Python
with:
# This is about the build environment, not the released wheel version.
python-version: '3.10'
- name: Install cibuildwheel
run: |
# cibuildwheel does the heavy lifting for us. Tested on
# 2.19, but should be fine at least up to any minor new release.
python -m pip install 'cibuildwheel==2.19.*'
- name: Build wheels
shell: bash
run: |
# If the version override was specified, then write it the VERSION
# file with it.
if [[ ! -z "$OVERRIDE_VERSION" ]]; then echo "$OVERRIDE_VERSION" > VERSION; fi
python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
deploy:
name: "Deploy to PyPI if desired"
needs: [deploy_test, build_sdist, build_wheels]
runs-on: ubuntu-latest
env:
TWINE_USERNAME: __token__
TWINE_NON_INTERACTIVE: 1
steps:
- name: Download build artifacts to local runner
uses: actions/download-artifact@v4
with:
path: wheels
merge-multiple: true
# Check that all .whl, .tar.gz and .zip have been properly build
# and downloaded.
- name: Check wheels
run: |
ls -R wheels
if ! [[ $(ls wheels/*.whl | wc -l) == 9 ]]; then exit 1; fi
if ! ls wheels/*.tar.gz 1> /dev/null 2>&1; then exit 1; fi
if ! ls wheels/*.zip 1> /dev/null 2>&1; then exit 1; fi
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.10'
- name: Verify this is not a dev version
shell: bash
run: |
python -m pip install wheels/*-cp310-cp310-manylinux*.whl
python -c 'import qutip; print(qutip.__version__); assert "dev" not in qutip.__version__; assert "+" not in qutip.__version__'
# We built the zipfile for convenience distributing to Windows users on
# our end, but PyPI only needs the tarball.
- name: Upload sdist and wheels to PyPI
run: |
# The confirmation is tested explicitly in `deploy_test`, so we know
# it is either a missing confirmation (so we shouldn't run this job),
# 'test' or a valid confirmation. We don't need to retest the value
# of the confirmation, beyond checking that one existed.
if [ '${{ github.event.inputs.confirm_ref }}' == 'test' ]; then
export TWINE_REPOSITORY=testpypi
export TWINE_PASSWORD=${{ secrets.TESTPYPI_TOKEN }}
elif [ '${{ github.event.inputs.confirm_ref }}' != '' ]; then
export TWINE_REPOSITORY=pypi
export TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }}
else
# Exit without deploying
echo "Don't update wheels"
exit 0
fi
echo "Deploy to $TWINE_REPOSITORY"
python -m pip install "twine"
python -m twine upload --verbose wheels/*.whl wheels/*.tar.gz