Communitygithub.com

lguidolin/合併閘門與自動化

用於設定或變更 CI、pre-push hook 或任務執行器,或用於決定合併前必須通過的檢查。典型症狀:僅在本機 hook 中設定權威檢查、跳過 CI、使用 --no-verify 繞過,或不清楚哪些檢查是合併閘門、哪些只是本機執行。

合併閘門與自動化 是什麼?

此技能定義了一套明確的開發流程原則,用以區分 CI(持續整合)與本機 hook 的角色。其核心思想是:CI 為驗證的權威來源,而本機 pre-push hook 僅是加速開發迴圈的便利鏡像,且明確可繞過(例如透過 --no-verify)。技能強調了單一任務執行器作為所有日常操作的規範入口、透過分層(presubmit / postsubmit)保持 CI 速度、容器映像必須在 CI 中建置並以內容摘要識別、以及明確宣告專案是採用「強制」(enforced)模式(透過分支保護阻止合併)還是「建議」(advisory)模式(依賴團隊紀律)。此技能適用於 Claude Code、Cursor、Codex 等 AI 代理,能幫助它們在設定 CI、hook 或任務執行器時做出正確的架構決策,避免將權威檢查錯誤地放在可繞過的本機 hook 中。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/merge-gates-and-automation

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

驗證閘門與自動化

概述

驗證邏輯存在於何處,以及它的真實效力。CI 是真相的來源;本機 hook 僅是便利的鏡像。 一項未經不可繞過閘門強制執行的規則,僅僅是個建議(原則 7)——因此,當平台無法提供該閘門時,專案應宣告為 advisory 模式,並有意地承擔該規則,而非假設其擁有實際上不存在的機制。

規則

  • 一個任務執行器是所有日常操作的規範入口——測試、建置、開發、部署均為已命名的配方。只存在於某人腦海中的程序無法可靠地發生,也無法交給代理執行。
  • CI 是真相的來源——權威、共享,且在平台允許的情況下不可繞過。 Lint、型別檢查、契約檢查、測試、安全掃描、提交驗證都在此執行,且在 enforced 模式下必須在合併前通過。CI 說了算。在 advisory 模式下,相同的檢查仍會執行並報告,閘門取決於紀律,而這絕不是減少檢查數量的理由。
  • Pre-push hook 是預提交鏡像,而非一道牆。 它在本機執行相同的快速檢查,讓你在推送前可能先通過 CI。它明確可繞過(--no-verify),且僅在安裝了工具鏈的環境中執行。其任務是速度與早期回饋,而非強制執行。Hook 永遠不是閘門;只要平台允許,CI 才是閘門。
  • 透過分層而非移除檢查來保持 CI 的速度。 當完整套件超出每個 PR 的負荷時,請拆分為 presubmit(快速子集,阻擋 PR)與 postsubmit(完整套件,合併後執行,阻擋晉升)——切勿將權威檢查移回可繞過的 hook 中。
  • 容器映像在 CI 中建置,以內容摘要識別,並附帶來源證明發佈。透過註冊表層快取或自託管執行器來控制成本——切勿將建置移回筆記型電腦,因為其他人無法驗證該工件(artifact)的來源。
  • 宣告強制執行模式。 enforced —— CI 透過分支保護阻止合併;CI 說了算。advisory —— CI 執行並報告,閘門取決於紀律,因為分支保護不可用(例如免費方案上的私有儲存庫)。Advisory 是合理的;謊稱擁有實際上不存在的強制執行則不然。在專案的第一個決策記錄中說明模式,以及什麼情況會使其轉為 enforced。

已命名的張力

可繞過的本機 presubmit 是快速但無法強制執行;權威的 CI 是可強制執行但較慢。解決方案是賦予它們不同的任務——hook 最佳化內部迴圈,CI 確保正確性的記錄——並讓 **CI(而非 hook)**成為阻擋合併的因素。

常見的合理化說詞

藉口現實
"Pre-push hook 已經跑了測試,所以 CI 可以很簡化"Hook 可繞過且依賴工具鏈,它不能是真相的來源。CI 必須重新執行所有項目。
"我就 --no-verify 這一次"沒問題——因為 CI 仍然會抓到問題。這正是由 CI(而非 hook)擔任閘門的原因。
"CI 太慢了,我們把測試移到 hook 裡吧"分層 CI(presubmit / postsubmit);切勿將權威檢查移到可繞過的閘門。
"CI 建置很慢,我在本機建置映像就好了"在本機建置的工件(artifact)所帶有的來源證明,其他人無法驗證。用層快取或自託管執行器來解決延遲問題。
"分支保護要花錢,所以規則不適用"規則仍然適用;強制執行的方式不同。宣告 advisory 模式並維持紀律,或將儲存庫設為公開以免費獲得保護。

紅旗 —— 立即停止

  • 僅存在於本機 hook 中的權威檢查
  • CI 不重新執行 hook 已執行過的檢查
  • CI 為紅燈時仍允許合併
  • 映像不是在 CI 中建置,或透過標籤而非摘要來晉升
  • 專案表現得好像 CI 可阻擋合併,但實際上不存在任何分支保護

完整原理:請參閱工程章程第八條,收錄於 engineering-constitution/references/engineering-constitution.md。部署 / K8s 相關細節:cloud-delivery-aks。

Individual skills in this repo

This repo contains 18 individual skills — each has its own dedicated page.

lguidolin/change-hygiene-and-code-craft

Use when writing or refactoring code, structuring a commit or PR, or deciding whether to abstract duplication. Symptoms — mixing reorg with logic changes, a PR doing several things at once, a file growing large, the second copy of similar code, or unsure whether to DRY something up.

lguidolin/cloud-delivery-aks

Use when deploying to Kubernetes or Azure Kubernetes Service (AKS), configuring cloud secrets, setting up progressive rollout/canary, per-PR ephemeral environments, or k8s health probes. Keywords — Kubernetes, AKS, Key Vault, Argo Rollouts, Flagger, canary, blue-green, liveness, readiness, PodDisruptionBudget, HPA, rollback, GHCR.

lguidolin/commit-history-rewrite

Use when an existing repository has messy commit history that needs to conform to conventional commits before adopting release-please, or when intermediate WIP/fixup/merge commits need to be cleaned up.

lguidolin/conventional-commits-and-releases

Use when committing, writing a commit message, opening a PR that will be squash-merged, or configuring automated versioning/changelogs. Keywords — conventional commits, release-please, semver, feat/fix/chore, breaking change, changelog.

lguidolin/defense-in-depth-security

Use when handling untrusted input, secrets, authentication/authorization, or dependencies — or threat-modeling a new surface. Keywords — STRIDE, threat model, least privilege, secrets management, supply chain, dependency scanning, input validation, audit log, defense in depth.

lguidolin/designing-before-building

Use when starting a feature, fixing a non-trivial bug, or about to write implementation code — before any code exists. Symptoms you need this: "this is simple, I'll just code it", reaching for the editor before a design is approved, or an idea that hasn't been turned into a spec and plan.

lguidolin/engineering-constitution

Use when starting work in a project that follows the engineering constitution, orienting to its rules, or deciding which engineering practice applies to a task — spec writing, commits, testing, security, deploys, database, or UI work.

lguidolin/graphql-contract-testing

Use when writing a GraphQL query/mutation that the UI and a test will share, or building route/schema contract or smoke tests. Symptoms — copying a query into a test, a test asserting on query text, schema change that didn't break the UI build, or RLS/permission drift. Keywords — graphql-codegen, typed document, contract test, route smoke test.

lguidolin/init-repo-CI

Use when setting up a new repository with conventional commits, release-please, and CI automation, or when retrofitting an existing repository that lacks automated versioning and PR validation workflows.

lguidolin/interface-craft-and-accessibility

Use when building or styling UI — components, layouts, forms, design tokens — or making accessibility decisions. Keywords — a11y, WCAG, keyboard navigation, focus state, contrast, design system, minimalist UI, component reuse, ARIA, semantic HTML.

lguidolin/observability-and-slos

Use when adding logging, metrics, tracing, health checks, SLOs, or alerting — or when building a service surface that needs to be operable and debuggable. Keywords — structured logs, OpenTelemetry, correlation id, RED metrics, liveness, readiness, SLI, SLO, error budget, alerting.

lguidolin/performance-and-scale

Use when working on hot paths, list endpoints, pagination, data-access in loops, or public interfaces/schemas. Symptoms — unbounded queries, N+1 access, no latency budget, optimizing without measuring, or changing an interface many consumers depend on. Keywords — pagination, N+1, Hyrum's Law, performance budget, bundle size.

lguidolin/postgres-postgraphile-rls-and-sql

Use when writing PostgreSQL, PostGraphile config, Row-Level Security policies, SQL schema files, or working on the Browser→App→PostGraphile→Postgres data path. Keywords — RLS, SECURITY DEFINER, search_path, pgSettings, grants, roles, GraphQL depth limit, query cost, statement_timeout, SQL file organization.

lguidolin/recording-decisions

Use when a design or architecture decision has been made and needs to be captured — writing a decision record or ADR, updating a decision index, noting a deferred idea, or superseding a past decision. Keywords — ADR, decision record, rationale, rejected alternatives, dependency index.

lguidolin/resilience-and-deploy-safety

Use when planning a deploy, designing a rollback, or responding to an incident or writing a postmortem. Keywords — deploy safety, rollback, immutable artifact, progressive delivery, canary, blast radius, incident response, blameless postmortem, error budget.

lguidolin/ship-it

Use when the user wants to ship work — push, PR, archive decision records, merge, and clean up. Handles the full lifecycle from committing final changes through post-merge cleanup including converting specs/plans to compact decision records.

lguidolin/tests-as-a-control

Use when writing or modifying tests, when a test breaks during a refactor, or when testing permission/role rules. Symptoms — tempted to edit a test to make it pass, testing only the happy path, a deny-test that started passing, flaky tests, or unsure what to assert.

lguidolin/zero-downtime-migrations

Use when changing a database schema where data must survive the change — adding/removing/renaming columns, constraints, indexes, or backfilling. Symptoms — a destructive migration bundled with a code deploy, a NOT NULL column with a backfill, a table-locking UPDATE, or a rename. Keywords — expand/contract, parallel change, backfill, NOT VALID, CREATE INDEX CONCURRENTLY, graphile-migrate.

相關技能