-
Notifications
You must be signed in to change notification settings - Fork 7
304 lines (270 loc) · 8.9 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
name: Build
on:
push:
branches:
- main # allow to trigger the workflow with tag push event
pull_request:
paths:
- setup.py
- setup.cfg
- pyproject.toml
- MANIFEST.in
- CMakeLists.txt
- include/**
- src/**
- optree/version.py
- .github/workflows/build.yml
release:
types:
- published
# Allow to trigger the workflow manually
workflow_dispatch:
inputs:
task:
description: "Task type"
type: choice
options:
- build-only
- build-and-publish
required: true
permissions:
contents: read
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build-sdist:
name: Build sdist
runs-on: ubuntu-latest
if: github.repository == 'metaopt/optree' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.7 - 3.13"
update-environment: true
- name: Upgrade pip
run: |
python -m pip install --upgrade pip setuptools wheel pybind11
- name: Set __release__
if: |
startsWith(github.ref, 'refs/tags/') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.task == 'build-and-publish')
run: |
python .github/workflows/set_release.py
- name: Print version
run: python setup.py --version
- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel build
- name: Build sdist
run: python -m build --sdist
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
if-no-files-found: error
build-wheels:
name: Build wheels for Python ${{ matrix.python-version }} on ${{ matrix.os }} (${{ matrix.archs }})
runs-on: ${{ matrix.os }}
needs: [build-sdist]
if: github.repository == 'metaopt/optree' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version:
["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.9", "pypy-3.10"]
archs: [
# Generic
"auto",
# Linux
"aarch64",
"ppc64le",
"s390x",
# Windows
"ARM64",
]
include:
- os: macos-13
python-version: "3.7"
archs: "auto"
exclude:
- os: ubuntu-latest
archs: "ARM64"
- os: windows-latest
archs: "aarch64"
- os: windows-latest
archs: "ppc64le"
- os: windows-latest
archs: "s390x"
- os: macos-latest
archs: "aarch64"
- os: macos-latest
archs: "ppc64le"
- os: macos-latest
archs: "s390x"
- os: macos-latest
archs: "ARM64"
- os: ubuntu-latest
python-version: "pypy-3.9"
archs: "ppc64le"
- os: ubuntu-latest
python-version: "pypy-3.10"
archs: "ppc64le"
- os: ubuntu-latest
python-version: "pypy-3.9"
archs: "s390x"
- os: ubuntu-latest
python-version: "pypy-3.10"
archs: "s390x"
- os: windows-latest
python-version: "3.7"
archs: "ARM64"
- os: windows-latest
python-version: "3.8"
archs: "ARM64"
- os: windows-latest
python-version: "pypy-3.9"
archs: "ARM64"
- os: windows-latest
python-version: "pypy-3.10"
archs: "ARM64"
- os: macos-latest
python-version: "3.7"
fail-fast: false
timeout-minutes: 180
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
update-environment: true
allow-prereleases: true
- name: Upgrade pip
run: |
python -m pip install --upgrade pip setuptools wheel pybind11
- name: Set __release__
if: |
startsWith(github.ref, 'refs/tags/') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.task == 'build-and-publish')
run: python .github/workflows/set_release.py
- name: Print version
run: python setup.py --version
- name: Set CIBW_BUILD
run: python .github/workflows/set_cibw_build.py
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD: ${{ env.CIBW_BUILD }}
CIBW_ARCHS: ${{ matrix.archs }}
CIBW_ARCHS_MACOS: ${{ matrix.archs }} universal2
with:
package-dir: .
output-dir: wheelhouse
config-file: "{package}/pyproject.toml"
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.archs }}
path: wheelhouse/*.whl
if-no-files-found: error
list-artifacts:
name: List artifacts
runs-on: ubuntu-latest
needs: [build-sdist, build-wheels]
if: github.repository == 'metaopt/optree' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
timeout-minutes: 15
steps:
- name: Download built sdist
uses: actions/download-artifact@v4
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: sdist
path: dist
- name: Download built wheels
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: List distributions
run: ls -lh dist/*
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: dist/*
if-no-files-found: error
publish:
runs-on: ubuntu-latest
needs: [list-artifacts]
if: |
github.repository == 'metaopt/optree' && github.event_name != 'pull_request' &&
(github.event_name != 'workflow_dispatch' || github.event.inputs.task == 'build-and-publish') &&
(github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
if: startsWith(github.ref, 'refs/tags/')
with:
python-version: "3.7 - 3.13"
update-environment: true
- name: Upgrade pip
run: |
python -m pip install --upgrade pip setuptools wheel pybind11
- name: Set __release__
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
run: |
python .github/workflows/set_release.py
- name: Print version
run: python setup.py --version
- name: Check consistency between the package version and release tag
if: startsWith(github.ref, 'refs/tags/')
run: |
PACKAGE_VER="v$(python setup.py --version)"
RELEASE_TAG="${GITHUB_REF#refs/*/}"
if [[ "${PACKAGE_VER}" != "${RELEASE_TAG}" ]]; then
echo "package ver. (${PACKAGE_VER}) != release tag. (${RELEASE_TAG})"
exit 1
fi
- name: Download built artifacts
uses: actions/download-artifact@v4
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifacts
path: dist
- name: List distributions
run: ls -lh dist/*
- name: Publish to TestPyPI
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TESTPYPI_UPLOAD_TOKEN }}
repository-url: https://test.pypi.org/legacy/
verbose: true
print-hash: true
skip-existing: true
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
verbose: true
print-hash: true
skip-existing: true