-
Notifications
You must be signed in to change notification settings - Fork 86
251 lines (210 loc) · 8.01 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
## These options mostly follow the ones used in
## https://github.com/matplotlib/matplotlib/blob/main/.github/workflows/cibuildwheel.yml, though I
## try to be a little less complicated.
name: tests
on:
push:
branches:
- main
tags: '*'
pull_request:
concurrency:
group: test-${{ github.head_ref }}
cancel-in-progress: true
env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"
jobs:
get_new_version:
name: Get new version number
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.get_version.outputs.new_version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.12'
- name: Install Hatch
shell: bash
run: python -m pip install --disable-pip-version-check --upgrade hatch
- name: Bump version
id: get_version
shell: bash
env:
github_event_head_commit_message: ${{ github.event.head_commit.message }}
run: |
# Note: The following line reads the HEAD commit message to look for an indication of how
# to bump the version number. Specifically, if `#patch`, `#minor`, or `#major` is present
# in the commit message, it bumps the corresponding version number. Those can also be
# prepended as `#premajor`, etc., to add/bump the prerelease modifier. If none of those
# are present, `#patch` is assumed — that is, the lowest-significance number is
# incremented. See the documentation of the `hatch version` command for details.
export version_bump_rule=$(python .github/scripts/parse_bump_rule.py)
echo "version_bump_rule: '${version_bump_rule}'"
hatch version "${version_bump_rule}"
export new_version=$(TERM="unknown" hatch version)
echo "new_version: '${new_version}'"
echo "new_version=${new_version}" >> "$GITHUB_OUTPUT" # Save variable for later steps
build_wheels:
needs: get_new_version
name: Build wheels on ${{ matrix.os }} for ${{matrix.archs}}
runs-on: ${{ matrix.os }}
if: >-
!contains(github.event.head_commit.message, '[skip ci]')
&& !contains(github.event.head_commit.message, '[skip tests]')
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
archs: ["auto"]
include:
- os: ubuntu-latest
archs: "aarch64"
env:
CIBW_ARCHS: ${{matrix.archs}}
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
CIBW_BEFORE_BUILD: python -c "print(('#'*130+'\n')*10)" && python -m pip install "numpy>=2.0,<3"
CIBW_TEST_REQUIRES: pytest pytest-cov
CIBW_TEST_COMMAND: "pytest {project}/tests"
CIBW_SKIP: "*-win32 *-manylinux_i686 cp36-* cp37-* cp38-* cp39-* pp* *-musllinux* cp313-*"
# Exclude 32-bit builds: *-win32 *-manylinux_i686
# Exclude python versions not supported by numpy: cp36-* cp37-* cp38-* cp39-* pp*
# Exclude musllinux builds: *-musllinux*
# Exclude python versions not yet supported by numba: cp313-*
# https://numpy.org/neps/nep-0029-deprecation_policy.html
# https://numba.readthedocs.io/en/stable/user/installing.html#numba-support-info
steps:
- name: Set up QEMU
if: matrix.archs == 'aarch64'
id: qemu
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: "Check out code"
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.12'
- name: Update versions
shell: bash
run: |
export new_version=${{needs.get_new_version.outputs.new_version}}
echo "Updating version to '${new_version}'"
python .github/scripts/update_versions.py
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
python -m pip install cibuildwheel
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v3 # Don't upgrade to v4 until each artifact is named
with:
path: ./wheelhouse/*.whl
build_sdist:
needs: get_new_version
name: Build source distribution
runs-on: ubuntu-latest
if: >-
!contains(github.event.head_commit.message, '[skip ci]')
&& !contains(github.event.head_commit.message, '[skip tests]')
steps:
- name: 'Check out code'
uses: actions/checkout@v4
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.12'
- name: Update versions
shell: bash
run: |
export new_version=${{needs.get_new_version.outputs.new_version}}
echo "Updating version to '${new_version}'"
python .github/scripts/update_versions.py
- name: Build sdist
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade "setuptools>=61" wheel "numpy>=2.0,<3"
python setup.py sdist
- uses: actions/upload-artifact@v3 # Don't upgrade to v4 until each artifact is named
with:
path: dist/*.tar.gz
upload_pypi:
needs: [get_new_version, build_wheels, build_sdist]
name: Tag and release
runs-on: ubuntu-latest
if: >-
github.ref == 'refs/heads/main'
&& !contains(github.event.head_commit.message, '[no release]')
&& (success() || contains(github.event.head_commit.message, '[skip tests]'))
environment: release
permissions: write-all
# actions: write
# checks: write
# contents: write
# deployments: write
# id-token: write
# issues: write
# discussions: write
# packages: write
# pages: write
# pull-requests: write
# repository-projects: write
# security-events: write
# statuses: write
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/download-artifact@v3 # Don't upgrade to v4 until each artifact is named
with:
name: artifact
path: dist
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.12'
- name: Install Hatch
shell: bash
run: python -m pip install --disable-pip-version-check --upgrade hatch
- name: Update versions
shell: bash
run: |
export new_version=${{needs.get_new_version.outputs.new_version}}
echo "Updating version to '${new_version}'"
python .github/scripts/update_versions.py
- name: Tag and push new version
shell: bash
run: |
export new_version=${{needs.get_new_version.outputs.new_version}}
git config user.name github-actions
git config user.email github-actions@github.com
git commit -m "Update version for new release" pyproject.toml setup.py src/quaternion/__init__.py
git tag -a "v${new_version}" -m "Version ${new_version}"
git status
git push --follow-tags # Will not trigger new workflow because it uses GITHUB_TOKEN
- name: Create release
if: "!contains(github.event.head_commit.message, '[no release]')"
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.get_new_version.outputs.new_version }}
name: Release v${{ needs.get_new_version.outputs.new_version }}
draft: false
prerelease: false
- name: Publish to PyPI
if: "!contains(github.event.head_commit.message, '[no pypi]')"
env:
# 1) Get key from https://pypi.org/manage/account/token/
# 2) Copy it to Github > repo > Settings > Secrets
HATCH_INDEX_USER: __token__
HATCH_INDEX_AUTH: ${{ secrets.PYPI_TOKEN }}
shell: bash
run: |
hatch publish