Debian Codegraph @

.github/workflows/ci.yml

raw
1 name: CI
2
3 on:
4 push:
5 branches:
6 - main
7 pull_request:
8
9 concurrency:
10 group: ${{ github.head_ref || github.run_id }}
11 cancel-in-progress: true
12
13 env:
14 POETRY_VIRTUALENVS_IN_PROJECT: "true"
15 UV_PYTHON_PREFERENCE: only-managed
16 UV_VERSION: "0.11.16"
17
18 jobs:
19 lint:
20 runs-on: ubuntu-latest
21 steps:
22 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
23 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v5
24 with:
25 python-version: 3.13
26 - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
27
28 # Make sure the PR title follows the conventional commits convention:
29 # https://www.conventionalcommits.org
30 # PRs are squash-merged, so the PR title becomes the commit on main and
31 # drives python-semantic-release's version bump.
32 pr-title:
33 name: Lint PR Title
34 runs-on: ubuntu-latest
35 if: github.event_name == 'pull_request'
36 permissions:
37 pull-requests: read
38 steps:
39 - uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
40 env:
41 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42 with:
43 subjectPattern: ^(?![A-Z]).+$
44 subjectPatternError: |
45 The subject "{subject}" found in the pull request title "{title}"
46 didn't match the configured pattern. Please ensure that the subject
47 starts with a lowercase character.
48
49 test:
50 strategy:
51 fail-fast: false
52 matrix:
53 python-version:
54 - "3.11"
55 - "3.12"
56 - "3.13"
57 - "3.14"
58 - "3.14t"
59 os:
60 - ubuntu-latest
61 - macOS-latest
62 - windows-latest
63 extension:
64 - "skip_cython"
65 - "use_cython"
66 runs-on: ${{ matrix.os }}
67 steps:
68 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
69 - name: Set up uv and Python ${{ matrix.python-version }}
70 id: python
71 uses: ./.github/actions/setup-uv-python
72 with:
73 uv-version: ${{ env.UV_VERSION }}
74 python-version: ${{ matrix.python-version }}
75 - name: Install poetry
76 run: uv tool install poetry
77 shell: bash
78 - name: Cache poetry venv
79 id: cache-venv
80 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
81 with:
82 path: |
83 .venv
84 src/habluetooth/**/*.so
85 key: venv-v3-${{ runner.os }}-py${{ steps.python.outputs.python-version }}-${{ matrix.extension }}-${{ hashFiles('poetry.lock', 'pyproject.toml', 'build_ext.py', 'src/habluetooth/**/*.py', 'src/habluetooth/**/*.pxd') }}
86 - name: Install Dependencies
87 if: steps.cache-venv.outputs.cache-hit != 'true'
88 env:
89 PYTHON_VERSION: ${{ matrix.python-version }}
90 run: |
91 poetry env use "$(uv python find "${PYTHON_VERSION}")"
92 if [ "${{ matrix.extension }}" = "skip_cython" ]; then
93 SKIP_CYTHON=1 poetry install --only=main,dev
94 else
95 REQUIRE_CYTHON=1 poetry install --only=main,dev
96 fi
97 shell: bash
98 - name: Test with Pytest
99 run: poetry run pytest --cov-report=xml
100 shell: bash
101 - name: Upload coverage to Codecov
102 uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v5
103 with:
104 token: ${{ secrets.CODECOV_TOKEN }}
105
106 benchmark:
107 # Keep actions/setup-python here so codspeed history stays comparable;
108 # astral's managed Python ships PGO/LTO/BOLT/mimalloc which would shift
109 # the baseline.
110 runs-on: ubuntu-latest
111 steps:
112 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
113 - name: Set up uv
114 uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
115 with:
116 enable-cache: true
117 - name: Install poetry
118 run: uv tool install poetry
119 - name: Setup Python 3.14
120 id: setup-python
121 uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v5
122 with:
123 python-version: "3.14"
124 cache: "poetry"
125 allow-prereleases: true
126 - name: Cache poetry venv
127 id: cache-venv
128 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
129 with:
130 path: |
131 .venv
132 src/habluetooth/**/*.so
133 key: venv-v2-${{ runner.os }}-benchmark-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock', 'pyproject.toml', 'build_ext.py', 'src/habluetooth/**/*.py', 'src/habluetooth/**/*.pxd') }}
134 - name: Install Dependencies
135 if: steps.cache-venv.outputs.cache-hit != 'true'
136 run: |
137 REQUIRE_CYTHON=1 poetry install --only=main,dev
138 shell: bash
139 - name: Run benchmarks
140 uses: CodSpeedHQ/action@373d6868929f444bc08d901fd0eb0ad52a8875ea # v3
141 with:
142 token: ${{ secrets.CODSPEED_TOKEN }}
143 run: poetry run pytest --no-cov -vvvvv --codspeed
144 mode: instrumentation
145
146 # Dry run on PRs and non-main pushes. No environment, no publish
147 # permissions, no OIDC, so PR runs carry no release blast radius.
148 release-dry-run:
149 needs:
150 - test
151 - lint
152 if: github.ref_name != 'main'
153 runs-on: ubuntu-latest
154 permissions:
155 contents: read
156 steps:
157 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
158 with:
159 fetch-depth: 0
160 ref: ${{ github.ref }}
161 - name: Create local branch name
162 env:
163 BRANCH: ${{ github.head_ref || github.ref_name }}
164 run: git switch -C "$BRANCH"
165 - name: Test release
166 uses: python-semantic-release/python-semantic-release@9a026e9303981c866c3425723009becb2437c757 # v10.6.2
167 with:
168 no_operation_mode: true
169
170 # Real release, only on main. The release environment and write/OIDC
171 # permissions are scoped to this job so they never apply to PR runs.
172 release:
173 needs:
174 - test
175 - lint
176 if: github.ref_name == 'main'
177 runs-on: ubuntu-latest
178 environment: release
179 concurrency:
180 group: release-${{ github.ref }}
181 cancel-in-progress: false
182 permissions:
183 id-token: write
184 contents: write
185 outputs:
186 released: ${{ steps.release.outputs.released }}
187 newest_release_tag: ${{ steps.release.outputs.tag }}
188
189 steps:
190 # Mint a short-lived installation token for the release-bot GitHub
191 # App, which is in the main ruleset's bypass_actors list so PSR's
192 # version-bump commit/tag push isn't blocked by required checks.
193 # Per PSR's docs, the same token must be passed to actions/checkout
194 # (via `token`) so its persisted http.extraheader doesn't override
195 # PSR's URL-embedded auth at push time and re-attribute the push
196 # to github-actions[bot].
197 - name: Generate release App token
198 id: app-token
199 uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
200 with:
201 app-id: ${{ secrets.RELEASE_APP_ID }}
202 private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
203
204 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
205 with:
206 fetch-depth: 0
207 ref: ${{ github.ref }}
208 token: ${{ steps.app-token.outputs.token || github.token }}
209
210 - name: Create local branch name
211 env:
212 BRANCH: ${{ github.ref_name }}
213 run: git switch -C "$BRANCH"
214
215 # On main branch: actual PSR + upload to PyPI & GitHub
216 - name: Release
217 uses: python-semantic-release/python-semantic-release@9a026e9303981c866c3425723009becb2437c757 # v10.6.2
218 id: release
219 with:
220 github_token: ${{ steps.app-token.outputs.token }}
221
222 - name: Publish package distributions to PyPI
223 uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1
224 if: steps.release.outputs.released == 'true'
225
226 - name: Publish package distributions to GitHub Releases
227 uses: python-semantic-release/upload-to-gh-release@0a92b5d7ebfc15a84f9801ebd1bf706343d43711 # main
228 if: steps.release.outputs.released == 'true'
229 with:
230 github_token: ${{ steps.app-token.outputs.token }}
231
232 build_wheels:
233 needs: [release]
234 if: needs.release.outputs.released == 'true'
235 name: Wheels for ${{ matrix.os }} (${{ matrix.musl == 'musllinux' && 'musllinux' || 'manylinux' }}) ${{ matrix.qemu }} ${{ matrix.pyver }}
236 runs-on: ${{ matrix.os }}
237 strategy:
238 matrix:
239 os: [windows-latest, ubuntu-24.04-arm, ubuntu-latest, macos-latest]
240 qemu: [""]
241 musl: [""]
242 pyver: [""]
243 include:
244 - os: ubuntu-latest
245 musl: "musllinux"
246 - os: ubuntu-24.04-arm
247 musl: "musllinux"
248 # qemu is slow, make a single
249 # runner per Python version
250 - os: ubuntu-latest
251 qemu: armv7l
252 musl: "musllinux"
253 pyver: cp311
254 - os: ubuntu-latest
255 qemu: armv7l
256 musl: "musllinux"
257 pyver: cp312
258 - os: ubuntu-latest
259 qemu: armv7l
260 musl: "musllinux"
261 pyver: cp313
262 - os: ubuntu-latest
263 qemu: armv7l
264 musl: "musllinux"
265 pyver: cp314
266 - os: ubuntu-latest
267 qemu: armv7l
268 musl: "musllinux"
269 pyver: cp314t
270 # qemu is slow, make a single
271 # runner per Python version
272 - os: ubuntu-latest
273 qemu: armv7l
274 musl: ""
275 pyver: cp311
276 - os: ubuntu-latest
277 qemu: armv7l
278 musl: ""
279 pyver: cp312
280 - os: ubuntu-latest
281 qemu: armv7l
282 musl: ""
283 pyver: cp313
284 - os: ubuntu-latest
285 qemu: armv7l
286 musl: ""
287 pyver: cp314
288 - os: ubuntu-latest
289 qemu: armv7l
290 musl: ""
291 pyver: cp314t
292 steps:
293 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
294 with:
295 ref: ${{ needs.release.outputs.newest_release_tag }}
296 fetch-depth: 0
297 # Used to host cibuildwheel
298 - name: Set up Python
299 uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v5
300 with:
301 python-version: "3.12"
302 - name: Set up QEMU
303 if: ${{ matrix.qemu }}
304 uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0
305 with:
306 platforms: all
307 # This should be temporary
308 # xref https://github.com/docker/setup-qemu-action/issues/188
309 # xref https://github.com/tonistiigi/binfmt/issues/215
310 image: tonistiigi/binfmt:qemu-v8.1.5
311 id: qemu
312 - name: Prepare emulation
313 if: ${{ matrix.qemu }}
314 run: |
315 if [[ -n "${{ matrix.qemu }}" ]]; then
316 # Build emulated architectures only if QEMU is set,
317 # use default "auto" otherwise
318 echo "CIBW_ARCHS_LINUX=${{ matrix.qemu }}" >> $GITHUB_ENV
319 fi
320 - name: Limit to a specific Python version on slow QEMU
321 if: ${{ matrix.pyver }}
322 run: |
323 if [[ -n "${{ matrix.pyver }}" ]]; then
324 echo "CIBW_BUILD=${{ matrix.pyver }}-*" >> $GITHUB_ENV
325 fi
326 - name: Build wheels
327 uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0
328 env:
329 CIBW_SKIP: cp36-* cp37-* cp38-* cp39-* cp310-* pp* ${{ matrix.musl == 'musllinux' && '*manylinux*' || '*musllinux*' }}
330 REQUIRE_CYTHON: 1
331
332 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v4
333 with:
334 name: wheels-${{ matrix.os }}-${{ matrix.musl }}-${{ matrix.pyver }}-${{ matrix.qemu }}
335 path: ./wheelhouse/*.whl
336
337 upload_pypi:
338 needs: [build_wheels]
339 runs-on: ubuntu-latest
340 environment: release
341 permissions:
342 id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
343
344 steps:
345 - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v4
346 with:
347 # unpacks default artifact into dist/
348 # if `name: artifact` is omitted, the action will create extra parent dir
349 path: dist
350 pattern: wheels-*
351 merge-multiple: true
352
353 - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2