Repository navigation
202 lines (172 loc) · 6.55 KB
/
Copy pathci.yml
File metadata and controls
202 lines (172 loc) · 6.55 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
name: CI
on:
push:
# main is included because releases are tagged from it, and release.yml
# builds the shipped ZIP from that tag. Without main here, the commit that
# reaches users would be one no job ever ran against.
branches: ["main", "dev", "feature/**", "fix/**", "hotfix/**"]
tags-ignore: ["**"]
pull_request:
branches: [dev, main]
# pytest-homeassistant-custom-component is deliberately unpinned, so the
# suite tracks whatever Home Assistant is current. That means a Home
# Assistant release can break this integration without anyone touching the
# repository — the weekly run surfaces it instead of the next contributor.
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
lint:
name: Lint & pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.14"
cache: pip
- name: Install dependencies
run: pip install pre-commit mypy -r requirements.txt
- name: Cache pre-commit hooks
uses: actions/cache@v6
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: pre-commit run --all-files
- name: Run mypy
run: mypy custom_components/battery_controller/
test:
# Home Assistant's supported Python floor decides which Home Assistant
# version pip can install. On 3.13 the newest resolvable release is
# 2026.2.3, because Home Assistant 2026.3 onwards requires Python 3.14.2.
# Testing only on 3.13 therefore validates against a Home Assistant that
# is months behind what users run, without saying so anywhere.
#
# 3.14 is the version that matters; 3.13 is kept so the older supported
# Home Assistant line does not silently break.
name: Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.14", "3.13"]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install dependencies
run: pip install -r requirements.txt
# Which Home Assistant a green run actually proves compatibility with is
# otherwise invisible, since the dependency is unpinned by design.
- name: Report the resolved Home Assistant version
run: |
HA_VERSION=$(pip show homeassistant | awk '/^Version:/ {print $2}')
echo "Python ${{ matrix.python-version }} resolved Home Assistant $HA_VERSION"
{
echo "### Environment"
echo ""
echo "Python \`${{ matrix.python-version }}\` → Home Assistant \`$HA_VERSION\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: Run pytest
run: pytest --cov=custom_components --cov-report=xml -q
# setup.cfg gates the build at 90%, but the number itself appeared
# nowhere on the pull request — so a run could sit just above the floor,
# or drift down towards it, with nothing to notice. always() matters
# here: the figure is most interesting on the run that just failed the
# gate.
- name: Summarise coverage
if: always()
run: |
python - <<'PY' >> "$GITHUB_STEP_SUMMARY"
import xml.etree.ElementTree as ET
from pathlib import Path
print("### Coverage\n")
report = Path("coverage.xml")
if not report.is_file():
print("No `coverage.xml` was produced — pytest did not get that far.")
raise SystemExit
root = ET.parse(report).getroot()
total = float(root.get("line-rate", 0)) * 100
floor = 90.0
mark = "✅" if total >= floor else "❌"
print(f"{mark} **{total:.1f}%** overall (floor {floor:.0f}%)\n")
files = sorted(
(
(float(c.get("line-rate", 0)) * 100, c.get("filename", "?"))
for c in root.iter("class")
),
)
weakest = [f for f in files if f[0] < 95.0][:5]
if weakest:
print("Least covered files:\n")
print("| File | Coverage |")
print("| --- | ---: |")
for rate, name in weakest:
print(f"| `{name}` | {rate:.1f}% |")
PY
- name: Upload coverage
uses: codecov/codecov-action@v7
with:
files: ./coverage.xml
fail_ci_if_error: false
hacs:
name: HACS validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: hacs/action@main
with:
category: integration
js-test:
name: Test (JS analyzer)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
# Node 20 left maintenance in April 2026, so the analyzer tests were
# running on an unsupported runtime. 22 is the current LTS.
node-version: "22"
cache: npm
- name: Install dependencies
run: npm ci
- name: Run Jest
run: npm test
# Separate from the Jest run on purpose: jest's vm context costs ~16x on
# this hot numeric loop, so a benchmark inside it would measure jest
# rather than the DP.
- name: Check DP runtime
run: |
# pipefail so the guard's exit code survives the tee; bash -e alone
# would report the exit status of tee instead.
set -o pipefail
npm run test:perf | tee perf-output.txt
# The benchmark prints its median on every run, but inside a job log that
# only gets read when something already failed. Surfacing it here makes a
# drift towards the ceiling visible while the check is still passing.
- name: Summarise DP runtime
if: always()
run: |
{
echo "### Analyzer DP runtime"
echo ""
if grep -q '^DP runtime:' perf-output.txt 2>/dev/null; then
sed -n 's/^DP runtime: //p' perf-output.txt
else
echo "The benchmark produced no timing — it failed before measuring."
fi
} >> "$GITHUB_STEP_SUMMARY"
hassfest:
name: Home Assistant hassfest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: home-assistant/actions/hassfest@master