@@ -220,6 +220,105 @@ <h2>1.12 進階挑戰題</h2>
220220 < li > 研究 GitHub OAuth App 與 GitHub App 的差異(從 Settings → Developer settings),寫一段 150 字說明你會在什麼場景選擇哪一種。</ li >
221221</ ol >
222222
223+ < h2 > 1.13 專案級端到端 Worked Example:TechCo 公司 GitHub 基礎建設專案</ h2 >
224+ < p > 把本單元的知識(平台、認證、Organization、安全治理)放大到< strong > 整家公司</ strong > 的規模:所有設定都寫成程式碼(Infrastructure as Code),放進一個 < code > techco-infra</ code > repo,讓「公司怎麼用 GitHub」也可以審查、版本化、重現——這是單元 1.9「單一 repo 治理」之上的整站層級。</ p >
225+ < div class ="demo-grid ">
226+ < div class ="demo-block "> < div class ="demo-label "> 產出檔案樹 · FILE TREE</ div > < pre > techco-infra/
227+ ├── .github/
228+ │ ├── CODEOWNERS < span class ="hl-c "> # 設定變更需 DevOps 審查</ span >
229+ │ └── workflows/
230+ │ └── audit.yml < span class ="hl-c "> # 每晚稽核「設定有沒有漂移」</ span >
231+ ├── scripts/
232+ │ ├── bootstrap-org.sh < span class ="hl-c "> # 一次性初始化(延伸 1.9)</ span >
233+ │ └── apply-policies.sh < span class ="hl-c "> # 把策略套到所有 repo</ span >
234+ ├── policies/
235+ │ ├── org.yml < span class ="hl-c "> # org 層級規則</ span >
236+ │ └── branch-protection.json< span class ="hl-c "> # 標準保護分支設定</ span >
237+ └── README.md</ pre > </ div >
238+ < div class ="demo-block "> < div class ="demo-label "> 關鍵檔案 · KEY FILES</ div > < pre > < span class ="hl-c "> # policies/branch-protection.json(片段)</ span >
239+ {
240+ "required_status_checks": {
241+ "strict": true,
242+ "contexts": ["ci"]
243+ },
244+ "required_pull_request_reviews": {
245+ "required_approving_review_count": 2
246+ },
247+ "enforce_admins": true
248+ }
249+
250+ < span class ="hl-c "> # scripts/apply-policies.sh(核心迴圈)</ span >
251+ for repo in $(gh repo list TechCo \
252+ --json name --jq '.[].name'); do
253+ gh api --method PUT \
254+ "/repos/TechCo/$repo/branches/main/protection" \
255+ --input policies/branch-protection.json
256+ done</ pre > </ div >
257+ </ div >
258+ < div class ="demo-block ">
259+ < div class ="demo-label "> 驗證命令與輸出 · VERIFY</ div >
260+ < pre > < span class ="hl-c "> # 1. 驗證所有 repo 的保護分支都生效</ span >
261+ gh api /repos/TechCo/backend/branches/main/protection \
262+ --jq '.required_pull_request_reviews.required_approving_review_count'
263+ < span class ="hl-c "> # 輸出 → 2</ span >
264+
265+ < span class ="hl-c "> # 2. 稽核成員 2FA 狀態(org 稽核 log)</ span >
266+ gh api "/orgs/TechCo/audit-log" --paginate \
267+ --jq '.[] | select(.action=="org.two_factor_requirement_enabled")' | head -1
268+ < span class ="hl-c "> # 輸出 → {"action":"org.two_factor_requirement_enabled", ...}</ span >
269+
270+ < span class ="hl-c "> # 3. 全公司 repo 清單與可見性</ span >
271+ gh repo list TechCo --limit 100 --json name,visibility
272+ < span class ="hl-c "> # 輸出 → [{"name":"backend","visibility":"PRIVATE"}, ...]</ span > </ pre >
273+ </ div >
274+ < div class ="callout info "> < strong > 為什麼這是「專案級」:</ strong > 單元 1.9 只設定單一 repo;這裡把< strong > 整間公司</ strong > 當成一個專案在治理——用程式碼管策略、用 CI 稽核漂移、用 CODEOWNERS 讓重大變更有人把關。規模越大,「人按 UI 慢慢點」越不可行,改成「程式碼 + 自動化」才是正解。</ div >
275+
276+ < h2 > 1.14 效能 / 品質 / 安全深度</ h2 >
277+ < div class ="demo-grid ">
278+ < div class ="demo-block "> < div class ="demo-label "> 效能 · PERFORMANCE</ div > < pre > < span class ="hl-c "> # 傳輸與 API 面</ span >
279+ - git clone 用 SSH 比 HTTPS 少一層認證往返
280+ - API rate limit:認證 5,000 次/小時,批次優先
281+ - 大 repo 用 --filter=blob:none 只拉需要的物件
282+ - LFS 檔案走獨立 CDN,不卡 Git 傳輸
283+ < span class ="hl-c "> # 回報與儀表板</ span >
284+ - github.com/status 查平台可用性
285+ - gh api /rate_limit 檢查剩餘額度</ pre > </ div >
286+ < div class ="demo-block "> < div class ="demo-label "> 品質 · QUALITY</ div > < pre > 平台層品質由 GitHub 保證(SLA、Status Page),
287+ 你這一層的品質是「設定品質」:
288+ - 每條規則都有人負責(CODEOWNERS)
289+ - 設定進 repo:可 diff、可 review
290+ - 稽核 workflow 每天抓「設定漂移」
291+ - 新 repo 用預設範本(repo template)
292+ 自動帶上安全設定,避免「開局就裸奔」</ pre > </ div >
293+ < div class ="demo-block "> < div class ="demo-label "> 安全 · SECURITY</ div > < pre > 安全由上到下三層:
294+ 1. 身份層:SAML SSO + 強制 2FA
295+ 2. 存取層:最小權限 + 保護分支
296+ 3. 內容層:Secret Scanning + push protection
297+ 紅線:PAT 只用最小 scope、不放進 repo、
298+ 失效立刻撤銷;金鑰一律存密碼管理員。</ pre > </ div >
299+ </ div >
300+
301+ < h2 > 1.15 站際比較:GitHub vs GitLab vs Markdown vs YAML vs JSON</ h2 >
302+ < table >
303+ < tr > < th > 面向</ th > < th > github</ th > < th > gitlab</ th > < th > markdown</ th > < th > yaml</ th > < th > json</ th > </ tr >
304+ < tr > < td > 定位</ td > < td > 雲端程式碼託管平台</ td > < td > 雲端 / 自架 DevOps 平台</ td > < td > 輕量排版語法</ td > < td > 人類可讀設定格式</ td > < td > 資料交換格式</ td > </ tr >
305+ < tr > < td > 認證</ td > < td > PAT / SSH / OAuth</ td > < td > PAT / OAuth / SAML</ td > < td > —(不涉及)</ td > < td > —(不涉及)</ td > < td > —(不涉及)</ td > </ tr >
306+ < tr > < td > 組織治理</ td > < td > Organization + Teams</ td > < td > Group + Subgroups(權限更細)</ td > < td > —</ td > < td > —</ td > < td > —</ td > </ tr >
307+ < tr > < td > 與其他欄的關係</ td > < td > 全站以 Markdown 寫文件、YAML 寫 Actions、JSON 做 API 資料</ td > < td > 同左(CI 也用 YAML)</ td > < td > GitHub README / Issue 的載體</ td > < td > GitHub Actions workflow 的載體</ td > < td > GitHub REST API 的回應格式</ td > </ tr >
308+ </ table >
309+
310+ < h2 > 1.16 互動式進階檢核清單</ h2 >
311+ < div class ="demo-render ">
312+ < ul >
313+ < li > < label > < input type ="checkbox "> 我的帳號已開啟 2FA,並把救援碼備份到密碼管理員。</ label > </ li >
314+ < li > < label > < input type ="checkbox "> 我已建立 Organization(或至少知道其用途),並啟用 SSO / 強制 2FA。</ label > </ li >
315+ < li > < label > < input type ="checkbox "> 至少一個 repo 已套用保護分支(2 人 Approve + CI 通過)。</ label > </ li >
316+ < li > < label > < input type ="checkbox "> 我的 PAT 只授予必要 scope,且存放在密碼管理員而非 repo 或程式碼。</ label > </ li >
317+ < li > < label > < input type ="checkbox "> 我能從稽核 log 說出「最近一次權限變更」是誰、改什麼。</ label > </ li >
318+ < li > < label > < input type ="checkbox "> 我把公司/個人「GitHub 使用規則」寫成了文件(誰可建 repo、token 規則、誰負責)。</ label > </ li >
319+ </ ul >
320+ </ div >
321+
223322</ div >
224323< footer > 這是 GitHub 繁體中文教學站 · 由 OpenCode 建置< br >
225324 < span class ="footer-license "> 本站教學內容(繁體中文解說)為本站原創,採 CC-BY-4.0;技術名詞與操作引用自 < a href ="https://docs.github.com/ " rel ="noopener "> GitHub Docs</ a > 與 < a href ="https://git-scm.com/doc " rel ="noopener "> Git 官方文件</ a > 。</ span > </ footer >
0 commit comments