Repository navigation
257 lines (232 loc) · 10.2 KB
/
Copy pathpython-tests.yaml
File metadata and controls
257 lines (232 loc) · 10.2 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
name: Python Tests
on:
workflow_dispatch:
pull_request:
merge_group:
permissions:
contents: read
pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
jobs:
changes:
if: github.repository_owner == 'jumpstarter-dev'
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.filter.outputs.python }}
renode_driver: ${{ steps.filter.outputs.renode_driver }}
python-versions: ${{ steps.matrix.outputs.python-versions }}
runners: ${{ steps.matrix.outputs.runners }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4
id: filter
with:
base: ${{ github.base_ref || github.event.merge_group.base_ref || 'main' }}
# Required for the '!...' exclusion patterns below to work; with the
# default 'some' quantifier a negated pattern matches every file it
# does NOT cover, so docs-only PRs would still trigger the tests.
predicate-quantifier: some-with-excludes
filters: |
python:
- 'python/**'
- '!python/**/*.md'
- '.github/workflows/python-tests.yaml'
renode_driver:
- 'python/packages/jumpstarter-driver-renode/**'
- name: Compute test matrix
id: matrix
run: |
# PRs: test only Python 3.14 on Linux to save CI time.
# Merge queue and workflow_dispatch run the full matrix
# (all Python versions on both Linux and macOS).
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo 'python-versions=["3.14"]' >> "$GITHUB_OUTPUT"
echo 'runners=["ubuntu-24.04"]' >> "$GITHUB_OUTPUT"
else
echo 'python-versions=["3.12", "3.13", "3.14"]' >> "$GITHUB_OUTPUT"
echo 'runners=["ubuntu-24.04", "macos-15"]' >> "$GITHUB_OUTPUT"
fi
pytest-matrix:
needs: changes
if: needs.changes.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ${{ matrix.runs-on }}
env:
# renovate: datasource=custom.fedora-cloud-qcow2 depName=fedora-cloud-base-generic
FEDORA_CLOUD_VERSION: 43-1.6
# Extra headroom for uv lock resolution; constraint-dependencies in
# python/pyproject.toml now steer the resolver to cp314-wheel versions,
# but keep a generous timeout as a safety net.
UV_LOCK_TIMEOUT: 1800
strategy:
matrix:
runs-on: ${{ fromJson(needs.changes.outputs.runners) }}
# Floor: oldest Python in supported platforms (RHEL 9 appstream)
# Ceiling: newest Python in latest Fedora
# Review on each RHEL/Fedora release
# PRs run only 3.14 on Linux; merge queue runs all versions
# on both Linux and macOS.
python-version: ${{ fromJson(needs.changes.outputs.python-versions) }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Free up runner disk space
uses: mathio/gha-cleanup@aca3d43a05bf564f5fc69acb929a65b01797f22b # v1.1.2
with:
remove-browsers: true
verbose: true
- id: uv
run: echo "version=$(cat .uv-version)" >> "$GITHUB_OUTPUT"
- name: Install uv
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
with:
version: ${{ steps.uv.outputs.version }}
python-version: ${{ matrix.python-version }}
- name: Install Qemu (Linux)
if: runner.os == 'Linux'
run: |
echo <<EOF | sudo tee /etc/udev/rules.d/99-kvm.rules
KERNEL=="kvm", GROUP="kvm", MODE="0666"
KERNEL=="vhost-vsock", GROUP="kvm", MODE="0666"
KERNEL=="vhost-net", GROUP="kvm", MODE="0666"
EOF
sudo udevadm control --reload-rules
sudo modprobe vhost_vsock
sudo modprobe vhost_net
sudo chmod 0666 /dev/kvm /dev/vhost-vsock /dev/vhost-net
sudo apt-get update
sudo apt-get install -y qemu-system-arm qemu-system-x86 rpm2cpio cpio
- name: Install libgpiod-dev (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libgpiod-dev liblgpio-dev
- name: Install nftables and dnsmasq (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y nftables dnsmasq-base isc-dhcp-client dnsutils
- name: Load kernel modules for DUT network tests (Linux)
if: runner.os == 'Linux'
run: |
for mod in veth bridge nf_nat nf_conntrack nft_masq nft_nat nft_chain_nat; do
sudo modprobe "$mod" 2>/dev/null || true
done
- name: Install Renode (Linux)
if: runner.os == 'Linux'
env:
# renovate: datasource=github-releases depName=renode/renode
RENODE_VERSION: v1.17.0
run: |
RENODE_TAG="${RENODE_VERSION#v}"
wget "https://github.com/renode/renode/releases/download/${RENODE_VERSION}/renode_${RENODE_TAG}_amd64.deb" -O /tmp/renode.deb
sudo apt-get install -y /tmp/renode.deb
- name: Install Qemu (macOS)
if: runner.os == 'macOS'
run: |
brew install qemu
# Homebrew Renode is slow (~5+ minutes per job). Install on macOS only when this run
# touches the Renode driver, or on workflow_dispatch (full manual run). Linux still
# installs Renode from the .deb in all jobs (fast).
- name: Install Renode (macOS)
if: >-
runner.os == 'macOS'
&& (needs.changes.outputs.renode_driver == 'true'
|| github.event_name == 'workflow_dispatch')
run: |
brew trust renode/tap
brew install renode/tap/renode
- name: Cache Fedora Cloud images
id: cache-fedora-cloud-images
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: python/packages/jumpstarter-driver-qemu/images
key: fedora-cloud-${{ env.FEDORA_CLOUD_VERSION }}
- name: Download Fedora Cloud images
if: steps.cache-fedora-cloud-images.outputs.cache-hit != 'true'
run: |
FEDORA_RELEASE="${FEDORA_CLOUD_VERSION%%-*}"
for arch in aarch64 x86_64; do
curl -L --fail --output "python/packages/jumpstarter-driver-qemu/images/Fedora-Cloud-Base-Generic-${FEDORA_CLOUD_VERSION}.${arch}.qcow2" \
"https://iad.mirror.rackspace.com/fedora/releases/${FEDORA_RELEASE}/Cloud/${arch}/images/Fedora-Cloud-Base-Generic-${FEDORA_CLOUD_VERSION}.${arch}.qcow2"
done
- name: Verify uv.lock is up-to-date
working-directory: python
run: |
uv lock --check
- name: Run pytest
working-directory: python
env:
PYTEST_ADDOPTS: "--cov-report=xml --log-level=CRITICAL --log-cli-level=CRITICAL"
run: |
make test -j4 LOGS_DIR=${{ runner.temp }}/test-logs
- name: Upload test logs
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: test-logs-${{ matrix.runs-on }}-py${{ matrix.python-version }}
path: ${{ runner.temp }}/test-logs/
if-no-files-found: ignore
retention-days: 7
# Diff-coverage is only checked on Linux. Several packages (e.g.
# jumpstarter-driver-dut-network) are Linux-only, so their tests are
# entirely skipped on macOS, making all changed lines appear uncovered
# and dragging diff-coverage below the threshold. Linux runners already
# enforce the 80% gate, so nothing is lost.
- name: Check coverage on changed lines
if: github.event_name == 'pull_request' && runner.os == 'Linux'
working-directory: python
run: |
coverage_files=$(find packages ../docs/source/reference -name coverage.xml 2>/dev/null | sort)
if [ -z "$coverage_files" ]; then
echo "::error::No coverage.xml files found"
exit 1
fi
uv run diff-cover $coverage_files --compare-branch=origin/${{ github.base_ref }} --fail-under=80 --exclude '*_pb2.py' '*_pb2_grpc.py' '**/conftest.py' '**/test_*.py' '**/*_test.py'
# Verify jumpstarter-all resolves under plain pip, the resolver end users get
# via install.sh. Runs on PRs too (unlike pytest-matrix, which only tests
# Python 3.14 on PRs).
pip-resolution:
needs: changes
if: needs.changes.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-26.04
strategy:
matrix:
python-version: ["3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
# Full history so hatch-vcs derives the same versions as elsewhere.
fetch-depth: 0
- id: uv
run: echo "version=$(cat .uv-version)" >> "$GITHUB_OUTPUT"
- name: Install uv
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
with:
version: ${{ steps.uv.outputs.version }}
python-version: ${{ matrix.python-version }}
- name: Verify plain-pip dependency resolution
working-directory: python
run: |
make build
uv venv --python "${{ matrix.python-version }}" --seed .pip-resolve
# By path: dev versions are pre-releases, so a bare name would resolve to PyPI's release
./.pip-resolve/bin/python -m pip install --dry-run --find-links dist dist/jumpstarter_all-*.whl
# https://github.com/orgs/community/discussions/26822
pytest:
runs-on: ubuntu-latest
needs: [changes, pytest-matrix, pip-resolution]
if: ${{ always() }}
steps:
- run: exit 1
# Fail on failures or cancellations, but allow skips when no relevant changes
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
|| (contains(needs.*.result, 'skipped') && needs.changes.outputs.should_run == 'true')
}}