-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (132 loc) · 5.46 KB
/
implement.yml
File metadata and controls
148 lines (132 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Reusable Workflow: Issue Implementation
# 用户确认后自动实现代码
name: Issue Implementation (Reusable)
on:
workflow_call:
inputs:
trigger_keywords:
description: '触发实现的关键词 JSON 数组'
type: string
default: '["/impl", "ok", "OK", "Ok", "oK"]'
use_feishu_notify:
description: '是否发送飞书通知'
type: boolean
default: true
secrets:
ANTHROPIC_API_KEY:
required: true
ANTHROPIC_BASE_URL:
required: false
PAT_TOKEN:
required: false
FEISHU_WEBHOOK_TOKEN:
required: false
jobs:
implement:
runs-on: ubuntu-latest
if: |
startsWith(github.event.comment.body, '/impl') ||
contains(fromJSON(inputs.trigger_keywords), github.event.comment.body)
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
submodules: recursive
token: ${{ secrets.PAT_TOKEN || github.token }}
- name: Implement with Claude
id: implement
uses: anthropics/claude-code-action@v1
env:
ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
with:
github_token: ${{ secrets.PAT_TOKEN || github.token }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
仓库: ${{ github.repository }}
仓库 URL: https://github.com/${{ github.repository }}
用户已确认,执行 `implement` skill 实现 Issue #${{ github.event.issue.number }},并使用 `gh issue comment` 报告进度。
Issue: ${{ github.event.issue.title }}
Body:
${{ github.event.issue.body }}
触发评论: ${{ github.event.comment.body }}
实现完成后必须调用 `gh issue comment ${{ github.event.issue.number }} --body "..."` 发表评论,说明创建的 PR 或遇到的问题。
注意: 所有代码链接必须使用 https://github.com/${{ github.repository }}/blob/main/... 格式。
claude_args: |
--model opus --allowedTools "Bash(gh issue:*),Bash(gh pr:*),Bash(git:*),Read,Write,Edit,Glob,Grep,Task,Skill"
--json-schema '{
"type": "object",
"properties": {
"description": {"type": "string", "description": "实现结果一句话摘要,如:已创建 PR #123"},
"status": {"type": "string", "enum": ["success", "failed", "blocked"], "description": "实现状态"},
"branch_name": {"type": "string", "description": "创建的分支名"},
"pr_number": {"type": "integer", "description": "PR 编号"},
"pr_url": {"type": "string", "description": "PR 链接"}
},
"required": ["description", "status"]
}'
- name: Output Result
if: always()
run: |
echo "## Issue Implementation Result" >> $GITHUB_STEP_SUMMARY
echo '```json' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.implement.outputs.structured_output }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Parse implement output
if: always() && inputs.use_feishu_notify
id: parse
run: |
STRUCTURED_OUTPUT='${{ steps.implement.outputs.structured_output }}'
if [ -n "$STRUCTURED_OUTPUT" ] && [ "$STRUCTURED_OUTPUT" != "null" ]; then
STATUS_VAL=$(echo "$STRUCTURED_OUTPUT" | jq -r '.status // "unknown"')
DESCRIPTION=$(echo "$STRUCTURED_OUTPUT" | jq -r '.description // "实现任务完成"')
else
STATUS_VAL="failed"
DESCRIPTION="未能获取实现结果"
fi
case "$STATUS_VAL" in
"success") STATUS="success" ;;
"blocked") STATUS="warning" ;;
*) STATUS="error" ;;
esac
if [ "${{ job.status }}" != "success" ]; then
STATUS="warning"
DESCRIPTION="GitHub Action 执行失败"
fi
echo "status=${STATUS}" >> $GITHUB_OUTPUT
echo "title=实现: ${STATUS_VAL}" >> $GITHUB_OUTPUT
# 多行输出使用 heredoc
{
echo 'description<<EOF'
echo "**${{ github.repository }}** #${{ github.event.issue.number }}"
echo "*${{ github.event.issue.title }}*"
echo "${DESCRIPTION}"
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Checkout Action
if: always() && inputs.use_feishu_notify
uses: actions/checkout@v5
with:
repository: vast-enterprise/agentic-workflow-template
ref: main
token: ${{ secrets.PAT_TOKEN || github.token }}
path: .agentic-actions
sparse-checkout: .github/actions
sparse-checkout-cone-mode: false
- name: Notify Feishu
if: always() && inputs.use_feishu_notify
uses: ./.agentic-actions/.github/actions/feishu-notify
with:
webhook_token: ${{ secrets.FEISHU_WEBHOOK_TOKEN }}
title: ${{ steps.parse.outputs.title }}
description: ${{ steps.parse.outputs.description }}
link_text: '🔗 查看 Issue'
link_url: ${{ github.event.issue.html_url }}
status: ${{ steps.parse.outputs.status }}
outputs:
structured_output: ${{ steps.implement.outputs.structured_output }}