Migrate legacy architecture heading during section upsert
This commit is contained in:
@@ -429,8 +429,18 @@ def render_architecture_section(
|
|||||||
def upsert_generated_section(path: Path, section_markdown: str, dry_run: bool, verbose: bool) -> None:
|
def upsert_generated_section(path: Path, section_markdown: str, dry_run: bool, verbose: bool) -> None:
|
||||||
existing = path.read_text(encoding="utf-8") if path.exists() else ""
|
existing = path.read_text(encoding="utf-8") if path.exists() else ""
|
||||||
section_body = section_markdown
|
section_body = section_markdown
|
||||||
|
legacy_heading = "## Runtime visibility from Prometheus"
|
||||||
|
new_heading = "## Runtime and infrastructure inventory"
|
||||||
|
|
||||||
if GENERATED_BEGIN in existing and GENERATED_END in existing:
|
if GENERATED_BEGIN in existing and GENERATED_END in existing:
|
||||||
|
# Migration: replace legacy heading that exists outside the generated markers.
|
||||||
|
existing = re.sub(
|
||||||
|
rf"^{re.escape(legacy_heading)}(?=\n)",
|
||||||
|
new_heading,
|
||||||
|
existing,
|
||||||
|
count=1,
|
||||||
|
flags=re.MULTILINE,
|
||||||
|
)
|
||||||
pattern = re.compile(
|
pattern = re.compile(
|
||||||
rf"{re.escape(GENERATED_BEGIN)}.*?{re.escape(GENERATED_END)}",
|
rf"{re.escape(GENERATED_BEGIN)}.*?{re.escape(GENERATED_END)}",
|
||||||
re.DOTALL,
|
re.DOTALL,
|
||||||
@@ -438,7 +448,7 @@ def upsert_generated_section(path: Path, section_markdown: str, dry_run: bool, v
|
|||||||
replacement = "\n".join(
|
replacement = "\n".join(
|
||||||
line
|
line
|
||||||
for line in section_body.splitlines()
|
for line in section_body.splitlines()
|
||||||
if line.strip() not in {"## Runtime visibility from Prometheus", "## Runtime and infrastructure inventory"}
|
if line.strip() not in {legacy_heading, new_heading}
|
||||||
)
|
)
|
||||||
updated = pattern.sub(replacement.strip(), existing)
|
updated = pattern.sub(replacement.strip(), existing)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user