-
-
Notifications
You must be signed in to change notification settings - Fork 98
415 lines (396 loc) Β· 14 KB
/
ci.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
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
name: CI
run-name: "${{ github.event_name == 'workflow_dispatch' && format('CI: {0}', github.ref_name) || '' }}"
on:
push:
branches:
- dev
pull_request:
release:
types: [published]
workflow_dispatch:
env:
ADDITIONAL_PYTHON_VERSIONS: "[]"
concurrency:
group: ${{ github.workflow }}-${{ (github.event_name == 'release' && github.run_id) || github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
info:
name: Collect information & prepare
outputs:
default_python_version: ${{ steps.info.outputs.default_python_version }}
python_versions: ${{ steps.info.outputs.python_versions }}
runs-on: ubuntu-latest
steps:
- name: β€΅οΈ Check out code from GitHub
uses: actions/[email protected]
- name: Collect information
id: info
run: |
default_python_version=$(cat .python-version)
echo "default python version: ${default_python_version}"
echo "default_python_version=${default_python_version}" >> $GITHUB_OUTPUT
# Ensure ADDITIONAL_PYTHON_VERSIONS is properly initialized
ADDITIONAL_PYTHON_VERSIONS=${ADDITIONAL_PYTHON_VERSIONS:-"[]"}
# Check if ADDITIONAL_PYTHON_VERSIONS contains default_python_version
if [[ ! ${ADDITIONAL_PYTHON_VERSIONS} == *"${default_python_version}"* ]]; then
# Handle empty or "[]" case properly
if [[ ${ADDITIONAL_PYTHON_VERSIONS} == "[]" ]]; then
all_python_versions="['${default_python_version}']"
elif [[ -z ${ADDITIONAL_PYTHON_VERSIONS} ]]; then
all_python_versions="['${default_python_version}']"
else
all_python_versions="[${ADDITIONAL_PYTHON_VERSIONS:1:-1}, '${default_python_version}']"
fi
else
all_python_versions="${ADDITIONAL_PYTHON_VERSIONS}"
fi
echo "python_versions: ${all_python_versions}"
echo "python_versions=${all_python_versions}" >> $GITHUB_OUTPUT
- name: π Install uv
uses: astral-sh/setup-uv@v5
- name: Generate requirements files
run: |
uv export --no-hashes --no-dev --group test --no-emit-project > requirements-test.txt
uv export --no-hashes --group dev --no-emit-project > requirements-dev.txt
- name: Upload requirements-test.txt
uses: actions/upload-artifact@v4
with:
name: requirements-test.txt
path: requirements-test.txt
- name: Upload requirements-dev.txt
uses: actions/upload-artifact@v4
with:
name: requirements-dev.txt
path: requirements-dev.txt
python-code-quality:
runs-on: "ubuntu-latest"
name: Check Python code quality
steps:
- name: β€΅οΈ Checkout repository
uses: actions/checkout@v4
- name: π Install uv and Python
uses: astral-sh/setup-uv@v5
- name: π Install the project
run: uv sync --locked --group lint
# Following steps cannot run by pre-commit.ci as repo = local
- name: Run mypy
run: uv run --frozen mypy deebot_client/
- name: Pylint review
run: uv run --frozen pylint deebot_client/**/*.py
- name: Verify no getLogger usages
run: scripts/check_getLogger.sh
rust-code-quality:
runs-on: "ubuntu-latest"
name: Check Rust code quality
env:
RUSTFLAGS: "-Dwarnings"
steps:
- name: β€΅οΈ Checkout repository
uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt,clippy
- name: Rust format
uses: actions-rust-lang/rustfmt@v1
- uses: clechasseur/rs-clippy-check@v4
with:
args: --all-features
tests:
name: Execute tests
runs-on: ubuntu-latest
needs:
- info
- python-code-quality
- rust-code-quality
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(needs.info.outputs.python_versions) }}
steps:
- name: β€΅οΈ Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: π Install uv and Python
uses: astral-sh/setup-uv@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
override: true
components: llvm-tools
cache-key: ${{ matrix.python-version }}
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Download requirements-dev.txt
uses: actions/download-artifact@v4
with:
name: requirements-dev.txt
- name: Prepare env and install requirements
shell: bash
run: |
uv venv -p ${{ matrix.python-version }}
uv pip install --system -r requirements-dev.txt
- name: Execute tests
id: tests
run: |
source .venv/bin/activate
source <(cargo llvm-cov show-env --export-prefix)
export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
export CARGO_INCREMENTAL=1
cargo llvm-cov clean --workspace
cargo test
maturin develop --uv
pytest tests --cov=deebot_client --cov-report xml --junitxml=junit.xml -o junit_family=legacy -v
cargo llvm-cov --no-run --lcov --output-path coverage.lcov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
disable_telem: true
files: coverage.lcov,coverage.xml
- name: Upload test results to Codecov
if: ${{ !cancelled() && steps.tests.outcome == 'success' }}
uses: codecov/test-results-action@v1
with:
fail_ci_if_error: true
verbose: true
build-test-native:
name: ${{ matrix.platform.name }} ${{ matrix.platform.target }} ${{ matrix.python-version }}
runs-on: ${{ matrix.platform.runner }}
needs:
- info
- tests
strategy:
fail-fast: false
matrix:
include:
- name: Linux
manylinux: manylinux_2_34
- name: Macos
pytest_args: -m "not docker"
platform:
- name: Linux
runner: ubuntu-latest
target: x86_64
- name: Linux
runner: ubuntu-24.04-arm
target: aarch64
- name: Windows
runner: windows-latest
target: x64
- name: Macos
runner: macos-13
target: x86_64
- name: Macos
runner: macos-14
target: aarch64
python-version: ${{ fromJSON(needs.info.outputs.python_versions) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ (matrix.platform.name == 'Windows') && matrix.platform.target || '' }}
- name: π Set package version
if: ${{ matrix.platform.name != 'Windows' && github.event_name == 'release' }}
run: |
sed -i.bak "s/^version = \".*\"/version = \"${{ github.event.release.tag_name }}\"/" pyproject.toml && rm pyproject.toml.bak
- name: π Set package version (Windows)
if: ${{ matrix.platform.name == 'Windows' && github.event_name == 'release' }}
run: |
(Get-Content pyproject.toml) -replace 'version = ".*"', 'version = "${{ github.event.release.tag_name }}"' | Set-Content pyproject.toml
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --strip --out dist -i python${{ matrix.python-version }}
sccache: "false"
manylinux: ${{ matrix.manylinux }}
before-script-linux: python3 -m ensurepip
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.platform.name }}-${{ matrix.platform.target }}-${{ matrix.python-version }}
path: dist
- name: π Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Download requirements-test.txt
uses: actions/download-artifact@v4
with:
name: requirements-test.txt
- name: Prepare env and install wheel
shell: bash
run: |
# Remove sources otherwise pytest will complain about missing rust files
rm -rf deebot_client
uv venv -p ${{ matrix.python-version }}
uv pip install -r requirements-test.txt
uv pip install --force-reinstall dist/deebot_client-*.whl
- name: Run pytest
if: ${{ matrix.platform.name != 'Windows' }}
id: pytest
run: |
source .venv/bin/activate
pytest tests -v ${{ matrix.pytest_args || ''}}
- name: Run pytest (windows)
if: ${{ matrix.platform.name == 'Windows' }}
id: pytest_windows
run: |
.venv/Scripts/activate
pytest tests -v -m "not docker"
build-test-musl:
name: Musllinux ${{ matrix.platform.target }} ${{ matrix.python-version }}
runs-on: ${{ matrix.platform.os || 'ubuntu-latest' }}
needs:
- info
- tests
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64
docker_arch: amd64
- target: aarch64
docker_arch: arm64
os: ubuntu-24.04-arm
- target: armv7
docker_arch: arm/v7
os: ubuntu-24.04-arm
qemu: true
- target: x86
docker_arch: 386
qemu: true
python-version: ${{ fromJSON(needs.info.outputs.python_versions) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: π Set package version
if: ${{ github.event_name == 'release' }}
run: |
sed -i "s/^version = \".*\"/version = \"${{ github.event.release.tag_name }}\"/" pyproject.toml
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --strip --out dist -i python${{ matrix.python-version }}
sccache: "false"
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}-${{ matrix.python-version }}
path: dist
- name: Download requirements-test.txt
uses: actions/download-artifact@v4
with:
name: requirements-test.txt
- name: Install Qemu
if: ${{ matrix.platform.qemu || false }}
uses: docker/setup-qemu-action@v3
- name: Install Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
file: ci/Dockerfile.alpine
platforms: linux/${{ matrix.platform.docker_arch }}
push: false
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
tags: deebot_client:${{ matrix.platform.target }}-${{ matrix.python-version }}
- name: Pytest in docker
id: pytest
run: |
docker run --rm -v ${{ github.workspace }}:/github/workspace --platform linux/${{ matrix.platform.docker_arch }} deebot_client:${{ matrix.platform.target }}-${{ matrix.python-version }}
benchmarks:
runs-on: "ubuntu-latest"
name: Run benchmarks
if: ${{ github.event_name != 'release' }}
needs:
- build-test-native
- build-test-musl
- sdist
steps:
- name: β€΅οΈ Checkout repository
uses: actions/checkout@v4
- name: π Install uv
uses: astral-sh/setup-uv@v5
- name: π Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ needs.info.outputs.default_python_version }}
- name: Download requirements-test.txt
uses: actions/download-artifact@v4
with:
name: requirements-test.txt
- name: π Install the project
run: |
uv pip install -e . --system -r requirements-test.txt
- name: Run benchmarks
uses: CodSpeedHQ/action@main
with:
run: pytest tests/ --codspeed
token: ${{ secrets.CODSPEED_TOKEN }}
sdist:
name: Create source distribution
runs-on: ubuntu-latest
needs: tests
steps:
- name: β€΅οΈ Check out code from GitHub
uses: actions/[email protected]
- name: π Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: π Set package version
if: ${{ github.event_name == 'release' }}
run: |
sed -i "s/^version = \".*\"/version = \"${{ github.event.release.tag_name }}\"/" pyproject.toml
- name: π¦ Build source package
run: uv build --sdist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist
release:
name: Releasing to PyPi
if: ${{ github.event_name == 'release' }}
runs-on: ubuntu-latest
needs:
- build-test-native
- build-test-musl
- sdist
environment:
name: release
url: https://pypi.org/p/deebot-client
permissions:
contents: write
id-token: write
steps:
- name: β€΅οΈ Check out code from GitHub
uses: actions/[email protected]
- name: β¬οΈ Download wheels
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: π Publish to PyPi
uses: pypa/[email protected]
with:
verbose: true
print-hash: true
- name: βοΈ Sign published artifacts
uses: sigstore/[email protected]
with:
inputs: ./dist/*.tar.gz ./dist/*.whl
release-signing-artifacts: true