Check Translation Staleness #4
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
| name: Check Translation Staleness | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # Daily at UTC 00:00 | |
| workflow_dispatch: | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Close existing stale PRs | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prs = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| head: `${context.repo.owner}:i18n/mark-outdated` | |
| }); | |
| for (const pr of prs.data) { | |
| console.log(`Closing stale PR #${pr.number}`); | |
| await github.rest.pulls.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr.number, | |
| state: 'closed' | |
| }); | |
| } | |
| - name: Check and update translation status | |
| id: check | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Delete remote branch if exists | |
| git push origin --delete i18n/mark-outdated 2>/dev/null || true | |
| git checkout -b i18n/mark-outdated | |
| # Scan all locales dynamically | |
| for locale_dir in website/i18n/*/; do | |
| locale=$(basename "$locale_dir") | |
| docs_dir="${locale_dir}docusaurus-plugin-content-docs/current" | |
| [ -d "$docs_dir" ] || continue | |
| echo "Scanning locale: $locale" | |
| # Find all markdown files in translation directory | |
| find "$docs_dir" -name "*.md" -type f | while read -r trans_file; do | |
| # Extract source_commit and source_file from frontmatter | |
| source_commit=$(grep -oP 'source_commit:\s*["'"'"']?\K[a-f0-9]+' "$trans_file" 2>/dev/null || echo "") | |
| source_file=$(grep -oP 'source_file:\s*["'"'"']?\K[^"'"'"']+' "$trans_file" 2>/dev/null || echo "") | |
| # Skip if no translation metadata | |
| [ -z "$source_commit" ] || [ -z "$source_file" ] && continue | |
| # Check if source file exists | |
| if [ -f "website/$source_file" ]; then | |
| # Count commits since source_commit | |
| updates=$(git log --oneline "$source_commit"..HEAD -- "website/$source_file" 2>/dev/null | wc -l) | |
| if [ "$updates" -gt 0 ]; then | |
| # Source has updates -> mark outdated | |
| if grep -q 'outdated:\s*false' "$trans_file"; then | |
| echo " Mark outdated: $trans_file ($updates commits behind)" | |
| sed -i 's/outdated:\s*false/outdated: true/' "$trans_file" | |
| fi | |
| else | |
| # Source is up-to-date -> mark not outdated | |
| if grep -q 'outdated:\s*true' "$trans_file"; then | |
| echo " Mark up-to-date: $trans_file (source_commit matches)" | |
| sed -i 's/outdated:\s*true/outdated: false/' "$trans_file" | |
| fi | |
| fi | |
| fi | |
| done | |
| done | |
| # Check for changes | |
| if git diff --quiet; then | |
| echo "No translation status changes" | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| git add -A | |
| git commit -m "chore(i18n): update translation status" | |
| git push -f origin i18n/mark-outdated | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create PR | |
| if: steps.check.outputs.has_changes == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| try { | |
| await github.rest.pulls.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: 'chore(i18n): update translation status', | |
| head: 'i18n/mark-outdated', | |
| base: 'main', | |
| body: `## Summary | |
| This PR updates translation status based on source file changes. | |
| ### What this PR does | |
| - Marks translations as \`outdated: true\` when their English source has been updated | |
| - Marks translations as \`outdated: false\` when their \`source_commit\` matches the latest source | |
| --- | |
| *Auto-generated by [check-translation-staleness](.github/workflows/check-translation-staleness.yml)*` | |
| }); | |
| console.log('PR created successfully'); | |
| } catch (e) { | |
| console.log('Failed to create PR:', e.message); | |
| } |