cherry-studio/.github/workflows/claude-translator.yml
Phantom 8b7776b545
CI: launch claude translate for all comments (#9983)
* ci(claude-translator): 临时禁用issues触发并更新条件

暂时禁用issues触发以解决上游bug
更新issue_comment的触发条件,简化claude_args参数
修改翻译结果的原始内容标题格式

* ci: 更新Claude翻译器工作流的名称和并发组配置

* fix(workflow): 修正Claude翻译工作流中的拼写错误

* ci(workflow): 更新claude-translator触发条件

添加对评论发送者类型的检查,避免机器人触发工作流
2025-09-07 13:36:01 +08:00

75 lines
3.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Claude Translator
concurrency:
group: translator-${{ github.event.comment.id || github.event.issue.number }}
cancel-in-progress: false
on:
# temporally disable this because upstream bug.
# issues:
# types: [opened]
issue_comment:
types: [created, edited]
jobs:
translate:
# disable issues for now because upstream bug
# (github.event_name == 'issues' && github.event.issue.author_association == 'COLLABORATOR' && !contains(github.event.issue.body, 'This issue was translated by Claude.')) ||
if: |
(github.event_name == 'issue_comment' && github.event.sender.type != 'Bot') &&
((github.event_name == 'issue_comment' && github.event.action == 'created' && !contains(github.event.comment.body, 'This issue was translated by Claude')) ||
(github.event_name == 'issue_comment' && github.event.action == 'edited'))
runs-on: ubuntu-latest
permissions:
contents: read
issues: write # 编辑issues/comments
pull-requests: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Claude for translation
uses: anthropics/claude-code-action@v1
id: claude
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
claude_args: 'Bash(gh issue:*),Bash(gh api:repos/*/issues:*)'
prompt: |
你是一个多语言翻译助手。请完成以下任务:
1. 获取当前issue/comment的完整信息
2. 智能检测内容。
1. 如果是已经遵循格式要求翻译过的issue/comment检查翻译内容和原始内容是否匹配。若不匹配则重新翻译一次令其匹配并遵循格式要求若匹配则跳过任务。
2. 如果是未翻译过的issue/comment检查其内容语言。若不是英文则翻译成英文若已经是英文则跳过任务。
3. 格式要求:
- 标题:英文翻译(如果非英文)
- 内容格式:
> [!NOTE]
> This issue/comment was translated by Claude.
[英文翻译内容]
---
<details>
<summary>Original Content</summary>
[原始内容]
</details>
4. 使用gh工具更新
- 根据环境信息中的Event类型选择正确的命令
- 如果Event是'issues'gh issue edit [ISSUE_NUMBER] --title "[英文标题]" --body "[翻译内容 + 原始内容]"
- 如果Event是'issue_comment'gh api -X PATCH /repos/[REPO]/issues/comments/[COMMENT_ID] -f body="[翻译内容 + 原始内容]"
环境信息:
- Event: ${{ github.event_name }}
- Issue Number: ${{ github.event.issue.number }}
- Repository: ${{ github.repository }}
- Comment ID: ${{ github.event.comment.id || 'N/A' }} (only available for comment events)
使用以下命令获取完整信息:
gh issue view ${{ github.event.issue.number }} --json title,body,comments