git-ship

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit PR CI Merge

Commit PR CI Merge

Full commit-to-merge flow with CI bypassed via GitHub Actions API.
通过GitHub Actions API绕过CI的完整从提交到合并流程。

Workflow

工作流

1. Detect repo → 2. Disable workflows → 3. Branch → 4. Commit → 5. Push → 6. PR → 7. Merge → 8. Re-enable workflows → 9. Cleanup
1. Detect repo → 2. Disable workflows → 3. Branch → 4. Commit → 5. Push → 6. PR → 7. Merge → 8. Re-enable workflows → 9. Cleanup

Steps

步骤

1. Detect Repository

1. 检测仓库

Extract owner and repo from git remote:
bash
gh repo view --json owner,name --jq '[.owner.login, .name] | @tsv'
Store as
OWNER
and
REPO
for all subsequent gh api calls.
从git远程地址提取所有者和仓库名:
bash
gh repo view --json owner,name --jq '[.owner.login, .name] | @tsv'
将结果存储为
OWNER
REPO
,供后续所有gh api调用使用。

2. List and Disable Workflows

2. 列出并禁用工作流

Get all active workflows:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows --jq '.workflows[] | select(.state=="active") | [.id, .name] | @tsv'
Disable each PR-triggered workflow:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/disable -X PUT
Track disabled workflow IDs for re-enabling later. Only disable workflows that trigger on
pull_request
or
push
events. If unsure, disable all active workflows.
获取所有活跃工作流:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows --jq '.workflows[] | select(.state=="active") | [.id, .name] | @tsv'
禁用每个由PR触发的工作流:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/disable -X PUT
记录被禁用的工作流ID,方便后续重新启用。仅禁用触发事件为
pull_request
push
的工作流。如果不确定,可禁用所有活跃工作流。

3. Create Feature Branch

3. 创建功能分支

If on main/master, create a branch. Use
/commit
skill conventions for branch naming:
bash
git checkout -b chore/short-description
如果当前在main/master分支,创建新分支。分支命名遵循
/commit
技能的规范:
bash
git checkout -b chore/short-description

4. Commit

4. 提交

Use
/commit
skill for message generation.
Skill(skill="commit")
使用
/commit
技能生成提交信息。
Skill(skill="commit")

5. Push

5. 推送

bash
git push -u origin $(git branch --show-current)
bash
git push -u origin $(git branch --show-current)

6. Create PR

6. 创建PR

Use
/pr-create
skill for PR creation. Add a note in the PR body that CI was skipped.
Skill(skill="pr-create")
使用
/pr-create
技能创建PR,在PR正文中添加说明,告知本次提交跳过了CI。
Skill(skill="pr-create")

7. Merge via API

7. 通过API合并

First attempt: merge using the GitHub API with
--admin
flag:
bash
gh pr merge {PR_NUMBER} --squash --admin
If merge fails with review requirement error (HTTP 405 or "approving review is required"):
  1. Save current review protection settings:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews --jq '{dismiss_stale_reviews, require_code_owner_reviews, require_last_push_approval, required_approving_review_count}'
  1. Temporarily remove review requirement:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X DELETE
  1. Merge:
bash
gh pr merge {PR_NUMBER} --squash --admin
  1. Restore review protection using saved settings (use
    --input -
    with JSON to preserve boolean types):
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X PATCH --input - <<'EOF'
{saved settings JSON}
EOF
CRITICAL: Always restore branch protection, even if the merge fails. Use the saved settings from step 1 to restore the exact original configuration.
首次尝试:使用带
--admin
参数的GitHub API合并:
bash
gh pr merge {PR_NUMBER} --squash --admin
如果合并失败并提示审查要求错误(HTTP 405或“需要批准审查”):
  1. 保存当前的审查保护设置:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews --jq '{dismiss_stale_reviews, require_code_owner_reviews, require_last_push_approval, required_approving_review_count}'
  1. 临时移除审查要求:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X DELETE
  1. 合并:
bash
gh pr merge {PR_NUMBER} --squash --admin
  1. 使用保存的设置恢复审查保护(使用带JSON参数的
    --input -
    保留布尔类型):
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X PATCH --input - <<'EOF'
{saved settings JSON}
EOF
关键提示: 即使合并失败,也必须始终恢复分支保护。使用步骤1中保存的设置恢复完全一致的原始配置。

8. Re-enable Workflows

8. 重新启用工作流

Re-enable all previously disabled workflows:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/enable -X PUT
重新启用所有之前被禁用的工作流:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/enable -X PUT

9. Local Cleanup

9. 本地清理

bash
git checkout main && git pull && git branch -d {BRANCH_NAME}
bash
git checkout main && git pull && git branch -d {BRANCH_NAME}

Safety

安全注意事项

  • Never skip CI for code changes that affect behavior
  • Always re-enable workflows, even if merge fails
  • Track disabled workflow IDs to ensure none are left disabled
  • Appropriate for: renames, typos, config changes, documentation
  • Not appropriate for: feature code, security changes, dependency updates
  • 永远不要对影响功能的代码变更跳过CI
  • 即使合并失败,也要始终重新启用工作流
  • 记录被禁用的工作流ID,确保没有遗漏的被禁用工作流
  • 适用场景:重命名、拼写修正、配置变更、文档修改
  • 不适用场景:功能代码、安全相关变更、依赖更新