|
| 1 | +name: claude-translate-sync |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["python-3.14-sync-with-cpython"] |
| 6 | + types: [completed] |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: claude-translate-sync |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +jobs: |
| 14 | + translate: |
| 15 | + # Only run when sync workflow succeeded (or on manual dispatch) |
| 16 | + if: >- |
| 17 | + github.repository == 'python/python-docs-zh-tw' |
| 18 | + && (github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success') |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + steps: |
| 24 | + - uses: actions/create-github-app-token@v2 |
| 25 | + id: app-token |
| 26 | + with: |
| 27 | + app-id: ${{ secrets.APP_ID }} |
| 28 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 29 | + |
| 30 | + - name: Find sync PR |
| 31 | + id: find-pr |
| 32 | + env: |
| 33 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 34 | + run: | |
| 35 | + PR_NUMBER=$(gh pr list \ |
| 36 | + --repo "${{ github.repository }}" \ |
| 37 | + --head "cron/sync/3.14" \ |
| 38 | + --state open \ |
| 39 | + --json number \ |
| 40 | + --jq '.[0].number // empty') |
| 41 | + if [ -z "$PR_NUMBER" ]; then |
| 42 | + echo "No open sync PR found on cron/sync/3.14" |
| 43 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 44 | + else |
| 45 | + echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT" |
| 46 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Checkout sync branch |
| 50 | + if: steps.find-pr.outputs.skip != 'true' |
| 51 | + uses: actions/checkout@v6 |
| 52 | + with: |
| 53 | + ref: cron/sync/3.14 |
| 54 | + token: ${{ steps.app-token.outputs.token }} |
| 55 | + fetch-depth: 0 |
| 56 | + |
| 57 | + - name: Configure git |
| 58 | + if: steps.find-pr.outputs.skip != 'true' |
| 59 | + run: | |
| 60 | + git config user.name "github-actions[bot]" |
| 61 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 62 | +
|
| 63 | + - name: Install gettext |
| 64 | + if: steps.find-pr.outputs.skip != 'true' |
| 65 | + run: sudo apt-get install -y gettext |
| 66 | + |
| 67 | + - name: Install uv |
| 68 | + if: steps.find-pr.outputs.skip != 'true' |
| 69 | + uses: astral-sh/setup-uv@v7 |
| 70 | + |
| 71 | + - name: Run Claude to translate |
| 72 | + if: steps.find-pr.outputs.skip != 'true' |
| 73 | + uses: anthropics/claude-code-action@v1 |
| 74 | + timeout-minutes: 30 |
| 75 | + with: |
| 76 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 77 | + claude_args: >- |
| 78 | + --max-turns 20 |
| 79 | + --allowedTools "Read,Edit,Write,Bash(git:*),Bash(grep:*),Bash(msgattrib:*),Bash(msgfmt:*),Bash(msgcat:*),Bash(uvx:*),Bash(gh:*)" |
| 80 | + track_progress: true |
| 81 | + prompt: | |
| 82 | + You are working on the CPython sync PR #${{ steps.find-pr.outputs.pr_number }} |
| 83 | + on the `cron/sync/3.14` branch. |
| 84 | +
|
| 85 | + Your task: translate fuzzy and untranslated entries in changed PO files. |
| 86 | + Follow the translate-po skill for translation rules and fuzzy resolution. |
| 87 | +
|
| 88 | + Steps: |
| 89 | + 1. Find changed PO files: `git diff --name-only origin/3.14...HEAD -- '*.po'` |
| 90 | + 2. For each file, use `msgattrib --only-fuzzy` and `msgattrib --only-untranslated` to find entries |
| 91 | + 3. Prioritize fuzzy entries first, then untranslated (use translate-po skill) |
| 92 | + 4. After editing, run `uvx powrap <file>` and `msgfmt --check <file>` |
| 93 | + 5. Commit and push: |
| 94 | + ``` |
| 95 | + git add <changed .po files> |
| 96 | + git commit -m "Translate fuzzy and untranslated entries from sync" |
| 97 | + git push origin cron/sync/3.14 |
| 98 | + ``` |
| 99 | + 6. Post a summary comment on PR #${{ steps.find-pr.outputs.pr_number }} with: |
| 100 | + - Fuzzy entries fixed count |
| 101 | + - New translations added count |
| 102 | + - Files modified |
| 103 | + - Entries skipped (if any, with reasons) |
| 104 | + Use: `gh pr comment ${{ steps.find-pr.outputs.pr_number }} --body "<summary>"` |
| 105 | +
|
| 106 | + If no entries need work, post a short "nothing to translate" comment and skip commit/push. |
0 commit comments