setup-github
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub の設定
GitHub 的设置
設定はすべて で行う。対象リポジトリを とする。
どの手順も、同じ値で何度実行しても結果が変わらない。
ghREPO=<owner>/<name>所有设置均通过 完成。将目标仓库设置为 。
每个步骤都可以使用相同的值重复执行,结果不会发生变化。
ghREPO=<owner>/<name>1. アプリ名を変える
1. 更改应用名称
apps/web/app-name.tsAPP_NAMEAPP_NAMEapps/web/app-name.tsAPP_NAMEAPP_NAME2. secrets を登録する
2. 注册 secrets
値はユーザーに尋ねる。
sh
gh secret set OPENROUTER_API_KEY --repo "$REPO"
gh secret set CLAUDE_CODE_OAUTH_TOKEN --repo "$REPO"
gh secret set CLOUDFLARE_ACCOUNT_ID --repo "$REPO"
gh secret set CLOUDFLARE_API_TOKEN --repo "$REPO"| 名前 | 用途 |
|---|---|
| verify ワークフローの oxlint-plugin-decision |
| verify 失敗時に Claude Code が自動修正する |
| デプロイ先と Alchemy の状態を置くアカウント |
| 同じアカウントの API トークン |
Organization のリポジトリなら、Organization の secrets に一度登録すれば、各リポジトリでの登録は要らない。
向用户询问具体值。
sh
gh secret set OPENROUTER_API_KEY --repo "$REPO"
gh secret set CLAUDE_CODE_OAUTH_TOKEN --repo "$REPO"
gh secret set CLOUDFLARE_ACCOUNT_ID --repo "$REPO"
gh secret set CLOUDFLARE_API_TOKEN --repo "$REPO"| 名称 | 用途 |
|---|---|
| verify workflow 的 oxlint-plugin-decision |
| verify 失败时由 Claude Code 自动修复 |
| 存放部署目标及 Alchemy 状态的账户 |
| 同一账户的 API token |
如果仓库属于 Organization,只需在 Organization 的 secrets 中注册一次,无需在各仓库中分别注册。
3. Actions に PR の作成を許可する
3. 允许 Actions 创建 PR
release-please と自動修正が PR を作るためである。
sh
gh api --method PUT "repos/$REPO/actions/permissions/workflow" \
-f default_workflow_permissions=read -F can_approve_pull_request_reviews=true这是因为 release-please 和自动修复流程需要创建 PR。
sh
gh api --method PUT "repos/$REPO/actions/permissions/workflow" \
-f default_workflow_permissions=read -F can_approve_pull_request_reviews=true4. PR を作れる人を collaborator に限り、auto-merge を有効にする
4. 将可创建 PR 的人员限制为 collaborator,并启用 auto-merge
sh
gh api --method PATCH "repos/$REPO" -f pull_request_creation_policy=collaborators_only \
-F allow_auto_merge=true -F allow_update_branch=truesh
gh api --method PATCH "repos/$REPO" -f pull_request_creation_policy=collaborators_only \
-F allow_auto_merge=true -F allow_update_branch=true5. 既定ブランチを保護する
5. 保护默认分支
既定ブランチの削除と force push を禁じ、最新の既定ブランチを取り込んでいない PR のマージを拒むルールセットを置く。
取り込みの検査は、 ワークフローのチェックを必須にし、 を有効にして行う。
バイパスは置かない。release-please の PR は、Claude が既定ブランチを取り込んで push し、そこで動いた を通してからマージする。
同じ名前のルールセットがあれば置き換える。
up-to-datestrict_required_status_checks_policyup-to-datesh
id="$(gh api "repos/$REPO/rulesets" --jq '.[] | select(.name == "protect default branch") | .id')"
gh api --method "$([ -n "$id" ] && echo PUT || echo POST)" "repos/$REPO/rulesets${id:+/$id}" --input - <<'JSON'
{
"name": "protect default branch",
"target": "branch",
"enforcement": "active",
"conditions": { "ref_name": { "include": ["~DEFAULT_BRANCH"], "exclude": [] } },
"bypass_actors": [],
"rules": [
{ "type": "deletion" },
{ "type": "non_fast_forward" },
{
"type": "required_status_checks",
"parameters": {
"strict_required_status_checks_policy": true,
"do_not_enforce_on_create": false,
"required_status_checks": [{ "context": "up-to-date", "integration_id": 15368 }]
}
}
]
}
JSON禁止删除默认分支和 force push,并设置 ruleset,拒绝合并没有包含最新默认分支的 PR。
在合并检查中,将 workflow check 设为必需,并启用 。
不设置任何 bypass。release-please 的 PR 会由 Claude 合并默认分支并 push,通过在该分支上运行的 后再进行合并。
如果存在同名 ruleset,则予以替换。
up-to-datestrict_required_status_checks_policyup-to-datesh
id="$(gh api "repos/$REPO/rulesets" --jq '.[] | select(.name == "protect default branch") | .id')"
gh api --method "$([ -n "$id" ] && echo PUT || echo POST)" "repos/$REPO/rulesets${id:+/$id}" --input - <<'JSON'
{
"name": "protect default branch",
"target": "branch",
"enforcement": "active",
"conditions": { "ref_name": { "include": ["~DEFAULT_BRANCH"], "exclude": [] } },
"bypass_actors": [],
"rules": [
{ "type": "deletion" },
{ "type": "non_fast_forward" },
{
"type": "required_status_checks",
"parameters": {
"strict_required_status_checks_policy": true,
"do_not_enforce_on_create": false,
"required_status_checks": [{ "context": "up-to-date", "integration_id": 15368 }]
}
}
]
}
JSON6. 反映を確かめる
6. 确认设置已生效
gh api "repos/$REPO" --jq '[.pull_request_creation_policy, .allow_auto_merge]'["collaborators_only",true]gh api "repos/$REPO/rules/branches/main" --jq '[.[].type]'required_status_checks确认 返回 。
同时确认 中包含 。
gh api "repos/$REPO" --jq '[.pull_request_creation_policy, .allow_auto_merge]'["collaborators_only",true]gh api "repos/$REPO/rules/branches/main" --jq '[.[].type]'required_status_checks