Repository navigation
458 lines (406 loc) · 15.6 KB
/
Copy pathrelease.yml
File metadata and controls
458 lines (406 loc) · 15.6 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
target:
description: "Release target. 'all' publishes Rust and Python; 'python' publishes Python only; 'rust' publishes Rust crates only."
required: true
default: all
type: choice
options:
- all
- python
- rust
version:
description: "Release version without the v prefix (for example 0.3.0)"
required: true
type: string
publish:
description: "Publish crates to crates.io. Only allowed from main. PyPI uploads happen only on a published GitHub release."
required: false
default: false
type: boolean
# A release and a manual run for the same target and version must not race.
# The python- and rust- prefixes keep a one-language run from colliding with an all run.
concurrency:
group: release-${{ github.event.release.tag_name || format('{0}v{1}', inputs.target != 'all' && format('{0}-', inputs.target) || '', inputs.version) }}
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
PYTHONUNBUFFERED: "1"
permissions:
contents: read
jobs:
validate-version:
name: Validate release version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check.outputs.version }}
tag: ${{ steps.check.outputs.tag }}
target: ${{ steps.check.outputs.target }}
python_version: ${{ steps.check.outputs.python_version }}
steps:
- uses: actions/checkout@v4
with:
# Release ancestry needs the tag commit and origin/main history.
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Check tag, Cargo manifests, and pyproject
id: check
env:
EVENT_NAME: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
INPUT_TARGET: ${{ inputs.target || 'all' }}
INPUT_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "release" ]; then
python scripts/release/check_versions.py \
--tag "$RELEASE_TAG" \
--github-output "$GITHUB_OUTPUT"
else
python scripts/release/check_versions.py \
--version "$INPUT_VERSION" \
--target "$INPUT_TARGET" \
--github-output "$GITHUB_OUTPUT"
fi
- name: Require the release tag to be on main
if: github.event_name == 'release'
env:
TAG: ${{ steps.check.outputs.tag }}
run: |
set -euo pipefail
tag="$TAG"
if ! printf '%s' "$tag" | grep -Eq \
'^(python-|rust-)?v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?$'; then
echo "::error::validated version did not form a safe release tag: $tag"
exit 1
fi
git fetch --no-tags origin \
+refs/heads/main:refs/remotes/origin/main \
"+refs/tags/$tag:refs/tags/$tag"
tagged=$(git rev-list -n 1 "refs/tags/$tag")
if ! git merge-base --is-ancestor "$tagged" refs/remotes/origin/main; then
echo "::error::release tag $tag is not an ancestor of origin/main"
exit 1
fi
echo "release tag $tag is on origin/main"
- name: Unit-test the release helpers
run: python scripts/release/test_release_scripts.py
- name: Reject PyPI publish on a manual run
if: github.event_name == 'workflow_dispatch' && steps.check.outputs.target == 'python' && inputs.publish
env:
TARGET: ${{ steps.check.outputs.target }}
run: |
echo "::error::publish=true is not allowed for target=$TARGET; PyPI uploads happen only on a published GitHub release"
exit 1
- name: Reject publish from a non-main ref
if: github.event_name == 'workflow_dispatch' && inputs.publish && github.ref != 'refs/heads/main'
env:
REF: ${{ github.ref }}
run: |
echo "::error::publish=true is only allowed from refs/heads/main; this run is $REF"
exit 1
build-wheels:
name: Build and smoke wheels (${{ matrix.artifact }})
needs: validate-version
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
manylinux: auto
artifact: linux-x86_64
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
manylinux: "2_28"
artifact: linux-aarch64
- os: macos-15-intel
target: x86_64-apple-darwin
manylinux: auto
artifact: macos-x86_64
- os: macos-15
target: aarch64-apple-darwin
manylinux: auto
artifact: macos-aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
manylinux: auto
artifact: windows-x86_64
steps:
- uses: actions/checkout@v4
# Native builds need every interpreter on PATH. The manylinux container
# has its own interpreters, but the host still needs these for smoke tests.
- name: Set up Python 3.10 through 3.14
uses: actions/setup-python@v5
with:
python-version: |
3.10
3.11
3.12
3.13
3.14
- name: Install uv
uses: astral-sh/setup-uv@v10.3.3
with:
enable-cache: false
- name: Install the five smoke-test interpreters
run: uv python install 3.10 3.11 3.12 3.13 3.14
- name: Build native wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: >-
--release --locked --out dist
--interpreter 3.10 3.11 3.12 3.13 3.14
--compatibility pypi
manylinux: ${{ matrix.manylinux }}
working-directory: crates/tokie-python
rust-toolchain: stable
- name: Verify exactly one wheel per supported Python
env:
VERSION: ${{ needs.validate-version.outputs.python_version }}
# Windows defaults to pwsh, which needs $env:VERSION. Run under Git Bash
# so the shared "$VERSION" expansion works on every matrix entry.
shell: bash
run: >-
python scripts/release/smoke_wheel.py verify-set
--dir crates/tokie-python/dist
--expected-version "$VERSION"
- name: Install and smoke every wheel in a matching venv
env:
VERSION: ${{ needs.validate-version.outputs.python_version }}
# Same pwsh caveat as above: this step expands "$VERSION" in bash.
shell: bash
run: >-
python scripts/release/smoke_wheel.py install-all
--dir crates/tokie-python/dist
--expected-version "$VERSION"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.artifact }}
path: crates/tokie-python/dist/*.whl
if-no-files-found: error
build-pyemscripten:
name: Build PyEmscripten wheel (Pyodide ${{ matrix.python-version }})
needs: validate-version
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.14"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install pyodide-build
run: pip install pyodide-build
- name: Get pyodide config
id: pyodide_config
run: |
echo "rust_toolchain=$(pyodide config get rust_toolchain)" >> "$GITHUB_OUTPUT"
echo "emscripten_version=$(pyodide config get emscripten_version)" >> "$GITHUB_OUTPUT"
echo "pyodide_abi_version=$(pyodide config get pyodide_abi_version)" >> "$GITHUB_OUTPUT"
echo "rustflags=$(pyodide config get rustflags)" >> "$GITHUB_OUTPUT"
- uses: emscripten-core/setup-emsdk@v16
with:
version: ${{ steps.pyodide_config.outputs.emscripten_version }}
- name: Build PyEmscripten wheel
uses: PyO3/maturin-action@v1
env:
CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUSTFLAGS: ${{ steps.pyodide_config.outputs.rustflags }}
MATURIN_PYEMSCRIPTEN_PLATFORM_VERSION: ${{ steps.pyodide_config.outputs.pyodide_abi_version }}
with:
target: wasm32-unknown-emscripten
args: >-
--release --locked --out dist
--interpreter ${{ matrix.python-version }}
--no-default-features
working-directory: crates/tokie-python
rust-toolchain: ${{ steps.pyodide_config.outputs.rust_toolchain }}
- name: Upload PyEmscripten wheel
uses: actions/upload-artifact@v4
with:
name: wheels-pyemscripten-${{ matrix.python-version }}
path: crates/tokie-python/dist/*.whl
if-no-files-found: error
smoke-pyemscripten:
name: Smoke PyEmscripten wheel in Pyodide
needs: [validate-version, build-pyemscripten]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.14"
- name: Install pyodide-build
run: pip install pyodide-build
- name: Create Pyodide venv
run: pyodide venv .venv-pyodide
- name: Download PyEmscripten wheel
uses: actions/download-artifact@v4
with:
name: wheels-pyemscripten-3.14
path: dist
# The Pyodide venv's pip is the supported way to install a Pyodide
# package. --only-binary stops pip from trying to compile NumPy for the
# host, which would produce the wrong artifact.
- name: Install NumPy from the Pyodide package index
run: |
source .venv-pyodide/bin/activate
pip install --only-binary=:all: numpy
# NumPy is already installed, so tokie can be installed without allowing
# pip to resolve a second, native NumPy wheel.
- name: Install the tokie wheel
run: |
source .venv-pyodide/bin/activate
wheel=$(ls dist/*.whl)
pip install --no-deps "$wheel"
- name: Run the functional smoke test
env:
VERSION: ${{ needs.validate-version.outputs.python_version }}
run: |
source .venv-pyodide/bin/activate
wheel=$(ls dist/*.whl)
python scripts/release/smoke_wheel.py check \
--expected-version "$VERSION" \
--wheel "$wheel"
build-sdist:
name: Build and smoke source distribution
needs: validate-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: dtolnay/rust-toolchain@stable
- name: Install uv
uses: astral-sh/setup-uv@v10.3.3
with:
enable-cache: false
- name: Install Python 3.12 for the sdist smoke
run: uv python install 3.12
- name: Build source distribution
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
working-directory: crates/tokie-python
- name: Verify the sdist bundles the workspace crates
env:
VERSION: ${{ needs.validate-version.outputs.python_version }}
run: |
archive=$(ls crates/tokie-python/dist/*.tar.gz)
python scripts/release/smoke_wheel.py verify-sdist \
--archive "$archive" \
--expected-version "$VERSION"
- name: Install the sdist in a clean venv and smoke it
env:
VERSION: ${{ needs.validate-version.outputs.python_version }}
run: |
archive=$(ls crates/tokie-python/dist/*.tar.gz)
py=$(uv python find 3.12)
python scripts/release/smoke_wheel.py install \
--source "$archive" \
--python "$py" \
--expected-version "$VERSION"
- name: Upload source distribution
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: crates/tokie-python/dist/*.tar.gz
if-no-files-found: error
publish-crates:
name: Publish crates to crates.io
needs:
- validate-version
- build-wheels
- build-pyemscripten
- build-sdist
- smoke-pyemscripten
# A published release always publishes Rust crates for an "all" target. A
# manual run publishes only when publish=true and the ref is main. A manual
# preflight never writes, and a Python-only release never touches crates.io.
# A Rust-only release publishes crates and never uploads to PyPI.
if: (needs.validate-version.outputs.target == 'all' || needs.validate-version.outputs.target == 'rust') && (github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish && github.ref == 'refs/heads/main'))
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Probe crates.io for the exact versions
id: probe
env:
VERSION: ${{ needs.validate-version.outputs.version }}
run: |
bash scripts/release/publish_crate.sh probe \
--registry crates-io \
--version "$VERSION"
# OIDC is only needed when a crate is actually missing. An idempotent
# rerun where all exact versions already exist skips this step.
- name: Authenticate to crates.io only when a crate is missing
if: steps.probe.outputs.need_oidc == 'true'
id: auth
uses: rust-lang/crates-io-auth-action@v1
- name: Publish in dependency order
env:
VERSION: ${{ needs.validate-version.outputs.version }}
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
CRATES_IO_TOKEN: ${{ steps.auth.outputs.token }}
run: |
bash scripts/release/publish_crate.sh publish \
--registry crates-io \
--version "$VERSION"
upload-pypi:
name: Upload wheels and sdist to PyPI
needs:
- validate-version
- build-wheels
- build-pyemscripten
- smoke-pyemscripten
- build-sdist
- publish-crates
# PyPI is release-event only. A manual run, with publish true or false,
# never uploads to PyPI. Every artifact job must have succeeded; for a
# Python-only release publish-crates is skipped by design, while an "all"
# release must have published the crates first.
if: >-
always() && !cancelled() && github.event_name == 'release'
&& needs.validate-version.result == 'success'
&& needs.build-wheels.result == 'success'
&& needs.build-pyemscripten.result == 'success'
&& needs.smoke-pyemscripten.result == 'success'
&& needs.build-sdist.result == 'success'
&& ((needs.validate-version.outputs.target == 'all' && needs.publish-crates.result == 'success')
|| (needs.validate-version.outputs.target == 'python' && needs.publish-crates.result == 'skipped'))
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Download all distributions
uses: actions/download-artifact@v4
with:
pattern: wheels-*
merge-multiple: true
path: dist
- name: List distributions
run: ls -l dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: dist/
skip-existing: true