[ci] Run CodSpeed benchmarks when top-level esphome Python modules change (#18114)

This commit is contained in:
J. Nick Koston
2026-08-05 20:50:13 -05:00
committed by GitHub
parent 0fcc2a6ff1
commit a7740091ec
4 changed files with 86 additions and 5 deletions
+15 -5
View File
@@ -63,6 +63,7 @@ from helpers import (
CPP_FILE_EXTENSIONS,
ESPHOME_TESTS_COMPONENTS_PATH,
PYTHON_FILE_EXTENSIONS,
base_python_changed,
changed_files,
core_changed,
filter_component_and_test_cpp_files,
@@ -657,16 +658,20 @@ BENCHMARK_INFRASTRUCTURE_FILES = frozenset(
def should_run_benchmarks(branch: str | None = None) -> bool:
"""Determine if C++ benchmarks should run based on changed files.
"""Determine if benchmarks (C++ and Python) should run based on changed files.
Benchmarks run when any of the following conditions are met:
1. Core C++ files changed (esphome/core/*)
2. The host platform changed (esphome/components/host/*) — benchmarks
1. Core files changed (esphome/core/*, C++ or Python)
2. Top-level Python files changed (esphome/*.py and esphome/*.pyi) —
the Python benchmarks exercise config loading (config.py,
yaml_util.py, ...), so a slowdown there is invisible unless the
benchmarks job runs
3. The host platform changed (esphome/components/host/*) — benchmarks
are built and run on the host platform, so its implementations of
``millis()``/``micros()``/etc. affect every benchmark
3. A directly changed component has benchmark files (no dependency expansion)
4. Benchmark infrastructure changed (tests/benchmarks/*, script/cpp_benchmark.py,
4. A directly changed component has benchmark files (no dependency expansion)
5. Benchmark infrastructure changed (tests/benchmarks/*, script/cpp_benchmark.py,
script/build_helpers.py, script/setup_codspeed_lib.py)
Unlike unit tests, benchmarks do NOT expand to dependent components.
@@ -683,6 +688,11 @@ def should_run_benchmarks(branch: str | None = None) -> bool:
if core_changed(files):
return True
# Top-level esphome/*.py modules are what the Python benchmarks in
# tests/benchmarks/python/ exercise
if base_python_changed(files):
return True
# Host platform supplies the runtime that benchmarks execute on
if any(f.startswith("esphome/components/host/") for f in files):
return True
+21
View File
@@ -1380,6 +1380,27 @@ def core_changed(files: list[str]) -> bool:
)
def base_python_changed(files: list[str]) -> bool:
"""Check if any Python file directly in esphome/ has changed.
Matches top-level modules and stubs (.py and .pyi) like esphome/config.py
and esphome/yaml_util.py but not files in subdirectories such as
esphome/components/ or esphome/dashboard/.
Args:
files: List of file paths to check
Returns:
True if any top-level esphome Python file has changed
"""
return any(
f.startswith("esphome/")
and f.endswith(PYTHON_FILE_EXTENSIONS)
and "/" not in f.removeprefix("esphome/")
for f in files
)
def get_cpp_changed_components(files: list[str]) -> list[str]:
"""Get components that have changed C++ files or tests.