mirror of
https://github.com/esphome/esphome.git
synced 2026-01-09 11:40:50 -07:00
[ci] Skip memory impact analysis for release and beta branches (#11740)
This commit is contained in:
@@ -63,6 +63,7 @@ from helpers import (
|
||||
get_components_from_integration_fixtures,
|
||||
get_components_with_dependencies,
|
||||
get_cpp_changed_components,
|
||||
get_target_branch,
|
||||
git_ls_files,
|
||||
parse_test_filename,
|
||||
root_path,
|
||||
@@ -471,6 +472,20 @@ def detect_memory_impact_config(
|
||||
- platform: platform name for the merged build
|
||||
- use_merged_config: "true" (always use merged config)
|
||||
"""
|
||||
# Skip memory impact analysis for release* or beta* branches
|
||||
# These branches typically contain many merged changes from dev, and building
|
||||
# all components at once would produce nonsensical memory impact results.
|
||||
# Memory impact analysis is most useful for focused PRs targeting dev.
|
||||
target_branch = get_target_branch()
|
||||
if target_branch and (
|
||||
target_branch.startswith("release") or target_branch.startswith("beta")
|
||||
):
|
||||
print(
|
||||
f"Memory impact: Skipping analysis for target branch {target_branch} "
|
||||
f"(would try to build all components at once, giving nonsensical results)",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return {"should_run": "false"}
|
||||
|
||||
# Get actually changed files (not dependencies)
|
||||
files = changed_files(branch)
|
||||
|
||||
@@ -196,6 +196,20 @@ def splitlines_no_ends(string: str) -> list[str]:
|
||||
return [s.strip() for s in string.splitlines()]
|
||||
|
||||
|
||||
@cache
|
||||
def _get_github_event_data() -> dict | None:
|
||||
"""Read and parse GitHub event file (cached).
|
||||
|
||||
Returns:
|
||||
Parsed event data dictionary, or None if not available
|
||||
"""
|
||||
github_event_path = os.environ.get("GITHUB_EVENT_PATH")
|
||||
if github_event_path and os.path.exists(github_event_path):
|
||||
with open(github_event_path) as f:
|
||||
return json.load(f)
|
||||
return None
|
||||
|
||||
|
||||
def _get_pr_number_from_github_env() -> str | None:
|
||||
"""Extract PR number from GitHub environment variables.
|
||||
|
||||
@@ -208,13 +222,30 @@ def _get_pr_number_from_github_env() -> str | None:
|
||||
return github_ref.split("/pull/")[1].split("/")[0]
|
||||
|
||||
# Fallback to GitHub event file
|
||||
github_event_path = os.environ.get("GITHUB_EVENT_PATH")
|
||||
if github_event_path and os.path.exists(github_event_path):
|
||||
with open(github_event_path) as f:
|
||||
event_data = json.load(f)
|
||||
pr_data = event_data.get("pull_request", {})
|
||||
if pr_number := pr_data.get("number"):
|
||||
return str(pr_number)
|
||||
if event_data := _get_github_event_data():
|
||||
pr_data = event_data.get("pull_request", {})
|
||||
if pr_number := pr_data.get("number"):
|
||||
return str(pr_number)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_target_branch() -> str | None:
|
||||
"""Get the target branch from GitHub environment variables.
|
||||
|
||||
Returns:
|
||||
Target branch name (e.g., "dev", "release", "beta"), or None if not in PR context
|
||||
"""
|
||||
# First try GITHUB_BASE_REF (set for pull_request events)
|
||||
if base_ref := os.environ.get("GITHUB_BASE_REF"):
|
||||
return base_ref
|
||||
|
||||
# Fallback to GitHub event file
|
||||
if event_data := _get_github_event_data():
|
||||
pr_data = event_data.get("pull_request", {})
|
||||
base_data = pr_data.get("base", {})
|
||||
if ref := base_data.get("ref"):
|
||||
return ref
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user