fix-ci

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Fix CI Failures

修复CI失败问题

This skill automatically diagnoses and fixes CI failures for the current branch by fetching GitHub Actions logs, categorizing the failure, applying targeted fixes, and pushing the result.
本Skill可通过获取GitHub Actions日志、分类失败类型、应用针对性修复并推送结果,自动诊断并修复当前分支的CI失败问题。

Usage

使用方法

/fix-ci           # Auto-diagnose and fix
/fix-ci --dry-run # Show what would be fixed without applying
/fix-ci           # 自动诊断并修复
/fix-ci --dry-run # 展示将修复的内容但不实际应用

Workflow

工作流程

Step 1: Fetch CI Failure Details

步骤1:获取CI失败详情

Determine the current branch:
bash
git branch --show-current
Fetch the latest CI run for this branch:
bash
gh run list --branch <current-branch> --limit 1 --json databaseId,conclusion
  • If the latest run has
    "conclusion": "failure"
    , fetch the failed logs:
    bash
    gh run view <run-id> --log-failed
  • If no failed run is found (conclusion is "success" or no runs exist), report "No CI failures found" and stop.
确定当前分支:
bash
git branch --show-current
获取该分支的最新CI运行记录:
bash
gh run list --branch <current-branch> --limit 1 --json databaseId,conclusion
  • 如果最新运行记录的
    "conclusion": "failure"
    ,则获取失败日志:
    bash
    gh run view <run-id> --log-failed
  • 如果未找到失败的运行记录(结果为"success"或无运行记录),则提示“未发现CI失败”并终止流程。

Step 2: Categorize Failure

步骤2:分类失败类型

Parse the failed log output to determine the failure type(s):
  • lint: ruff check errors (look for
    ruff check
    output, rule codes like E, F, I, UP, B, SIM)
  • format: ruff format errors (look for
    ruff format
    output, "would reformat" messages)
  • type: mypy errors (look for
    mypy
    output, type annotation errors like "Incompatible type", "Missing return")
  • test: pytest failures (look for
    pytest
    output, "FAILED" markers, assertion errors)
  • multiple: if more than one category is detected, fix them in order: format -> lint -> type -> test
解析失败日志输出以确定失败类型:
  • lint:ruff检查错误(查找
    ruff check
    输出,规则代码如E、F、I、UP、B、SIM)
  • format:ruff格式错误(查找
    ruff format
    输出,包含"would reformat"的信息)
  • type:mypy错误(查找
    mypy
    输出,类型注解错误如"Incompatible type"、"Missing return")
  • test:pytest失败(查找
    pytest
    输出,包含"FAILED"标记、断言错误)
  • multiple:如果检测到多种类型,按以下顺序修复:格式 -> lint -> 类型 -> 测试

Step 3: Apply Fixes

步骤3:应用修复

Apply targeted fixes based on the failure category:
For format errors:
bash
ruff format synapse/ tests/
For lint errors:
bash
ruff check --fix synapse/ tests/
For type errors:
  • Read the specific mypy error messages from the log
  • Identify the file and line number for each error
  • Read the source code around the error location
  • Apply targeted fixes to the type annotations (add return types, fix incompatible types, add missing imports)
For test failures:
  • Read the pytest output to identify failing test names and assertion errors
  • Read the failing test code and the source code under test
  • Determine whether the fix belongs in the source code or the test
  • Apply the targeted fix
After each fix category, run the corresponding check locally to verify before proceeding to the next category.
If
--dry-run
flag is provided: report what would be fixed for each category but do NOT apply any changes, do NOT commit, and do NOT push.
根据失败类型应用针对性修复:
针对格式错误:
bash
ruff format synapse/ tests/
针对lint错误:
bash
ruff check --fix synapse/ tests/
针对类型错误:
  • 从日志中读取具体的mypy错误信息
  • 定位每个错误对应的文件和行号
  • 读取错误位置附近的源代码
  • 应用针对性修复(添加返回类型、修正不兼容类型、补充缺失的导入)
针对测试失败:
  • 读取pytest输出以确定失败的测试名称和断言错误
  • 读取失败的测试代码及被测源代码
  • 判断修复应应用于源代码还是测试代码
  • 应用针对性修复
完成每个类型的修复后,运行对应的本地检查以验证,再进行下一个类型的修复。
如果提供了
--dry-run
参数:展示每个类型将修复的内容,但实际应用任何更改、不提交、不推送。

Step 4: Local Verification

步骤4:本地验证

Run all relevant checks to verify the fixes:
bash
ruff check synapse/ tests/
bash
ruff format synapse/ tests/ --check
bash
uv run mypy synapse/
If test failures were involved:
bash
pytest
If any check still fails after the initial fix, attempt one more targeted fix for that category (max 1 retry per category). If it still fails after the retry, proceed to the error handling step.
运行所有相关检查以验证修复效果:
bash
ruff check synapse/ tests/
bash
ruff format synapse/ tests/ --check
bash
uv run mypy synapse/
如果涉及测试失败:
bash
pytest
如果初始修复后仍有检查失败,针对该类型再尝试一次修复(每个类型最多重试1次)。如果重试后仍失败,进入错误处理步骤。

Step 5: Commit and Push

步骤5:提交并推送

After all checks pass locally:
  1. Stage only modified files (do NOT stage untracked files):
    bash
    git add -u
  2. Commit with a descriptive message indicating which categories were fixed:
    bash
    git commit -m "fix: resolve CI failures (<categories>)"
    Where
    <categories>
    is a comma-separated list of what was fixed (e.g.,
    lint, format
    or
    test
    or
    format, lint, type, test
    ).
  3. Push to the current branch:
    bash
    git push
  4. Report a summary of what was fixed, including:
    • Which failure categories were detected
    • Which files were modified
    • Whether all local checks pass
本地所有检查通过后:
  1. 仅暂存已修改的文件(暂存未跟踪文件):
    bash
    git add -u
  2. 提交并添加描述性信息,说明修复的类型:
    bash
    git commit -m "fix: resolve CI failures (<categories>)"
    其中
    <categories>
    是修复的类型列表(例如:
    lint, format
    test
    format, lint, type, test
    )。
  3. 推送到当前分支:
    bash
    git push
  4. 报告修复摘要,包括:
    • 检测到的失败类型
    • 修改的文件
    • 本地所有检查是否通过

Step 6: Error Handling

步骤6:错误处理

  • gh CLI not authenticated: If
    gh run list
    fails with an authentication error, report "GitHub CLI is not authenticated. Run
    gh auth login
    first." and stop.
  • Fixes do not resolve the issue: If local verification still fails after one retry per category, report exactly what remains broken (include the error output) and stop. Do NOT commit partial fixes that leave CI in a broken state.
  • Never force-push: Always use
    git push
    , never
    git push --force
    or
    git push --force-with-lease
    .
  • gh CLI未认证:如果
    gh run list
    因认证错误失败,提示“GitHub CLI未认证,请先运行
    gh auth login
    。”并终止流程。
  • 修复未解决问题:如果本地验证在每个类型重试1次后仍失败,准确报告剩余的问题(包含错误输出)并终止流程。不要提交会导致CI仍处于失败状态的部分修复。
  • 禁止强制推送:始终使用
    git push
    ,绝不使用
    git push --force
    git push --force-with-lease

Examples

示例

Auto-diagnose and fix all CI failures

自动诊断并修复所有CI失败

/fix-ci
/fix-ci

Preview what would be fixed without applying changes

预览将修复的内容但不实际应用更改

/fix-ci --dry-run
/fix-ci --dry-run

Tool Configuration

工具配置

This project uses the following CI checks (from pyproject.toml):
本项目使用以下CI检查(配置来自pyproject.toml):

Ruff

Ruff

  • Target: Python 3.10
  • Line length: 88
  • Rules: E, F, I, UP, B, SIM
  • Ignored: E501, B008
  • Excluded: synapse/proto/a2a_pb2*.py
  • 目标版本:Python 3.10
  • 行长度:88
  • 规则:E、F、I、UP、B、SIM
  • 忽略规则:E501、B008
  • 排除文件:synapse/proto/a2a_pb2*.py

Mypy

Mypy

  • Strict mode with disallow_untyped_defs
  • Tests have relaxed rules (ignore_errors)
  • Proto files excluded
  • 严格模式,禁用无类型定义(disallow_untyped_defs)
  • 测试文件规则放宽(ignore_errors)
  • 排除Proto文件

Pytest

Pytest

  • asyncio_mode: auto
  • Run with:
    pytest
    or
    pytest tests/ -v
  • asyncio_mode: auto
  • 运行命令:
    pytest
    pytest tests/ -v