-
Notifications
You must be signed in to change notification settings - Fork 55
321 lines (272 loc) · 12.2 KB
/
pytest.yml
File metadata and controls
321 lines (272 loc) · 12.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
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
name: Pytest
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#packaging-workflow-data-as-artifacts
on:
pull_request:
paths:
- '**/*.py' # Watch for changes in any Python files
- 'pyproject.toml' # Watch for changes in the pyproject.toml file
- '.github/workflows/pytest.yml'
push:
branches:
- master # Only run on push to master branch
paths:
- '**/*.py' # Watch for changes in any Python files
- 'pyproject.toml' # Watch for changes in the pyproject.toml file
- '.github/workflows/pytest.yml'
workflow_dispatch:
release:
types: [published]
permissions:
contents: read
jobs:
pytest:
if: github.event_name == 'pull_request' || (github.event_name == 'push' && !github.event.pull_request) || github.event_name == 'workflow_dispatch'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# python-version: ["3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
os: [ubuntu-latest]
python-version: ["3.9", "3.14", "3.14t"]
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
# https://docs.astral.sh/uv/guides/integration/github/
- name: Install uv and set the Python version
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
with:
python-version: ${{ matrix.python-version }}
activate-environment: true
- name: Install system dependencies for GUI testing
run: |
sudo apt-get update
sudo apt-get install -y python3-tk scrot xdotool x11-utils gnome-screenshot tcl8.6 tk8.6 libtcl8.6 libtk8.6
- name: Ensure Tcl/Tk search paths
run: |
echo "TCL_LIBRARY=/usr/share/tcltk/tcl8.6" >> $GITHUB_ENV
echo "TK_LIBRARY=/usr/share/tcltk/tk8.6" >> $GITHUB_ENV
- name: Install dependencies and application
# without --editable, the coverage report is not generated correctly
run: |
uv pip install --editable .[dev,ci_headless_tests]
- name: Download ArduCopter SITL (if available)
run: |
# Create cache key based on current quarter (YYYY-Q)
CURRENT_YEAR=$(date +%Y)
CURRENT_MONTH=$(date +%m)
QUARTER=$(( (CURRENT_MONTH-1)/3 + 1 ))
CACHE_KEY="${CURRENT_YEAR}-Q${QUARTER}"
echo "Cache key: ${CACHE_KEY}"
# Check if we have cached SITL files for this quarter
if [ -d "sitl-cache/${CACHE_KEY}" ] && [ -f "sitl-cache/${CACHE_KEY}/arducopter" ]; then
echo "Using cached SITL files from ${CACHE_KEY}"
mkdir -p sitl/
cp sitl-cache/${CACHE_KEY}/* sitl/
else
echo "Downloading fresh SITL files for ${CACHE_KEY}"
mkdir -p sitl/ sitl-cache/${CACHE_KEY}/
# Download latest ArduCopter SITL from official firmware server
curl -L -o sitl/arducopter https://firmware.ardupilot.org/Copter/latest/SITL_x86_64_linux_gnu/arducopter
curl -L -o sitl/firmware-version.txt https://firmware.ardupilot.org/Copter/latest/SITL_x86_64_linux_gnu/firmware-version.txt
curl -L -o sitl/git-version.txt https://firmware.ardupilot.org/Copter/latest/SITL_x86_64_linux_gnu/git-version.txt
# Cache the downloaded files
cp sitl/* sitl-cache/${CACHE_KEY}/
fi
# Make executable and verify
chmod +x sitl/arducopter
ls -la sitl/
# Set environment variables
echo "SITL_BINARY=$(pwd)/sitl/arducopter" >> $GITHUB_ENV
echo "SITL_AVAILABLE=true" >> $GITHUB_ENV
echo "SITL version: $(cat sitl/git-version.txt)"
echo "Firmware version: $(cat sitl/firmware-version.txt)"
continue-on-error: true
- name: Cache SITL files
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
path: sitl-cache/
key: sitl-cache-${{ github.run_id }}
restore-keys: |
sitl-cache-
- name: Test with pytest
id: pytest
continue-on-error: false
run: |
export LIBGL_ALWAYS_SOFTWARE=1
export DISPLAY=:99
# disable X authentication
export XAUTHORITY=/dev/null
# disable access control restrictions
Xvfb :99 -screen 0 1024x768x16 -ac &
# ensure Xvfb is fully started before running tests
sleep 2
if [ "$SITL_AVAILABLE" = "true" ]; then
echo "Running tests with SITL support"
uv run pytest --cov=ardupilot_methodic_configurator --cov-report=xml:tests/coverage.xml --md=tests/results-${{ matrix.python-version }}.md --junit-xml=tests/results-junit.xml -m "sitl or not sitl"
else
echo "Running tests without SITL (mocked tests only)"
uv run pytest --cov=ardupilot_methodic_configurator --cov-report=xml:tests/coverage.xml --md=tests/results-${{ matrix.python-version }}.md --junit-xml=tests/results-junit.xml -m "not sitl"
fi
- name: Fix coverage paths
run: |
sed -i 's|<package name="." |<package name="ardupilot_methodic_configurator" |' tests/coverage.xml
sed -i 's|<source>.*</source>|<source>.</source>|' tests/coverage.xml
sed -i 's|filename="|filename="ardupilot_methodic_configurator/|g' tests/coverage.xml
shell: bash
- name: Display test results as GitHub job summary
run: cat tests/results-${{ matrix.python-version }}.md >> $GITHUB_STEP_SUMMARY
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload coverage xml report
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: coverage-${{ matrix.python-version }}-xml
path: tests/*.xml
retention-days: 1
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload coverage report
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: coverage-${{ matrix.python-version }}
path: .coverage
include-hidden-files: true
retention-days: 1
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
upload_coverage_to_coveralls:
if: (github.event_name == 'push' && github.ref == 'refs/heads/master') && (success() || failure())
runs-on: ubuntu-latest
needs: pytest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Download coverage xml report
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: coverage-3.9-xml
- name: Upload coverage xml report to coveralls.io
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
files: coverage.xml
# TODO: create a badge that presents the result of the Upload coverage xml report step
check_coverage:
if: success() || failure()
runs-on: ubuntu-latest
needs: pytest # This will ensure this job runs after 'pytest'
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Download coverage report
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: coverage-3.9
# https://docs.astral.sh/uv/guides/integration/github/
- name: Install uv and set the Python version
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
with:
python-version: '3.9' # Match with the coverage report Python version
activate-environment: true
- name: Install dependencies
run: |
uv pip install .[dev]
- name: Check coverage
run: |
# Check if pytest job failed
if [ "${{ needs.pytest.result }}" == "failure" ]; then
echo "Pytest failed - failing coverage check"
exit 1
fi
coverage report --fail-under=89
publish-test-results:
if: always()
name: "Publish Tests Results"
runs-on: ubuntu-latest
needs: pytest # This will ensure this job runs after 'pytest'
permissions:
checks: write
# only needed unless run with comment_mode: off
pull-requests: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Download Artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
path: artifacts
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@27d65e188ec43221b20d26de30f4892fad91df2f # v2.22.0
id: test-results
with:
files: "artifacts/**/results-junit.xml"
- name: Set badge color
shell: bash
run: |
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
success)
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
;;
failure)
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
;;
neutral)
echo "BADGE_COLOR=696969" >> $GITHUB_ENV
;;
esac
- name: Create badge
uses: emibcn/badge-action@808173dd03e2f30c980d03ee49e181626088eee8
with:
label: Tests
status: '${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests }} tests, ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.runs }} runs: ${{ fromJSON( steps.test-results.outputs.json ).conclusion }}'
color: ${{ env.BADGE_COLOR }}
path: badge.svg
- name: Upload badge to Gist
# Upload only for master branch
if: >
github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'master' ||
github.event_name != 'workflow_run' && github.ref == 'refs/heads/master'
uses: andymckay/append-gist-action@ab30bf28df67017c7ad696500b218558c7c04db3
with:
token: ${{ secrets.GIST_TOKEN }}
gistURL: https://gist.githubusercontent.com/amilcarlucas/81b511dc0ff92b8072613d1cd100832e
file: badge.svg
add_coverage_to_pullrequest:
if: github.event_name == 'pull_request' && (success() || failure())
runs-on: ubuntu-latest
needs: pytest # This will ensure this job runs after 'pytest'
permissions:
contents: read
pull-requests: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Download coverage xml report
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: coverage-3.9-xml
- name: Get Cover
uses: orgoro/coverage@3f13a558c5af7376496aa4848bf0224aead366ac # v3.2
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
thresholdAll: 0.89