-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (177 loc) · 6.85 KB
/
Copy pathci.yml
File metadata and controls
208 lines (177 loc) · 6.85 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
---
name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: YAML lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install yamllint
run: pip install yamllint
- name: Lint YAML sources
run: >-
yamllint -c .yamllint.yaml
blueprints/ .github/ .yamllint.yaml mkdocs.yml
test:
name: Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements-dev.txt
- name: Install development dependencies
run: pip install -r requirements-dev.txt
- name: Run the test suite
run: pytest -v -m "not slow"
mutation:
name: Mutation testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements-dev.txt
- name: Install development dependencies
run: pip install -r requirements-dev.txt
# Corrupts one part of the blueprint at a time and asserts the suite
# notices. A green suite that survives a mutation is a vacuous suite.
- name: Verify the suite detects a broken blueprint
run: pytest -v -m slow
ruff:
name: Python lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements-dev.txt
- name: Install development dependencies
run: pip install -r requirements-dev.txt
- name: Lint the test harness and tools
run: ruff check tests/ tools/
# tools/ has to keep running on the interpreter people already have.
# The main lint targets 3.11, so on its own it would happily pass code
# that 3.9 cannot even parse.
- name: Lint tools/ against the oldest supported Python
run: ruff check --target-version py39 tools/
tools-python39:
name: trace_report.py on Python 3.9
runs-on: ubuntu-latest
# The script is what users run to produce a bug report, so it must work on
# a stock system interpreter with nothing installed. macOS still ships 3.9.
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: "3.9"
- name: Byte-compile without any dependencies
run: python -m py_compile tools/trace_report.py
- name: Run it end to end under an ASCII locale
env:
LC_ALL: C
LANG: C
PYTHONUTF8: "0"
PYTHONCOERCECLOCALE: "0"
run: |
python - <<'PY'
import json, pathlib
folder = pathlib.Path("_ci_traces")
folder.mkdir(exist_ok=True)
(folder / "a.json").write_text(json.dumps({
"trace": {"trace": {"action/0": [{"changed_variables": {"verdict": "старт"}}]},
"timestamp": {"start": "2026-08-02T00:05:00+00:00"}},
"logbookEntries": [{"message": "запускаем зарядку", "when": 1785628800.0}],
}, ensure_ascii=False), encoding="utf-8")
PY
python tools/trace_report.py _ci_traces --vars
python tools/trace_report.py _ci_traces --json > /dev/null
packaging:
name: HACS metadata
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# The version lives in the blueprint description and nowhere else, so it
# can silently disagree with the changelog. A tag disagreeing with either
# is worse: HACS serves tags, so users would install something whose
# notes describe a different release.
- name: Version agrees between the blueprint and the changelog
run: |
python - <<'PY'
import pathlib, re, sys
bp = pathlib.Path("blueprints/automation/ev_smart_charging"
"/ev_smart_charging.yaml").read_text(encoding="utf-8")
found = re.search(r"Версия\s+(\d+\.\d+\.\d+)", bp)
if not found:
sys.exit("no version found in the blueprint description")
version = found.group(1)
changelog = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8")
if f"## [{version}]" not in changelog:
sys.exit(f"blueprint says {version}, CHANGELOG has no such section")
tag = "${{ github.ref_type == 'tag' && github.ref_name || '' }}"
if tag and tag.lstrip("v") != version:
sys.exit(f"tag {tag} does not match blueprint version {version}")
print(f"version {version} agrees across the blueprint and CHANGELOG")
PY
# hacs.json is never exercised by the test suite, but a typo in it breaks
# installation for every HACS user and only surfaces as a bug report.
- name: Validate hacs.json and the blueprint layout
run: |
python - <<'PY'
import json, pathlib, sys
meta = json.loads(pathlib.Path("hacs.json").read_text(encoding="utf-8"))
if not meta.get("name"):
sys.exit("hacs.json: name is required")
# HACS installs blueprints by directory layout: blueprints/<domain>/<slug>/
found = list(pathlib.Path("blueprints").glob("*/*/*.yaml"))
if not found:
sys.exit("no blueprint found under blueprints/<domain>/<slug>/")
print("hacs.json OK;", ", ".join(str(p) for p in found))
PY
home-assistant-schema:
name: Home Assistant schema (informational)
runs-on: ubuntu-latest
# Home Assistant's internal APIs carry no stability promise, so a failure
# here is a signal to investigate rather than a reason to block a merge.
continue-on-error: true
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Install Home Assistant
run: pip install homeassistant
# The script exits 77 when it decides to skip; to GitHub that is just a
# failure, so translate it back into a pass.
- name: Validate the blueprint against the real schema
run: |
status=0
python tests/validate_with_home_assistant.py || status=$?
if [ "$status" -eq 77 ]; then
echo "::notice::schema check skipped"
exit 0
fi
exit "$status"