-
Notifications
You must be signed in to change notification settings - Fork 28
179 lines (161 loc) · 5.81 KB
/
Copy pathpython-wheels.yml
File metadata and controls
179 lines (161 loc) · 5.81 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
name: Python wheels
on:
push:
branches: [main]
tags: ["py-v*", "py-test-*"]
pull_request:
branches: [main]
workflow_dispatch: # manual ad-hoc builds from any branch
concurrency:
# Tag pushes get their own group so publishes never get cancelled.
group: >-
${{ github.workflow }}-${{ github.ref }}-${{ startsWith(github.ref, 'refs/tags/') && 'publish' || 'branch' }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build wheel (${{ matrix.target.label }})
runs-on: ${{ matrix.target.runner }}
strategy:
fail-fast: false
matrix:
target:
# `manylinux: "2_28"` makes maturin-action run the build inside the
# official PyPA manylinux_2_28 container (Rocky Linux 8 / glibc 2.28).
# Without this, the build runs on the host (Ubuntu glibc 2.39) and
# produces a wheel that fails the auditwheel manylinux_2_28 check.
- label: linux-x86_64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
manylinux: "2_28"
- label: macos-universal2
runner: macos-latest
target: universal2-apple-darwin
manylinux: "auto"
- label: windows-x86_64
runner: windows-latest
target: x86_64-pc-windows-msvc
manylinux: "auto"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10" # abi3 — any 3.10+ works for building
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target.label == 'macos-universal2' && 'x86_64-apple-darwin,aarch64-apple-darwin' || '' }}
- uses: Swatinem/rust-cache@v2
with:
workspaces: bonsai-py
key: ${{ matrix.target.label }}
- name: Tag/version guard (tag pushes only)
if: startsWith(github.ref, 'refs/tags/')
shell: bash
run: |
tag="${GITHUB_REF#refs/tags/}"
version="${tag#py-v}"
version="${version#py-test-}"
cargo_version=$(grep -m1 '^version' bonsai-py/Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')
if [ "$version" != "$cargo_version" ]; then
echo "::error::Tag version '$version' does not match Cargo.toml version '$cargo_version'."
exit 1
fi
- uses: PyO3/maturin-action@v1
with:
working-directory: bonsai-py
command: build
target: ${{ matrix.target.target }}
manylinux: ${{ matrix.target.manylinux }}
args: --release --out dist --strip
- name: Verify wheel (Linux/macOS only — Windows venv quirks)
if: matrix.target.runner != 'windows-latest'
shell: bash
run: |
python -m venv .venv-test
source .venv-test/bin/activate
pip install --upgrade pip
pip install pytest pytest-timeout mypy
pip install bonsai-py/dist/*.whl
pytest bonsai-py/tests/
- name: Wheel size sanity (Linux/macOS only)
if: matrix.target.runner != 'windows-latest'
shell: bash
run: |
size=$(stat -c%s bonsai-py/dist/*.whl 2>/dev/null || stat -f%z bonsai-py/dist/*.whl)
ceiling=$((5 * 1024 * 1024))
if [ "$size" -gt "$ceiling" ]; then
echo "::error::Wheel size $size exceeds 5MB ceiling."
exit 1
fi
echo "Wheel size: $size bytes (under 5MB ceiling)."
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.target.label }}
path: bonsai-py/dist/*.whl
retention-days: ${{ startsWith(github.ref, 'refs/tags/') && 90 || 14 }}
sdist:
name: Build sdist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: PyO3/maturin-action@v1
with:
working-directory: bonsai-py
command: sdist
args: --out dist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: bonsai-py/dist/*.tar.gz
retention-days: ${{ startsWith(github.ref, 'refs/tags/') && 90 || 14 }}
verify-sdist:
name: Verify sdist builds from source
needs: sdist
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: dtolnay/rust-toolchain@stable
- uses: actions/download-artifact@v4
with:
name: sdist
path: dist
- name: Install + smoke-test from sdist
run: |
python -m venv .venv-sdist
source .venv-sdist/bin/activate
pip install --upgrade pip
pip install --no-binary :all: dist/*.tar.gz
python -c "import bonsai_py; print(bonsai_py.__version__)"
publish:
name: Publish to PyPI / TestPyPI
needs: [build, sdist, verify-sdist]
if: startsWith(github.ref, 'refs/tags/py-v') || startsWith(github.ref, 'refs/tags/py-test-')
runs-on: ubuntu-latest
environment:
name: ${{ startsWith(github.ref, 'refs/tags/py-test-') && 'testpypi' || 'pypi' }}
permissions:
id-token: write # OIDC for Trusted Publishing
steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: wheel-*
merge-multiple: true
- uses: actions/download-artifact@v4
with:
name: sdist
path: dist
- name: List artifacts to publish
run: ls -la dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: >-
${{ startsWith(github.ref, 'refs/tags/py-test-') && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
packages-dir: dist
skip-existing: true