-
Notifications
You must be signed in to change notification settings - Fork 18
359 lines (295 loc) · 11.2 KB
/
ci-multiplatform.yml
File metadata and controls
359 lines (295 loc) · 11.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
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
name: CI Multi-Platform
on:
push:
branches: [main]
paths-ignore:
- '**.md'
- 'images/**'
pull_request:
branches: [main]
paths-ignore:
- '**.md'
- 'images/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
DEFAULT_PYTHON: "3.12"
SRC_DIR: src/nmea_gps_emulator
TEST_DIR: tests
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: 'pip'
- name: Install linters
run: pip install ruff mypy
- name: Run ruff check
run: ruff check ${{ env.SRC_DIR }} ${{ env.TEST_DIR }}
- name: Run ruff format check
run: ruff format --check ${{ env.SRC_DIR }} ${{ env.TEST_DIR }}
- name: Run mypy
run: mypy ${{ env.SRC_DIR }} --ignore-missing-imports
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: 'pip'
- name: Install dependencies
run: |
pip install -e .
pip install pip-audit
- name: Run pip-audit
run: pip-audit
- name: Check for secrets (Gitleaks)
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test:
needs: lint
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.12", "3.13"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-cov
- name: Run tests with coverage
run: pytest ${{ env.TEST_DIR }} -v --cov=${{ env.SRC_DIR }} --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: coverage.xml
fail_ci_if_error: false
flags: ${{ matrix.os }}-py${{ matrix.python-version }}
name: ${{ matrix.os }}-py${{ matrix.python-version }}
token: ${{ secrets.CODECOV_TOKEN }}
# Platform-specific smoke tests
platform-smoke-tests:
needs: test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: 'pip'
- name: Install package
run: pip install -e .
- name: Test CLI help (Unix)
if: runner.os != 'Windows'
run: |
nmea-gps-emulator --help
python -m nmea_gps_emulator --help
- name: Test CLI help (Windows)
if: runner.os == 'Windows'
run: |
nmea-gps-emulator --help
python -m nmea_gps_emulator --help
- name: Test CLI flags (Unix)
if: runner.os != 'Windows'
run: |
# Test --quiet flag
python -m nmea_gps_emulator --quiet --help
echo "[OK] --quiet flag works"
# Test --verbose flag
python -m nmea_gps_emulator --verbose --help
echo "[OK] --verbose flag works"
# Test short flags
python -m nmea_gps_emulator -q --help
echo "[OK] -q flag works"
python -m nmea_gps_emulator -v --help
echo "[OK] -v flag works"
- name: Test CLI flags (Windows)
if: runner.os == 'Windows'
run: |
# Test --quiet flag
python -m nmea_gps_emulator --quiet --help
echo "[OK] --quiet flag works"
# Test --verbose flag
python -m nmea_gps_emulator --verbose --help
echo "[OK] --verbose flag works"
# Test short flags
python -m nmea_gps_emulator -q --help
echo "[OK] -q flag works"
python -m nmea_gps_emulator -v --help
echo "[OK] -v flag works"
- name: Test conflicting flags (Unix)
if: runner.os != 'Windows'
run: |
# Test that --quiet and --verbose together fails with exit code 1
if python -m nmea_gps_emulator --quiet --verbose 2>&1; then
echo "[FAIL] Conflicting flags should be rejected"
exit 1
else
echo "[OK] Conflicting flags properly rejected (exit code: $?)"
fi
- name: Test conflicting flags (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
# Test that --quiet and --verbose together fails with exit code 1
if python -m nmea_gps_emulator --quiet --verbose 2>&1; then
echo "[FAIL] Conflicting flags should be rejected"
exit 1
else
echo "[OK] Conflicting flags properly rejected"
fi
- name: Verify imports
run: |
python -c "from nmea_gps_emulator.nmea_gps import NmeaMsg; print('[OK] NmeaMsg import successful')"
python -c "from nmea_gps_emulator.main import Menu; print('[OK] Menu import successful')"
python -c "from nmea_gps_emulator.utils import position_input; print('[OK] Utils import successful')"
python -c "from nmea_gps_emulator.custom_thread import NmeaSrvThread; print('[OK] Thread classes import successful')"
- name: Test NMEA message generation (Unix)
if: runner.os != 'Windows'
run: |
python -c "
from nmea_gps_emulator.nmea_gps import NmeaMsg
# Create NMEA object with test data
position = {
'latitude_value': '5430.000',
'latitude_direction': 'N',
'longitude_value': '01920.000',
'longitude_direction': 'E'
}
nmea = NmeaMsg(position=position, altitude=100.0, speed=10.0, heading=90.0)
# Generate one set of sentences
sentences = next(nmea)
# Verify we got sentences
assert len(sentences) > 0, 'No NMEA sentences generated'
# Verify sentence format (should start with $ and contain *)
for sentence_obj in sentences:
sentence = str(sentence_obj) # Convert object to string
assert sentence.startswith('$'), f'Invalid sentence format: {sentence}'
assert '*' in sentence, f'Missing checksum in: {sentence}'
print(f'[OK] Generated {len(sentences)} valid NMEA sentences')
"
- name: Test NMEA message generation (Windows)
if: runner.os == 'Windows'
run: |
python -c "from nmea_gps_emulator.nmea_gps import NmeaMsg; position = {'latitude_value': '5430.000', 'latitude_direction': 'N', 'longitude_value': '01920.000', 'longitude_direction': 'E'}; nmea = NmeaMsg(position=position, altitude=100.0, speed=10.0, heading=90.0); sentences = next(nmea); assert len(sentences) > 0; sentence_strs = [str(s) for s in sentences]; assert all(s.startswith('$') and '*' in s for s in sentence_strs); print(f'[OK] Generated {len(sentences)} valid NMEA sentences')"
- name: Test input validation functions (Unix)
if: runner.os != 'Windows'
run: |
python -c "
import re
from nmea_gps_emulator.utils import position_input, heading_input, speed_input
# Test position regex
position_regex = re.compile(
r'^(([0-8]\d[0-5]\d|9000)(N|S|n|s)\s?(([0-1][0-7]\d[0-5]\d)|(0[0-9]\d[0-5]\d)|18000)(E|W|e|w))$',
re.VERBOSE
)
assert position_regex.match('5430N 01920E'), 'Position regex failed'
print('[OK] Position validation regex works')
# Test heading regex
heading_regex = re.compile(r'(3[0-5]\d|[0-2]\d{2}|\d{1,2})')
assert heading_regex.fullmatch('90'), 'Heading regex failed'
assert heading_regex.fullmatch('359'), 'Heading regex failed'
print('[OK] Heading validation regex works')
# Test speed regex
speed_regex = re.compile(r'(\d{1,3}(\.\d+)?)')
assert speed_regex.fullmatch('10.5'), 'Speed regex failed'
assert speed_regex.fullmatch('999'), 'Speed regex failed'
print('[OK] Speed validation regex works')
"
- name: Test input validation functions (Windows)
if: runner.os == 'Windows'
run: |
python -c "import re; position_regex = re.compile(r'^(([0-8]\d[0-5]\d|9000)(N|S|n|s)\s?(([0-1][0-7]\d[0-5]\d)|(0[0-9]\d[0-5]\d)|18000)(E|W|e|w))$', re.VERBOSE); assert position_regex.match('5430N 01920E'); print('[OK] Input validation works')"
- name: Check platform detection (Unix)
if: runner.os != 'Windows'
run: |
python -c "
import platform
print(f'Platform: {platform.system()}')
print(f'Python: {platform.python_version()}')
print(f'Architecture: {platform.machine()}')
"
- name: Check platform detection (Windows)
if: runner.os == 'Windows'
run: |
python -c "import platform; print(f'Platform: {platform.system()}'); print(f'Python: {platform.python_version()}'); print(f'Architecture: {platform.machine()}')"
build:
needs: [lint, test, platform-smoke-tests]
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: 'pip'
- name: Install build tools
run: pip install build
- name: Build package
run: python -m build
- name: Verify wheel installation (Unix)
if: runner.os != 'Windows'
run: |
pip install dist/*.whl
nmea-gps-emulator --help
- name: Verify wheel installation (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
pip install dist/*.whl
nmea-gps-emulator --help
- name: Upload build artifacts
uses: actions/upload-artifact@v6
with:
name: dist-${{ matrix.os }}
path: dist/
retention-days: 7
# Summary job to check overall status
ci-success:
needs: [lint, security, test, platform-smoke-tests, build]
runs-on: ubuntu-latest
if: always()
steps:
- name: Check CI status
run: |
if [ "${{ needs.lint.result }}" != "success" ] || \
[ "${{ needs.security.result }}" != "success" ] || \
[ "${{ needs.test.result }}" != "success" ] || \
[ "${{ needs.platform-smoke-tests.result }}" != "success" ] || \
[ "${{ needs.build.result }}" != "success" ]; then
echo "❌ CI failed"
exit 1
else
echo "✅ All CI checks passed"
fi