mirror of
https://github.com/Ar9av/obsidian-wiki.git
synced 2026-09-14 20:36:34 +08:00
e8172201fc
The readme-sync workflow no longer fails when README.md and README_TW.md don't change together. Instead, check_readme_sync.py reports drift: it lists commits that touched README.md after the last README_TW.md update, plus the pending English diff to translate and backfill. CI surfaces drift as a warning annotation only. Claude-Session: https://claude.ai/code/session_01PG9Pz6tcUfgpTHLjq3BT5Q
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Report README translation drift.
|
|
|
|
Lists commits that changed README.md after the last commit that touched
|
|
README_TW.md, plus the combined English diff that still needs to be
|
|
translated and backfilled into README_TW.md. Advisory only — exits 1 on
|
|
drift so callers can detect it, but CI never uses it to block a merge.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
|
|
|
|
ENGLISH = "README.md"
|
|
TRANSLATION = "README_TW.md"
|
|
|
|
|
|
def git(*args: str) -> str:
|
|
return subprocess.run(
|
|
["git", *args], capture_output=True, text=True, check=True
|
|
).stdout
|
|
|
|
|
|
def main() -> int:
|
|
# ponytail: a TW-only commit marks everything before it as synced;
|
|
# per-commit pairing if that ever misleads
|
|
last_tw = git("log", "-1", "--format=%H", "--", TRANSLATION).strip()
|
|
log_range = f"{last_tw}..HEAD" if last_tw else "HEAD"
|
|
pending = git(
|
|
"log", "--format=%h %s", log_range, "--", ENGLISH
|
|
).strip()
|
|
|
|
if not pending:
|
|
print(f"{TRANSLATION} is up to date with {ENGLISH}.")
|
|
return 0
|
|
|
|
print(f"Commits that changed {ENGLISH} without a later {TRANSLATION} update:")
|
|
print(pending)
|
|
print()
|
|
print(f"English changes not yet reflected in {TRANSLATION}:")
|
|
if last_tw:
|
|
print(git("diff", log_range, "--", ENGLISH))
|
|
else:
|
|
print(f"{TRANSLATION} has no history — the entire {ENGLISH} is untranslated.")
|
|
print(f"Translate the changes above and backfill them into {TRANSLATION}.")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|