Communitygithub.com

lguidolin/合并门控与自动化

在设置或更改CI、pre-push钩子或任务运行器,或决定合并前必须通过哪些检查时使用。症状——倾向于只在本地钩子中放入权威检查,跳过CI,使用 --no-verify 绕过,或不确定哪些检查是合并门控而哪些仅在本地运行。

合并门控与自动化 是什么?

该技能指导开发者和AI代理如何正确设置验证门控与自动化,确保代码质量检查的权威性。核心原则是:CI是唯一可信的来源,本地钩子只是便捷的镜像,允许被绕过。技能详细定义了“强制”和“建议”两种执行模式:在平台支持的分支保护下,CI阻塞合并;在平台不支持时,项目明确声明为“建议”模式,依靠纪律而非机械强制。此外,技能提供了分层的CI策略(presubmit/postsubmit),确保快速反馈的同时不牺牲权威检查;还规定容器镜像必须在CI中构建,通过内容摘要和来源证明确保可验证性。常见误区(如将权威检查移至本地钩子、以CI缓慢为由降级检查)被一一列举并驳斥,同时列出了需要立即停止的红旗行为。

兼容平台~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是真理的源头;本地钩子只是一个便捷的镜像。 一个未被不可绕过的门控强制执行的规则只是一个建议(原则7)——因此,当平台无法提供这样的门控时,项目声明为advisory(建议)模式,并有意地遵循规则,而不是假设它不具备的机制。

规则

  • 一个任务运行器是每个日常操作的规范入口——测试、构建、开发、部署都是命名的配方。只存在于某人脑海中的流程无法可靠地执行,也无法交给代理。
  • CI是真理的源头——权威、共享,并且在平台允许的地方不可绕过。 Lint、类型检查、合约检查、测试、安全扫描、提交验证都在这里运行,并且在enforced(强制)模式下必须在合并前通过。CI说了算。在advisory模式下,相同的检查运行并报告;门控依靠纪律,这绝不是减少检查数量的理由。
  • pre-push钩子是一个提交前镜像,而不是一堵墙。 它本地运行相同的快速检查,这样你可能在推送前就通过了CI。它明确是可绕过的(--no-verify),并且只在安装了工具链的地方运行。它的职责是速度和早期反馈,而不是强制执行。钩子从不门控;只要平台允许,CI门控。
  • 通过分层而不是移除检查来保持CI快速。 当完整套件超出每个PR的负荷时,将presubmit(快速子集,阻塞PR)与postsubmit(完整套件,合并后运行,阻塞提升)分开——永远不要将权威检查移回可绕过的钩子。
  • 容器镜像在CI中构建,通过内容摘要标识,并附带来源证明发布。通过注册表层缓存或自托管运行器保持成本可控——永远不要将构建移回笔记本电脑,在那里其他人无法验证产物的来源。
  • 声明强制模式。 enforced(强制)——CI通过分支保护阻塞合并;CI说了算。advisory(建议)——CI运行并报告,门控依靠纪律,因为分支保护不可用(例如私有仓库的免费计划)。建议是合法的;声称拥有你并不具备的强制能力则是不合理的。在项目的第一个决策记录中声明模式,以及什么条件会使其变为强制。

命名的张力

一个可绕过的本地提交前检查快速但不可强制执行;权威的CI可强制执行但较慢。通过赋予它们不同的职责来解决——钩子优化内部循环,CI优化记录的正确性——并且让CI,而不是钩子,成为阻塞合并的因素。

常见合理化

借口现实
“pre-push钩子运行了测试,所以CI可以最小化”钩子是可绕过的且依赖工具链。它不能作为真理的源头。CI必须重新运行所有内容。
“我就这一次用 --no-verify 绕过”没关系——因为CI仍然会抓住它。这正是CI而不是钩子作为门控的原因。
“CI太慢了,把测试移到钩子里吧”分层CI(presubmit/postsubmit);永远不要将权威检查迁移到可绕过的门控。
“CI构建太慢了,我本地构建镜像吧”笔记本电脑构建的产物携带无人能验证的来源。使用层缓存或自托管运行器解决延迟问题。
“分支保护要花钱,所以规则不适用”规则适用;执行方式不同。声明建议模式并保持纪律,或者将仓库设为公开以免费获得保护。

红旗——立即停止

  • 权威检查仅存在于本地钩子中
  • CI不重新运行钩子已运行的检查
  • 在CI为红色时允许合并
  • 镜像在CI以外的任何地方构建,或者通过标签而非摘要进行提升
  • 项目表现得像CI门控了合并,但实际上不存在分支保护

完整理由:章程第八章,捆绑在 engineering-constitution/references/engineering-constitution.md 中。部署/kubernetes 细节: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.

相关技能