Last active
October 28, 2025 05:10
-
-
Save sayanchowdhury/378ddcc398fe7b0a909301c2ec8648d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| Reads "old -> new" pairs from stdin, replaces them in the target files, and | |
| prints which lines were missed (no match found). | |
| """ | |
| import sys | |
| from pathlib import Path | |
| def parse_pairs(stdin_lines): | |
| pairs = [] | |
| for line in stdin_lines: | |
| if "->" not in line: | |
| continue | |
| old, new = line.split("->", 1) | |
| old, new = old.strip(), new.strip() | |
| if old and new and old != new: | |
| pairs.append((old, new)) | |
| return pairs | |
| def main(): | |
| if len(sys.argv) < 2: | |
| print("Usage: sync_releasenotes.py <file1> <file2> ...", file=sys.stderr) | |
| sys.exit(2) | |
| targets = [Path(p) for p in sys.argv[1:]] | |
| pairs = parse_pairs(sys.stdin) | |
| if not pairs: | |
| print("No releasenote.text changes detected.") | |
| return | |
| missed = [] | |
| for t in targets: | |
| if not t.exists(): | |
| print(f"✗ missing: {t}") | |
| continue | |
| text = t.read_text(encoding="utf-8") | |
| updated = False | |
| misses_for_file = [] | |
| for old, new in pairs: | |
| if t.suffix == ".md": | |
| old = old[0].upper() + old[1:] | |
| if old in text: | |
| text = text.replace(old, new) | |
| updated = True | |
| else: | |
| misses_for_file.append(old) | |
| if updated: | |
| t.write_text(text, encoding="utf-8") | |
| print(f"✓ updated: {t}") | |
| else: | |
| print(f"⚠ no replacements made in: {t}") | |
| for m in misses_for_file: | |
| print(f" ⚠ missed line: \"{m}\"") | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| BASE=${1:-d64e6476c17cec1999b705f95014a4f0e267947f} | |
| TARGET_JSON="releases/release-1.35/release-notes/release-notes-draft.json" | |
| TARGET_MD="releases/release-1.35/release-notes/release-notes-draft.md" | |
| git diff --diff-filter=ACMR --name-only "$BASE..HEAD" -- '*.yml' '*.yaml' | | |
| while IFS= read -r f; do | |
| old=$(git show "${BASE}:${f}" 2>/dev/null | | |
| yq -r '.. | .releasenote?.text? | select(. != null and . != "")' - | | |
| tr '\n' ' ') | |
| new=$(git show "HEAD:${f}" 2>/dev/null | | |
| yq -r '.. | .releasenote?.text? | select(. != null and . != "")' - | | |
| tr '\n' ' ') | |
| [ "${old:-}" != "${new:-}" ] && printf '%s -> %s\n' "$old" "$new" | |
| done | python3 sync_releasenotes.py "$TARGET_JSON" "$TARGET_MD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment