From cf2fd398b48dc69a29f62d8fd550eaeb20a74669 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 5 Apr 2026 09:57:48 +0100 Subject: [PATCH] ci: skip zh-CN translation when docs are unchanged --- .github/workflows/translate-zh-cn.yml | 37 ++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/.github/workflows/translate-zh-cn.yml b/.github/workflows/translate-zh-cn.yml index 1d9cca601..394998316 100644 --- a/.github/workflows/translate-zh-cn.yml +++ b/.github/workflows/translate-zh-cn.yml @@ -81,11 +81,28 @@ jobs: path.rmdir() PY - - name: Build docs file list + - name: Build pending docs file list + id: pending run: | python - <<'PY' + import hashlib + import os + import re from pathlib import Path - files = [] + + source_hash_re = re.compile(r'^x-i18n:\n(?: .*\n)*? source_hash: ([0-9a-f]{64})$', re.M) + + def stored_source_hash(path: Path) -> str: + if not path.exists(): + return "" + text = path.read_text(encoding="utf-8", errors="ignore") + match = source_hash_re.search(text) + if not match: + return "" + return match.group(1).strip() + + all_files = [] + pending_files = [] for path in Path("docs").rglob("*"): if not path.is_file(): continue @@ -98,12 +115,24 @@ jobs: continue if rel.startswith("docs/.generated/"): continue - files.append(str(path.resolve())) + all_files.append(str(path.resolve())) + + rel_doc = path.relative_to("docs") + zh_path = Path("docs") / "zh-CN" / rel_doc + source_hash = hashlib.sha256(path.read_bytes()).hexdigest() + if stored_source_hash(zh_path) != source_hash: + pending_files.append(str(path.resolve())) + Path(".openclaw-sync").mkdir(exist_ok=True) - Path(".openclaw-sync/docs-i18n-files.txt").write_text("\n".join(files) + "\n") + Path(".openclaw-sync/docs-i18n-files.txt").write_text("\n".join(pending_files) + ("\n" if pending_files else "")) + print(f"all_docs={len(all_files)} pending_docs={len(pending_files)}") + with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh: + fh.write(f"all_count={len(all_files)}\n") + fh.write(f"pending_count={len(pending_files)}\n") PY - name: Translate changed docs into zh-CN + if: steps.pending.outputs.pending_count != '0' env: OPENAI_API_KEY: ${{ secrets.OPENCLAW_DOCS_I18N_OPENAI_API_KEY }} OPENCLAW_DOCS_I18N_PROVIDER: openai