Skip to content

Commit 32f2df3

Browse files
appergbbaiqing
andauthored
Add Claude Code GitHub Workflow (#308)
* "Claude PR Assistant workflow" * "Claude Code Review workflow" * ci(claude): 收紧 review 触发:只 OWNER @claude 才跑,默认 Sonnet 4.6 - 删除 claude-code-review.yml:原本 PR opened/sync 自动触发会无差别烧 OAuth 额度 - claude.yml if 加 author_association == 'OWNER' 门禁:只有仓库 owner 评论 @claude 才触发 - 加 Pick model step:默认 claude-sonnet-4-6;评论包含 --opus / claude-opus 时切 claude-opus-4-7 - 用 env 注入 body / title 而不是直接 inline expression,避免外部内容引号注入 --------- Co-authored-by: baiqing <lbx12309@icloud.com>
1 parent 2c9dca5 commit 32f2df3

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/claude.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Claude Code
2+
3+
# 触发策略:
4+
# - 默认不主动 review;任何 PR 打开 / 同步都不会自动调用模型,避免烧 OAuth token 额度。
5+
# - 评论 / review / issue 中出现 `@claude` 才触发,且发起者必须是仓库 OWNER(appergb)。
6+
# - 模型默认 claude-sonnet-4-6(量大、成本低);评论里写 `--opus` 或包含 `claude-opus`
7+
# 字样会切到 claude-opus-4-7(用于需要更深推理的任务)。
8+
9+
on:
10+
issue_comment:
11+
types: [created]
12+
pull_request_review_comment:
13+
types: [created]
14+
issues:
15+
types: [opened, assigned]
16+
pull_request_review:
17+
types: [submitted]
18+
19+
jobs:
20+
claude:
21+
# 双重门禁:(1) 内容含 @claude (2) 触发者是 OWNER。
22+
# author_association == 'OWNER' 是 GitHub 内建字段,免一次 API 调用。
23+
if: |
24+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude') && github.event.comment.author_association == 'OWNER') ||
25+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude') && github.event.comment.author_association == 'OWNER') ||
26+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude') && github.event.review.author_association == 'OWNER') ||
27+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')) && github.event.issue.author_association == 'OWNER')
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
pull-requests: read
32+
issues: read
33+
id-token: write
34+
actions: read # Required for Claude to read CI results on PRs
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 1
40+
41+
- name: Pick model (default sonnet, opt-in opus)
42+
id: pick_model
43+
env:
44+
COMMENT_BODY: ${{ github.event.comment.body }}
45+
REVIEW_BODY: ${{ github.event.review.body }}
46+
ISSUE_BODY: ${{ github.event.issue.body }}
47+
ISSUE_TITLE: ${{ github.event.issue.title }}
48+
run: |
49+
set -eu
50+
body="${COMMENT_BODY}${REVIEW_BODY}${ISSUE_BODY}${ISSUE_TITLE}"
51+
if [[ "$body" == *"--opus"* ]] || [[ "$body" == *"claude-opus"* ]]; then
52+
echo "model=claude-opus-4-7" >> "$GITHUB_OUTPUT"
53+
else
54+
echo "model=claude-sonnet-4-6" >> "$GITHUB_OUTPUT"
55+
fi
56+
57+
- name: Run Claude Code
58+
id: claude
59+
uses: anthropics/claude-code-action@v1
60+
with:
61+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
62+
63+
# 让 Claude 能看 CI 结果
64+
additional_permissions: |
65+
actions: read
66+
67+
# 模型策略:默认 sonnet,评论里 --opus 才升级到 opus
68+
claude_args: '--model ${{ steps.pick_model.outputs.model }}'

0 commit comments

Comments
 (0)