Loading...
Loading...
Compare original and translation side by side
| Use this skill when... | Use something else when... |
|---|---|
| Setting up auto-fix workflow for a repo | Fixing a single PR's checks ( |
| Customizing which workflows trigger auto-fix | Inspecting workflow runs manually ( |
| Understanding the auto-fix pattern | Writing new workflows from scratch ( |
| 适用本技能的场景... | 适用其他方案的场景... |
|---|---|
| 为仓库设置自动修复工作流 | 修复单个PR的检查( |
| 自定义触发自动修复的工作流 | 手动检查工作流运行情况( |
| 了解自动修复模式 | 从零开始编写新工作流( |
find .github/workflows -maxdepth 1 -name 'github-workflow-auto-fix.yml'find .github/workflows -maxdepth 1 -name '*.yml' -type fgh secret listfind .github/workflows -maxdepth 1 -name 'github-workflow-auto-fix.yml'find .github/workflows -maxdepth 1 -name '*.yml' -type fgh secret list$ARGUMENTS--setup.github/workflows/--workflows <names>--dry-run$ARGUMENTS--setup.github/workflows/--workflows <names>--dry-run.github/workflows/github-workflow-auto-fix.ymlname:CLAUDE_CODE_OAUTH_TOKEN.github/workflows/github-workflow-auto-fix.ymlname:CLAUDE_CODE_OAUTH_TOKEN--workflows--workflows--setup.github/workflows/github-workflow-auto-fix.ymlname: Auto-fix Workflow Failures
on:
workflow_run:
workflows:
# List monitored workflows here
- "CI"
- "Lint"
types: [completed]
concurrency:
group: auto-fix-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
issues: write
actions: read
id-token: write
jobs:
auto-fix:
if: >-
github.event.workflow_run.conclusion == 'failure' &&
github.event.workflow_run.actor.type != 'Bot' &&
github.event.workflow_run.head_branch != 'main' &&
github.event.workflow_run.head_branch != 'master'
runs-on: ubuntu-latest
steps:
- name: Checkout failed branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Gather failure context
id: context
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RUN_ID="${{ github.event.workflow_run.id }}"
gh run view "$RUN_ID" --log-failed 2>&1 | tail -500 > .auto-fix-failed-logs.txt
gh run view "$RUN_ID" --json conclusion,status,name,headBranch,headSha,jobs > .auto-fix-run-summary.json
PR_NUMBER=$(gh pr list --head "${{ github.event.workflow_run.head_branch }}" --json number --jq '.[0].number' 2>/dev/null || echo "")
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
RECENT_FIX=$(git log --oneline -5 --format='%s' | grep -c 'fix:.*resolve CI failure' || true)
echo "recent_fix_count=$RECENT_FIX" >> "$GITHUB_OUTPUT"
- name: Skip if already attempted
if: steps.context.outputs.recent_fix_count != '0'
run: echo "::notice::Skipping - recent auto-fix commit exists"
- name: Analyze and fix with Claude
if: steps.context.outputs.recent_fix_count == '0'
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
direct_prompt: |
<analysis-and-fix-prompt>
additional_permissions: |
Read
Write
Edit
Grep
Glob
Bash(git *)
Bash(gh *)--setup.github/workflows/github-workflow-auto-fix.ymlname: Auto-fix Workflow Failures
on:
workflow_run:
workflows:
# List monitored workflows here
- "CI"
- "Lint"
types: [completed]
concurrency:
group: auto-fix-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
issues: write
actions: read
id-token: write
jobs:
auto-fix:
if: >-
github.event.workflow_run.conclusion == 'failure' &&
github.event.workflow_run.actor.type != 'Bot' &&
github.event.workflow_run.head_branch != 'main' &&
github.event.workflow_run.head_branch != 'master'
runs-on: ubuntu-latest
steps:
- name: Checkout failed branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Gather failure context
id: context
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RUN_ID="${{ github.event.workflow_run.id }}"
gh run view "$RUN_ID" --log-failed 2>&1 | tail -500 > .auto-fix-failed-logs.txt
gh run view "$RUN_ID" --json conclusion,status,name,headBranch,headSha,jobs > .auto-fix-run-summary.json
PR_NUMBER=$(gh pr list --head "${{ github.event.workflow_run.head_branch }}" --json number --jq '.[0].number' 2>/dev/null || echo "")
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
RECENT_FIX=$(git log --oneline -5 --format='%s' | grep -c 'fix:.*resolve CI failure' || true)
echo "recent_fix_count=$RECENT_FIX" >> "$GITHUB_OUTPUT"
- name: Skip if already attempted
if: steps.context.outputs.recent_fix_count != '0'
run: echo "::notice::Skipping - recent auto-fix commit exists"
- name: Analyze and fix with Claude
if: steps.context.outputs.recent_fix_count == '0'
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
direct_prompt: |
<analysis-and-fix-prompt>
additional_permissions: |
Read
Write
Edit
Grep
Glob
Bash(git *)
Bash(gh *)workflow_run (failure)
|
v
Gather logs & context
|
v
Claude analyzes failure
|
+---+---+
| |
v v
Fixable Complex/External
| |
v v
Fix & Open issue
push with analysis
| |
v v
Comment Comment on PR
on PR linking issueworkflow_run (failure)
|
v
收集日志与上下文信息
|
v
Claude分析失败原因
|
+---+---+
| |
v v
可修复问题 复杂/外部问题
| |
v v
修复并推送 创建Issue
附带分析结果
| |
v v
在PR上评论 在PR上评论
关联Issue| Guard | Purpose |
|---|---|
| Prevent bot-triggered loops |
| Never auto-fix main branch directly |
| Recent fix check | Skip if auto-fix already attempted |
| Concurrency group | One auto-fix per branch at a time |
| Limit Claude's iteration count |
| 防护措施 | 目的 |
|---|---|
| 防止机器人触发的循环 |
| 绝不直接自动修复主分支 |
| 近期修复检查 | 如果已尝试过自动修复则跳过 |
| 并发组限制 | 每个分支同时仅运行一个自动修复任务 |
| 限制Claude的迭代次数 |
| Requirement | How to set up |
|---|---|
| Repository secret with Claude Code OAuth token |
| Included in workflow permissions |
| Included in workflow permissions |
| For creating issues on complex failures |
| 要求 | 设置方法 |
|---|---|
| 配置仓库密钥,包含Claude Code OAuth令牌 |
| 已包含在工作流权限中 |
| 已包含在工作流权限中 |
| 用于为复杂失败创建Issue |
| Context | Command |
|---|---|
| Check recent failures | |
| Get failed logs | |
| Run summary | |
| Find associated PR | |
| List workflow names | |
| 场景 | 命令 |
|---|---|
| 检查近期失败记录 | |
| 获取失败日志 | |
| 运行摘要 | |
| 查找关联PR | |
| 列出工作流名称 | |