Skip to content

Commit 321f3a6

Browse files
authored
Fix orphaned file deletion not being included in translation PRs (#862)
* Fix orphaned file deletion not being included in translation PRs The translate job deletes orphaned files but artifacts only contain new/updated translations. The merge job now runs ci-delete-orphans to delete orphans and stage them via git rm before creating the PR. * Translation: run pre-commit on all files
1 parent 9509f7a commit 321f3a6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

.github/workflows/translate.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ jobs:
149149
if: steps.check.outputs.has_artifacts == 'true'
150150
run: |
151151
pip install pre-commit
152-
pre-commit run --files docs/*/docs/**/*.md || true
152+
pre-commit run --all-files || true
153+
154+
- name: Delete orphaned translation files
155+
if: steps.check.outputs.has_artifacts == 'true'
156+
working-directory: _scripts
157+
run: uv run -q translate.py ci-delete-orphans
153158

154159
- name: Create PR
155160
if: steps.check.outputs.has_artifacts == 'true'

_scripts/translate.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,38 @@ def ci_detect(
14751475
print(f"has_work={'true' if need_sync else 'false'}")
14761476

14771477

1478+
@app.command("ci-delete-orphans")
1479+
def ci_delete_orphans():
1480+
"""Delete orphaned translation files for all languages (CI).
1481+
1482+
This runs in the merge job to delete translation files that no longer
1483+
have a corresponding English source file. Files are deleted and staged
1484+
for commit using git rm.
1485+
"""
1486+
console = Console(
1487+
stderr=True, force_terminal=True if os.getenv("GITHUB_ACTIONS") else None
1488+
)
1489+
all_langs = get_translation_languages()
1490+
total_deleted = 0
1491+
1492+
for lang in all_langs:
1493+
orphaned = get_orphaned_files(lang)
1494+
if orphaned:
1495+
console.print(
1496+
f"[bold cyan]{lang}[/bold cyan]: deleting {len(orphaned)} orphaned files"
1497+
)
1498+
for p in orphaned:
1499+
console.print(f" [red]Deleting:[/red] {p.relative_to(DOCS_ROOT)}")
1500+
# Use git rm to delete and stage the deletion in one step
1501+
subprocess.run(["git", "rm", "-f", str(p)], check=True, cwd=REPO_ROOT)
1502+
total_deleted += 1
1503+
1504+
if total_deleted:
1505+
console.print(f"\n[bold]Total deleted:[/bold] {total_deleted} orphaned files")
1506+
else:
1507+
console.print("[dim]No orphaned files found[/dim]")
1508+
1509+
14781510
@app.command("ci-run")
14791511
def ci_run(
14801512
languages: str = typer.Option("[]", "--languages"),

0 commit comments

Comments
 (0)