mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
ci: 同步AI ISSUE BOT更改
This commit is contained in:
183
.github/workflows/issue-ai-analysis.yml
vendored
183
.github/workflows/issue-ai-analysis.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Issue AI Analysis
|
||||
name: AI Issue Analysis
|
||||
|
||||
on:
|
||||
issues:
|
||||
@@ -12,165 +12,48 @@ on:
|
||||
required: true
|
||||
type: number
|
||||
|
||||
env:
|
||||
# 初始评论内容(包含运行链接,仅出现一次)
|
||||
INITIAL_BODY: |
|
||||
🤖 **MaaBot 正在分析该 Issue...**
|
||||
感谢您的反馈!AI 正在自动分析该问题,预计耗时约 10 分钟。
|
||||
ACTION_LINK: |
|
||||
🔗 [GitHub Action 运行记录](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
|
||||
DETAILS_BEGIN: |
|
||||
<details><summary>点击此处展开分析过程</summary>
|
||||
DETAILS_END: |
|
||||
</details>
|
||||
|
||||
jobs:
|
||||
copilot-analysis:
|
||||
if: |
|
||||
(github.event_name == 'issues' && github.event.action == 'opened') ||
|
||||
github.event_name == 'workflow_dispatch' ||
|
||||
(github.event_name == 'issue_comment' &&
|
||||
github.event.action == 'created' &&
|
||||
contains(github.event.comment.body, '@MaaArknightsBot') &&
|
||||
(github.event_name == 'issue_comment' &&
|
||||
github.event.action == 'created' &&
|
||||
contains(github.event.comment.body, '@MaaArknightsBot') &&
|
||||
github.event.comment.user.type != 'Bot')
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
issues: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Determine issue number
|
||||
id: issue_number
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "issues" ]] || [[ "${{ github.event_name }}" == "issue_comment" ]]; then
|
||||
echo "issue_number=${{ github.event.issue.number }}" | tee -a "$GITHUB_OUTPUT"
|
||||
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||
echo "issue_number=${{ github.event.inputs.issue_number }}" | tee -a "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "Unknown trigger" && exit 1
|
||||
fi
|
||||
|
||||
# 步骤 1:发布初始中文评论,提示正在分析,并附上 Actions 运行链接
|
||||
- name: Create initial comment
|
||||
id: initial_comment
|
||||
uses: peter-evans/create-or-update-comment@main
|
||||
# 这个 action 只负责编排,分析质量仍依赖配套的 issue/log analysis skill。
|
||||
# 最佳实践参考:
|
||||
# - https://github.com/MaaAssistantArknights/MaaAssistantArknights/blob/dev-v2/.claude/skills/maa-issue-log-analysis/SKILL.md
|
||||
# - https://github.com/MaaEnd/MaaEnd/blob/ci/prompt/.claude/skills/maaend-issue-log-analysis/SKILL.md
|
||||
- name: Analyze issue with AI
|
||||
id: analysis
|
||||
uses: Misteo/ai-issue-analysis@main
|
||||
with:
|
||||
issue-number: ${{ steps.issue_number.outputs.issue_number }}
|
||||
token: ${{ secrets.MAA_BOT_TOKEN }}
|
||||
body: |
|
||||
${{ env.INITIAL_BODY }}
|
||||
---
|
||||
${{ env.ACTION_LINK }}
|
||||
github-token: ${{ secrets.MAA_BOT_TOKEN }}
|
||||
copilot-github-token: ${{ secrets.COPILOT_GITHUB_TOKEN }}
|
||||
bot-name: '@MaaArknightsBot'
|
||||
initial-comment-body: |
|
||||
🤖 **MaaBot 正在分析该 Issue...**
|
||||
|
||||
- name: Install Copilot CLI
|
||||
run: npm install -g @github/copilot
|
||||
感谢您的反馈!AI 正在自动分析该问题,预计耗时约 10 分钟。
|
||||
|
||||
# 步骤 2:执行 AI 分析,并流式更新评论(固定时间间隔)
|
||||
# 注意需搭配 issue 分析 skill 使用: https://github.com/MaaAssistantArknights/MaaAssistantArknights/blob/v2/.claude/skills/maa-issue-log-analysis/SKILL.md
|
||||
- name: Run Copilot analysis with streaming updates
|
||||
shell: bash
|
||||
- name: Consume outputs
|
||||
env:
|
||||
# GitHub 个人设置里添加 Fine-grained token, 勾选上所有 Copilot 相关的,过期时间不能超过一年。
|
||||
# Personal access tokens (classic) 不行,只能是 Fine-grained token
|
||||
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
|
||||
# 用于更新评论的 token
|
||||
GITHUB_TOKEN: ${{ secrets.MAA_BOT_TOKEN }}
|
||||
COMMENT_ID: ${{ steps.initial_comment.outputs.comment-id }}
|
||||
REPO: ${{ github.repository }}
|
||||
ISSUE_NUMBER: ${{ steps.issue_number.outputs.issue_number }}
|
||||
ANALYSIS_PROMPT: ${{ steps.analysis.outputs.analysis-prompt }}
|
||||
ISSUE_NUMBER: ${{ steps.analysis.outputs.issue-number }}
|
||||
COMMENT_ID: ${{ steps.analysis.outputs.comment-id }}
|
||||
COMMENT_URL: ${{ steps.analysis.outputs.comment-url }}
|
||||
COPILOT_OUTPUT: ${{ steps.analysis.outputs.copilot-output }}
|
||||
FINAL_CONCLUSION: ${{ steps.analysis.outputs.final-conclusion }}
|
||||
run: |
|
||||
# 定义输出文件和临时文件
|
||||
OUTPUT_FILE="copilot_output.log"
|
||||
BODY_FILE="comment_body.txt"
|
||||
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
|
||||
# 启动 Copilot 后台进程,将输出重定向到文件(同时捕获错误输出)
|
||||
# 这里用了 gpt-5.4-xhigh。免费模型不会调用工具和 skill(太笨),不建议用
|
||||
copilot --yolo --model gpt-5.4 --reasoning-effort xhigh \
|
||||
--prompt "分析一下 #${{ steps.issue_number.outputs.issue_number }},将你的结论输出到 copilot_answer.md" > "$OUTPUT_FILE" 2>&1 &
|
||||
COPILOT_PID=$!
|
||||
echo "Copilot started with PID $COPILOT_PID"
|
||||
|
||||
# 记录上一次更新的内容,避免重复更新
|
||||
last_content=""
|
||||
|
||||
# 循环检查,直到 Copilot 进程结束
|
||||
while true; do
|
||||
# 启动一个后台 sleep 进程
|
||||
sleep 30 &
|
||||
sleep_pid=$!
|
||||
|
||||
# 等待两个进程中的任意一个结束
|
||||
# - 如果 sleep 先结束,表示 30 秒已到,需要执行 curl
|
||||
# - 如果 COPILOT_PID 先结束,表示监控进程已退出,循环结束
|
||||
wait -n $COPILOT_PID $sleep_pid 2>/dev/null
|
||||
wait_ret=$?
|
||||
|
||||
# 检查哪个进程结束了
|
||||
if ! kill -0 $COPILOT_PID 2>/dev/null; then
|
||||
# 监控进程已结束,退出循环(清理后台 sleep 进程)
|
||||
kill $sleep_pid 2>/dev/null
|
||||
break
|
||||
fi
|
||||
|
||||
if [ -f "$OUTPUT_FILE" ]; then
|
||||
current_content=$(cat "$OUTPUT_FILE")
|
||||
# 只有当内容变化且非空时才更新评论
|
||||
if [ "$current_content" != "$last_content" ] && [ -n "$current_content" ]; then
|
||||
# 构建评论正文:当前输出 + 分隔符 + 运行链接
|
||||
{
|
||||
echo "${{ env.INITIAL_BODY }}"
|
||||
echo ""
|
||||
echo "---"
|
||||
echo ""
|
||||
echo "${{ env.DETAILS_BEGIN }}"
|
||||
echo "$current_content"
|
||||
echo "${{ env.DETAILS_END }}"
|
||||
echo ""
|
||||
echo "${{ env.ACTION_LINK }}"
|
||||
} > "$BODY_FILE"
|
||||
|
||||
# 使用 jq 构造 JSON 并通过 API 更新评论
|
||||
jq -n --arg body "$(cat "$BODY_FILE")" '{"body":$body}' | \
|
||||
curl -s -L -X PATCH \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
"https://api.github.com/repos/$REPO/issues/comments/$COMMENT_ID" \
|
||||
-d @-
|
||||
|
||||
last_content="$current_content"
|
||||
echo "Comment updated at $(date)"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
- name: Full Analysis (完整分析结果)
|
||||
shell: bash
|
||||
run: |
|
||||
cat copilot_output.log
|
||||
echo ""
|
||||
echo "---"
|
||||
echo ""
|
||||
cat copilot_answer.md
|
||||
|
||||
# 步骤 3:将分析结果与运行链接合并,准备最终评论内容(中文链接描述)
|
||||
- name: Prepare final comment
|
||||
run: |
|
||||
# 复制分析结果到新文件
|
||||
cp copilot_answer.md final_comment.md
|
||||
|
||||
echo "" >> final_comment.md
|
||||
echo "---" >> final_comment.md
|
||||
echo "" >> final_comment.md
|
||||
echo "${{ env.DETAILS_BEGIN }}" >> final_comment.md
|
||||
cat copilot_output.log >> final_comment.md
|
||||
echo "${{ env.DETAILS_END }}" >> final_comment.md
|
||||
echo "" >> final_comment.md
|
||||
echo "${{ env.ACTION_LINK }}" >> final_comment.md
|
||||
|
||||
# 步骤 4:更新之前发布的评论,替换为分析结论 + 运行链接
|
||||
- name: Update comment with analysis result
|
||||
uses: peter-evans/create-or-update-comment@main
|
||||
with:
|
||||
comment-id: ${{ steps.initial_comment.outputs.comment-id }}
|
||||
edit-mode: replace
|
||||
body-path: final_comment.md
|
||||
token: ${{ secrets.MAA_BOT_TOKEN }}
|
||||
printf '%s\n' "$ANALYSIS_PROMPT"
|
||||
echo "issue_number=$ISSUE_NUMBER"
|
||||
echo "comment_id=$COMMENT_ID"
|
||||
echo "comment_url=$COMMENT_URL"
|
||||
printf '%s\n' "$COPILOT_OUTPUT"
|
||||
printf '%s\n' "$FINAL_CONCLUSION"
|
||||
|
||||
Reference in New Issue
Block a user