-
Notifications
You must be signed in to change notification settings - Fork 13
261 lines (226 loc) · 7.66 KB
/
Copy pathci.yml
File metadata and controls
261 lines (226 loc) · 7.66 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
name: CI/CD Pipeline
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:
# Cancel in-progress runs when a new run is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Quick validation checks that can fail fast
validate:
name: Validation Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate manifest.json
run: |
python3 -c "
import json
import sys
with open('custom_components/mitsubishi/manifest.json') as f:
manifest = json.load(f)
# Check required keys
required = ['domain', 'name', 'version', 'requirements', 'codeowners']
missing = [k for k in required if k not in manifest]
if missing:
print(f'❌ Missing required keys: {missing}')
sys.exit(1)
# Check key order (domain, name, then alphabetical)
keys = list(manifest.keys())
if keys[0] != 'domain' or keys[1] != 'name':
print('❌ Keys must start with domain, name')
sys.exit(1)
print('✅ Manifest structure valid')
"
- name: Validate strings.json
run: |
python3 -c "
import json
with open('custom_components/mitsubishi/strings.json') as f:
strings = json.load(f)
print('✅ Strings JSON valid')
"
- name: Validate YAML files
run: |
pip install pyyaml
python3 -c "
import yaml
import glob
for file in glob.glob('.github/workflows/*.yml'):
with open(file) as f:
yaml.safe_load(f)
print('✅ All YAML files valid')
"
# Linting and formatting checks (can run in parallel)
lint:
name: Lint & Format
runs-on: ubuntu-latest
needs: validate # Only run if validation passes
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.cache/pre-commit
key: lint-${{ runner.os }}-${{ hashFiles('**/requirements*.txt', '.pre-commit-config.yaml') }}
restore-keys: |
lint-${{ runner.os }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff mypy pre-commit
pip install -r requirements.txt
- name: Run ruff check
run: |
ruff check custom_components tests --output-format=github
- name: Run ruff format check
run: |
ruff format custom_components tests --check
- name: Run pre-commit hooks
run: |
pre-commit run --all-files --show-diff-on-failure
# Type checking (can run in parallel)
type-check:
name: Type Checking
runs-on: ubuntu-latest
needs: validate # Only run if validation passes
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: mypy-${{ runner.os }}-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
mypy-${{ runner.os }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Install homeassistant first to get its dependencies
pip install homeassistant
# Then install mypy and other dev dependencies
pip install mypy
# Install types-requests with compatible urllib3
pip install "types-requests<2.32.0.20240712"
pip install -r requirements.txt
- name: Run mypy
run: |
mypy custom_components/mitsubishi \
--ignore-missing-imports \
--no-warn-unused-ignores \
--show-error-codes
# Tests with coverage (matrix for multiple Python versions)
test:
name: Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
needs: validate # Only run if validation passes
strategy:
fail-fast: false # Don't cancel other matrix jobs if one fails
matrix:
python-version: ["3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: test-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
test-${{ runner.os }}-${{ matrix.python-version }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-homeassistant-custom-component pytest-cov pytest-asyncio
pip install -r requirements.txt
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi
- name: Run tests with coverage
run: |
pytest tests/ \
--cov=custom_components/mitsubishi \
--cov-report=xml \
--cov-report=term-missing:skip-covered \
--cov-fail-under=85 \
-v
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.python-version == '3.12'
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
# Home Assistant specific validation
ha-validate:
name: Home Assistant Validation
runs-on: ubuntu-latest
needs: [lint, type-check, test] # Only run after all checks pass
continue-on-error: true # Don't fail the workflow if HACS brands check fails
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Hassfest validation
uses: home-assistant/actions/hassfest@master
- name: HACS validation
uses: hacs/action@main
with:
category: integration
# Security check (only on main branch)
security:
name: Security Scan
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
needs: [lint, type-check, test]
continue-on-error: true # Security issues shouldn't block deployment
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Run safety check
run: |
python -m pip install --upgrade pip
pip install safety
pip install -r requirements.txt
safety check --json || true
# Final status check for branch protection
status-check:
name: CI Status
runs-on: ubuntu-latest
needs: [validate, lint, type-check, test]
if: always()
steps:
- name: Check CI Status
run: |
if [[ "${{ needs.validate.result }}" == "failure" || \
"${{ needs.lint.result }}" == "failure" || \
"${{ needs.type-check.result }}" == "failure" || \
"${{ needs.test.result }}" == "failure" ]]; then
echo "❌ CI failed"
exit 1
else
echo "✅ CI passed"
fi