Skip to content

Commit 3a5a421

Browse files
josixclaude
andcommitted
ci: Add Claude-powered translation and review workflows for Python docs
refactor: Simplify Claude review and translation sync workflow instructions ci: migrate Claude Code Action workflows from @beta to @v1 Replace deprecated inputs (direct_prompt, allowed_tools, max_turns) with v1 equivalents (prompt, claude_args). Add track_progress for the long-running translate workflow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 30fd37f commit 3a5a421

File tree

3 files changed

+150
-1
lines changed

3 files changed

+150
-1
lines changed

.claude/skills/validate-translation/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Reviews translated PO entries for quality, checking terminology, pu
44
argument-hint: <path-to-po-file>
55
---
66

7-
# review-translation
7+
# validate-translation
88

99
Validate translated PO entries against project rules and report issues.
1010

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: claude-review-translation
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
paths:
7+
- "**/*.po"
8+
9+
jobs:
10+
review:
11+
# Only run on the upstream repo, skip forks
12+
if: >-
13+
github.repository == 'python/python-docs-zh-tw'
14+
&& !contains(github.event.pull_request.labels.*.name, 'sync-cpython')
15+
&& github.event.pull_request.head.ref != 'cron/sync/3.14'
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
steps:
21+
- uses: actions/checkout@v6
22+
23+
- name: Install gettext
24+
run: sudo apt-get install -y gettext
25+
26+
- uses: anthropics/claude-code-action@v1
27+
timeout-minutes: 10
28+
with:
29+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
30+
github_token: ${{ github.token }}
31+
claude_args: >-
32+
--max-turns 5
33+
--allowedTools "Read,Bash(gh pr diff:*),Bash(grep:*),Bash(msgattrib:*),Bash(msgfmt:*)"
34+
prompt: |
35+
Review the changed PO files in this pull request for translation quality.
36+
Follow the validate-translation and check-terminology skills for review criteria.
37+
38+
Steps:
39+
1. Run `gh pr diff ${{ github.event.pull_request.number }}` to identify changed PO files
40+
2. Read each changed file and review translated entries per the skill checklists
41+
3. Run `msgfmt --check` on each changed file to validate
42+
4. Post a concise review comment grouping issues by category
43+
5. If no issues found, post a short approval comment
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

Comments
 (0)