| name | auto-commit-cicd |
| description | 自动化代码提交 → 推送 → 创建 PR → CI 监控 → 合并 main 的完整工作流。如果 CI 失败,自动分析错误并修复,最多重试 3 次。 |
| disable-model-invocation | true |
| allowed-tools | Bash, Read, Grep, Glob, Edit, Write |
| model | sonnet |
| metadata | {"short-description":"自动化 Git 提交、推送、创建 PR、CI 监控与合并工作流"} |
auto-commit-cicd
TRIGGER
当用户说以下任一内容时调用本 skill:
- "提交代码" / "提交并推送" / "commit and push"
- "自动提交" / "auto commit" / "auto-commit"
- "提交到 master" / "合并到 master" / "merge to master"
- "运行 CI" / "run CI" / "触发 CI"
- "/auto-commit-cicd" (slash command)
工作流
Step 1: 检查工作区
In: 仓库当前状态
Out: clean working tree 信号 / 当前分支名 → Step 2 本地预检
Role: [L1 git] git status / git branch; [L4 主 AI] 决定是否需要 stash; [NOT] 不自动 stash(用户决定)
Done: [ ] 知道是否有 uncommitted 改动;[ ] 知道当前分支
cd "D:\windsulf\daugf2527-repos\harmonyos-libretro-emulator"
git status --short
- 如果有未提交改动 → 继续 Step 2
- 如果工作区干净 → 提示用户"没有需要提交的改动",退出
Step 2: 本地预检
In: Step 1 产出 clean working tree
Out: 本地 PASS / FAIL 信号 → Step 3 commit / 回 Step 4 修复
Role: [L1 脚本] bash scripts/check/quick_signals.sh; [L4 主 AI] 解读 FAIL 输出; [NOT] 不跳过 FAIL 直接 commit
Done: [ ] regression / hygiene / ui-fixes / cxx-build 全 PASS
在提交前运行本地 CI 脚本,确保代码符合项目规范:
cd "D:\windsulf\daugf2527-repos\harmonyos-libretro-emulator"
bash scripts/ci/check_repo_hygiene.sh
bash scripts/ci/check_regression_guards.sh
- 如果任一脚本失败 → 根据错误信息修复代码,修复后重新运行预检
- 两次预检均通过 → 继续 Step 3
常见预检错误修复指引:
merge conflict markers (冲突标记 <<<<<<<, =======, >>>>>>>) → 检查并移除残留的合并冲突标记
build cache directories (构建缓存目录) → 检查 .gitignore 中是否已排除
NativeBuffer 使用违规 → 确保使用 FromNativeWindowBuffer + Map/Unmap,不要用 mmap/munmap
LOG_DOMAIN 缺失 → 在源文件中添加 #define LOG_DOMAIN
TODO/FIXME 残留 → 替换为实现代码或移除
Step 3: 提交改动
In: Step 2 产出 PASS 信号
Out: 1 个新 commit(HEAD 推进)→ Step 4 push
Role: [L4 主 AI] 写 commit message(scope/type/why); [L1 git] git add + commit; [NOT] 不 --amend(创建 NEW commit),不 --no-verify
Done: [ ] commit message 含 scope/type;[ ] working tree clean
- 确认当前分支名:
git branch --show-current
git add 相关文件(排除 secrets、.env、二进制文件):
git diff --name-only
git ls-files --others --exclude-standard
- 生成符合项目规范的 commit message:
- 格式:
type(scope): 中文描述
- type: feat / fix / refactor / perf / ci / docs / chore
- 参考
git log --oneline -5 查看最近的提交风格
- 示例:
fix(perf): 提取 setInterval 动画组件避免全量 build() 重渲染
─── MANDATORY HUMAN CHECKPOINT — commit message 确认 ───
在执行子步骤 4(git commit)之前必须:
向用户展示子步骤 3 生成的完整 commit message 草稿(type/scope/标题/body
含 Co-Authored-By 行)。通过 AskUserQuestion 问 go / edit / abort:
- go → 进入子步骤 4 创建提交
- edit → 用户指明改哪里 → 回子步骤 3 修订 → 重新走本 checkpoint
- abort → 放弃提交,退出 skill(保留 working tree,不删 staged changes)
未收到明确 "go" 之前,禁止调用 git commit。
理由:commit 进入历史后 rewrite(amend / rebase / force-push)成本是
10 倍。让用户在 message 上拍一次板比 commit 后改廉价得多。
参考 .claude/skills/closed-loop/SKILL.md 第 274-295 行 CHECKPOINT D 同精神。
- 创建提交:
git commit -m "$(cat <<'EOF'
type(scope): 简要描述改动内容
更详细的说明(如有需要)。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
EOF
)"
Step 4: 推送并创建 PR
In: Step 3 产出 commit
Out: 远程 PR 链接 → Step 5 监控 CI
Role: [L1 gh] git push -u + gh pr create; [L4 主 AI] 写 PR title(<70 字符)+ body; [NOT] 不 force push 到 main/master
Done: [ ] PR 已创建;[ ] PR 链接已返回
- 推送当前分支到远端:
git push origin <current-branch>
如果分支尚未推送(no upstream),使用:
git push -u origin <current-branch>
- 创建 PR(合并到 master):
gh pr create \
--base master \
--head <current-branch> \
--title "<简洁的 PR 标题(≤70 字符)>" \
--body "$(cat <<'EOF'
## Summary
- <改动点 1>
- <改动点 2>
## Test Plan
- [ ] CI 通过(harmonyos-pr-ci.yml)
- [ ] 本地仓库卫生检查和回归守卫检查通过
🤖 Generated with [Claude Code](https://claude.com/claude-code)
EOF
)"
- 记录 PR URL(后续步骤会用到):
gh pr view --json url,number,state
Step 5: 监控 CI
In: Step 4 产出 PR 链接
Out: CI 全 PASS 信号 → Step 6 合并 / 进 Step 7 修复循环
Role: [L1 gh] gh pr checks --watch; [L4 主 AI] 解读 CI 失败原因; [NOT] 不跳过 CI 直接合并
Done: [ ] 所有 CI checks 状态已知;[ ] 全 PASS 进 Step 6,有 FAIL 进 Step 7
PR 创建后会自动触发 harmonyos-pr-ci.yml。监控 CI 状态:
gh pr checks
轮询策略:
- 每 60-90 秒检查一次 CI 状态(不超过 5 分钟的 prompt cache TTL)
- 如果所有 checks 状态为
pass → Step 6
- 如果任一 check 状态为
fail → Step 7(修复循环)
- 如果状态为
pending / in_progress → 继续等待
最大等待时间:30 分钟(harmonyos-pr-ci.yml 的 timeout 为 120 分钟,但通常 15-25 分钟完成)。
Step 6: 合并 PR
In: Step 5 产出 CI 全 PASS
Out: PR 已合并,main 分支推进 → 流程完成
Role: [L1 gh] gh pr merge --squash; [L4 主 AI] 经 user 确认合并(关键 PR)或自动合并(小修复); [NOT] 不 delete branch 没经 user 同意
Done: [ ] PR status = MERGED;[ ] working tree 清理完成
CI 全部通过后,合并 PR 到 master:
gh pr merge <PR_URL> --merge
--merge 创建 merge commit(保持提交历史完整)
- 如果合并冲突 → 提示用户手动解决冲突,退出 skill
报告最终状态:
- ✅ PR URL
- ✅ CI 通过
- ✅ 已合并到 master
Step 7: 修复循环(最多 3 次迭代)
In: Step 5 产出 CI FAIL 信号 + 失败 check 详情
Out: 修复 commit + 推送 → 回 Step 5 重新监控(最多迭代 3 次)
Role: [L4 主 AI] 解析 CI log + 找根因; [L4 主 AI] Edit 修复; [L1 git/gh] commit + push; [NOT] 第 3 次仍 FAIL 必须停止 + 报告给用户(不无限循环)
Done: [ ] CI 全 PASS(回 Step 6) OR [ ] 3 次迭代未通过 → 报告 user 介入
CI 失败时执行修复循环:
迭代计数器:从 1 开始,每次修复后递增。超过 3 次则退出并报告用户。
每次迭代的步骤:
- 获取 CI 失败的详细日志:
gh run list --branch <current-branch> --limit 1 --json databaseId,status,conclusion
gh run view <run-id> --log --job <job-id> 2>&1 | tail -200
-
分析错误原因(MCP 协同优先于纯 log 阅读 — 2026-05-26 ECP2 加;总览见 root CLAUDE.md "MCP / Skill 工具决策树"):
- 编译错误 → 检查语法、类型、导入;优先
mcp__cclsp__get_diagnostics_for_file 看 LSP 详细诊断(比 CI log tail 更精准定位)
- codelinter 错误 → 按 codelinter 报告修复;配合
mcp__cclsp__find_references 看违规函数 caller 是否一并要改
- 签名错误 → 检查 secrets 配置(无法自动修复,报告用户)
- HAP 构建错误 → 检查 build 脚本和配置;配合
mcp__ast-grep__find_code 找类似 build 配置 pattern
- 仓库卫生 / 回归守卫错误 → 参考 Step 2 的修复指引;配合
mcp__ast-grep__find_code 找类似违规 pattern(mmap( / TODO / 硬编码 timeout 等)
-
修复代码后提交:
git add <修复的文件>
git commit -m "$(cat <<'EOF'
fix(ci): 修复 CI 错误 — <简要描述>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
EOF
)"
git push origin <current-branch>
- 回到 Step 5 重新监控 CI
无法自动修复的情况(报告中止):
- GitHub secrets 或环境变量缺失
- 第三方服务不可用
- 分支保护规则阻止合并
- 3 次迭代后仍失败
安全约束
- 绝对不提交:
.env、credentials.json、*.p12、*.keystore、secrets.*
- 不 force push master 分支
- 不跳过 Git hooks(不使用
--no-verify、--no-gpg-sign)
- 修复循环上限:最多 3 次迭代,防止无限循环
- 合并前确认:CI 必须全部通过才能合并
项目信息
- 仓库:
https://github.com/daugf2527/harmonyos-libretro-emulator.git
- base 分支:
master
- CI 工作流:
harmonyos-pr-ci.yml(PR 触发)、ci.yml(push 到 master 触发)
- 提交格式:
type(scope): 中文描述(Conventional Commits)
本地 CI 脚本
| 脚本 | 作用 |
|---|
bash scripts/ci/check_repo_hygiene.sh | 仓库卫生检查(冲突标记、缓存目录、shell 语法) |
bash scripts/ci/check_regression_guards.sh | 回归守卫(NativeBuffer、LOG_DOMAIN、硬编码超时、TODO/FIXME) |