Skip to content

Commit 93f0d98

Browse files
authored
chore(ci): speed up CI with uvx semantic-release, xdist, and uv caching (#1083)
* chore(ci): parallelize tests, cache uv, and run semantic-release via uvx * chore(ci): centralize CI version variables with comments * chore(ci): drop unused SEMANTIC_RELEASE_VERSION env var
1 parent 186bab8 commit 93f0d98

3 files changed

Lines changed: 64 additions & 30 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ concurrency:
1010
group: ${{ github.head_ref || github.run_id }}
1111
cancel-in-progress: true
1212

13+
env:
14+
# Default Python version for tooling jobs (lint, build, test-release)
15+
DEFAULT_PYTHON_VERSION: "3.11"
16+
# Matrix Python version that collects branch coverage and uploads to Codecov
17+
COVERAGE_PYTHON_VERSION: "3.14"
18+
1319
jobs:
1420
# Make sure commit messages follow the conventional commits convention:
1521
# https://www.conventionalcommits.org
@@ -27,16 +33,17 @@ jobs:
2733
- uses: actions/checkout@v6
2834
- uses: actions/setup-python@v6
2935
with:
30-
python-version: "3.11"
36+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
3137
- uses: pre-commit/action@v3.0.1
3238

3339
test:
3440
strategy:
3541
fail-fast: false
3642
matrix:
43+
# Keep COVERAGE_PYTHON_VERSION in sync with this matrix
3744
python-version:
38-
- "3.11"
39-
- "3.14"
45+
- "3.11" # Minimum supported Python version
46+
- "3.14" # Latest supported Python version (coverage)
4047
runs-on: ubuntu-latest
4148
steps:
4249
- uses: actions/checkout@v6
@@ -45,11 +52,14 @@ jobs:
4552
with:
4653
python-version: ${{ matrix.python-version }}
4754
activate-environment: true
48-
- run: uv pip install pip
55+
enable-cache: true
4956
- name: Test with Pytest
50-
run: uv run pytest --log-cli-level=DEBUG -vv -s --cov --cov-branch --cov-report=xml
57+
run: >-
58+
uv run pytest -n auto
59+
${{ matrix.python-version == env.COVERAGE_PYTHON_VERSION && '--cov --cov-branch --cov-report=xml' || '' }}
5160
shell: bash
5261
- name: Upload results to Codecov
62+
if: matrix.python-version == env.COVERAGE_PYTHON_VERSION
5363
uses: codecov/codecov-action@v5
5464
with:
5565
token: ${{ secrets.CODECOV_TOKEN }}
@@ -59,9 +69,10 @@ jobs:
5969
strategy:
6070
fail-fast: false
6171
matrix:
72+
# Keep COVERAGE_PYTHON_VERSION in sync with this matrix
6273
python-version:
63-
- "3.11"
64-
- "3.14"
74+
- "3.11" # Minimum supported Python version
75+
- "3.14" # Latest supported Python version (coverage)
6576
runs-on: ubuntu-latest
6677
services:
6778
emqx:
@@ -70,19 +81,23 @@ jobs:
7081
- 1888:1883
7182
options: >-
7283
--health-cmd "/opt/emqx/bin/emqx ctl status"
73-
--health-interval 5s
84+
--health-interval 1s
7485
--health-timeout 25s
75-
--health-retries 5
86+
--health-retries 25
7687
steps:
7788
- uses: actions/checkout@v6
7889
- name: Set up uv
7990
uses: astral-sh/setup-uv@v7
8091
with:
8192
python-version: ${{ matrix.python-version }}
8293
activate-environment: true
94+
enable-cache: true
8395
- name: Test MQTT with Pytest
84-
run: uv run pytest -m mqtt_broker --log-cli-level=DEBUG -vv -s --cov --cov-branch --cov-report=xml
96+
run: >-
97+
uv run pytest -m mqtt_broker
98+
${{ matrix.python-version == env.COVERAGE_PYTHON_VERSION && '--cov --cov-branch --cov-report=xml' || '' }}
8599
- name: Upload results to Codecov
100+
if: matrix.python-version == env.COVERAGE_PYTHON_VERSION
86101
uses: codecov/codecov-action@v5
87102
with:
88103
token: ${{ secrets.CODECOV_TOKEN }}
@@ -97,8 +112,9 @@ jobs:
97112
- name: Set up uv
98113
uses: astral-sh/setup-uv@v7
99114
with:
100-
python-version: "3.11"
115+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
101116
activate-environment: true
117+
enable-cache: true
102118
- name: Build package
103119
run: uv build
104120

@@ -111,32 +127,25 @@ jobs:
111127
- uses: actions/checkout@v6
112128
with:
113129
fetch-depth: 0
130+
- name: Set up uv
131+
uses: astral-sh/setup-uv@v7
132+
with:
133+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
134+
enable-cache: true
114135
- name: Setup Git for Semantic Release Testing
115136
run: |
116137
# Setup a temp branch to test
117138
git checkout -B temp-main-branch
118139
git merge ${{ github.event.pull_request.head.sha }} --no-edit
119140
git config user.name "GitHub Actions"
120141
git config user.email "actions@github.com"
121-
- name: Test Semantic Release (No-op)
122-
id: test-release
123-
uses: python-semantic-release/python-semantic-release@v10.5.3
124-
with:
125-
github_token: ${{ secrets.GITHUB_TOKEN }}
126-
changelog: true
127-
# Use noop mode to test without making changes
128-
no_operation_mode: true
129142
- name: Test Semantic Release (Dry Run)
130-
id: test-release-dry
131-
uses: python-semantic-release/python-semantic-release@v10.5.3
132-
with:
133-
github_token: ${{ secrets.GITHUB_TOKEN }}
134-
changelog: true
135-
# Use dry run mode to test without committing
136-
commit: false
137-
tag: false
138-
push: false
139-
vcs_release: false
143+
env:
144+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145+
# Keep version in sync with python-semantic-release action in the release job
146+
run: >-
147+
uv tool run --from python-semantic-release==10.5.3
148+
semantic-release version --changelog --no-commit --no-tag --no-push --no-vcs-release
140149
release:
141150
runs-on: ubuntu-latest
142151
needs:

‎pyproject.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ dev = [
7070
"syrupy>=4.9.1,<6",
7171
"pdoc>=15.0.4,<17",
7272
"pytest-cov>=7.0.0",
73+
"pytest-xdist>=3.8.0",
7374
"zmqtt>=0.2.0,<0.3.0",
7475
"pytest-benchmark>=5.1.0",
7576
]
@@ -87,7 +88,7 @@ build-backend = "hatchling.build"
8788
[tool.semantic_release]
8889
branch = "main"
8990
version_toml = ["pyproject.toml:project.version"]
90-
build_command = "pip install uv && uv lock --upgrade-package python-roborock && git add uv.lock && uv build"
91+
build_command = "(command -v uv >/dev/null || pip install uv) && uv lock --upgrade-package python-roborock && git add uv.lock && uv build"
9192
changelog_file = 'CHANGELOG.md'
9293
commit = true
9394

‎uv.lock‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)