Skip to content

Commit f267e19

Browse files
fix(ci): replace yq with Python nav patching in publish-devnotes (#548)
The yq JSON roundtrip was mangling the entire mkdocs.yml file (indentation, quoting, comments), causing mike deploy to fail. Extract a Python script that surgically replaces only the Dev Notes nav block, leaving all other content byte-identical.
1 parent 1a237d9 commit f267e19

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Patch the Dev Notes nav block in mkdocs.yml.
5+
6+
Used by publish-devnotes.yml to splice HEAD's Dev Notes nav entries into an
7+
older source checkout without touching the rest of the file.
8+
9+
Usage: python patch-devnotes-nav.py <head_mkdocs> <target_mkdocs>
10+
"""
11+
12+
from __future__ import annotations
13+
14+
import re
15+
import sys
16+
17+
18+
def extract_devnotes_block(text: str) -> tuple[int, int, list[str]]:
19+
"""Return (start, end, lines) for the ' - Dev Notes:' nav block."""
20+
lines = text.splitlines(keepends=True)
21+
start = None
22+
for i, line in enumerate(lines):
23+
if re.match(r"^ - Dev Notes:", line):
24+
start = i
25+
break
26+
if start is None:
27+
raise SystemExit("Dev Notes nav section not found")
28+
end = start + 1
29+
while end < len(lines):
30+
# Stop at next top-level nav entry (2-space indent) or non-nav section
31+
if lines[end].strip() and not lines[end].startswith(" ") and not lines[end].startswith(" #"):
32+
break
33+
end += 1
34+
return start, end, lines
35+
36+
37+
def main() -> None:
38+
if len(sys.argv) != 3:
39+
raise SystemExit(f"Usage: {sys.argv[0]} <head_mkdocs> <target_mkdocs>")
40+
41+
head_path, target_path = sys.argv[1], sys.argv[2]
42+
43+
with open(head_path) as f:
44+
head_start, head_end, head_lines = extract_devnotes_block(f.read())
45+
head_block = head_lines[head_start:head_end]
46+
47+
with open(target_path) as f:
48+
old_start, old_end, old_lines = extract_devnotes_block(f.read())
49+
new_lines = old_lines[:old_start] + head_block + old_lines[old_end:]
50+
51+
with open(target_path, "w") as f:
52+
f.writelines(new_lines)
53+
print(f"Patched Dev Notes nav: replaced lines {old_start + 1}-{old_end} with {len(head_block)} lines from HEAD")
54+
55+
56+
if __name__ == "__main__":
57+
main()

.github/workflows/publish-devnotes.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ jobs:
3838
- name: Checkout docs source and overlay devnotes
3939
run: |
4040
git checkout ${{ env.SOURCE_SHA }}
41-
git checkout ${{ github.sha }} -- docs/devnotes/
41+
git checkout ${{ github.sha }} -- docs/devnotes/ .github/scripts/patch-devnotes-nav.py
4242
4343
# Patch the "Dev Notes" nav section from HEAD's mkdocs.yml into the
4444
# old source's mkdocs.yml. This keeps nav entries for new devnotes
4545
# without pulling in entries for non-devnotes pages that may not
4646
# exist in the old source checkout.
47-
pip install -q yq
48-
DEVNOTES_NAV=$(git show ${{ github.sha }}:mkdocs.yml \
49-
| yq '.nav[] | select(has("Dev Notes")) | .["Dev Notes"]')
50-
yq -y -i "(.nav[] | select(has(\"Dev Notes\")))[\"Dev Notes\"] = ${DEVNOTES_NAV}" mkdocs.yml
47+
git show ${{ github.sha }}:mkdocs.yml > /tmp/mkdocs-head.yml
48+
python3 .github/scripts/patch-devnotes-nav.py /tmp/mkdocs-head.yml mkdocs.yml
5149
- name: Install uv
5250
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
5351
with:

0 commit comments

Comments
 (0)