-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (144 loc) · 4.93 KB
/
python-tests.yml
File metadata and controls
171 lines (144 loc) · 4.93 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
name: Python Tests
on:
push:
branches: [ main, develop, 'cursor/**' ]
paths:
- 'software/**'
- '.github/workflows/python-tests.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'software/**'
- '.github/workflows/python-tests.yml'
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black mypy pylint
- name: Lint with flake8
working-directory: software/driver
run: |
# Stop the build if there are Python syntax errors or undefined names
flake8 pico_fan_hub --count --select=E9,F63,F7,F82 --show-source --statistics
# Exit-zero treats all errors as warnings
flake8 pico_fan_hub --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Check Code Formatting with Black
working-directory: software/driver
run: |
black --check --diff pico_fan_hub
- name: Type Check with mypy
working-directory: software/driver
continue-on-error: true
run: |
mypy pico_fan_hub --ignore-missing-imports
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y libhidapi-hidraw0 libhidapi-libusb0
- name: Install Python Dependencies
working-directory: software/driver
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-cov pytest-mock
- name: Run Unit Tests
working-directory: software/driver
run: |
pytest --cov=pico_fan_hub --cov-report=xml --cov-report=term
continue-on-error: true
- name: Upload Coverage to Codecov
if: matrix.python-version == '3.10'
uses: codecov/codecov-action@v5
with:
file: software/driver/coverage.xml
flags: unittests
name: codecov-umbrella
continue-on-error: true
- name: Test Installation
run: |
which pico-fan-hub || echo "pico-fan-hub not in PATH"
which pico-fan-ctl || echo "pico-fan-ctl not in PATH"
python -c "import pico_fan_hub; print(pico_fan_hub.__version__)"
- name: Generate Test Summary
run: |
echo "## Python Tests Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Python Version: ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Tests completed!" >> $GITHUB_STEP_SUMMARY
build:
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Install Build Dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel setuptools
- name: Build Package
working-directory: software/driver
run: |
python -m build
- name: Verify Build
working-directory: software/driver
run: |
ls -lh dist/
test -f dist/*.whl || exit 1
test -f dist/*.tar.gz || exit 1
- name: Upload Package Artifacts
uses: actions/upload-artifact@v6
with:
name: python-packages
path: software/driver/dist/*
retention-days: 90
- name: Generate Build Summary
run: |
echo "## Python Package Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Build Artifacts:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
ls -lh software/driver/dist/ >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Package build successful!" >> $GITHUB_STEP_SUMMARY