开发全流程质量门禁守护者
简介
提供从预提交到部署后的全链路质量门禁配置指南,集成CI/CD最佳实践,帮助团队拦截代码缺陷、保障交付质量。
原始描述
Quality checkpoints at every development stage — pre-commit through post-deploy — with configuration examples, threshold tables, bypass protocols, and CI/CD integration. Use when setting up quality automation, configuring CI pipelines, establishing coverage thresholds, or defining deployment requirements.
通过你的 Agent 添加
安装目录:quality-gates/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
quality-gates 是一份系统化的软件质量门禁配置手册,为开发团队提供从代码提交到生产部署的全流程质量检查方案。它将质量管控划分为六大关键节点:Pre-commit(预提交)、Pre-push(预推送)、Pre-merge(预合并)、Pre-deploy Staging(预部署-测试环境)、Pre-deploy Production(预部署-生产环境)以及 Post-deploy(部署后监控)。每个节点明确定义了检查内容、执行时机、阻断策略及具体配置示例。
显著优点
- 体系化完整:覆盖开发全生命周期,从本地开发钩子到云端 CI/CD 流水线,再到部署后监控,形成闭环质量管理
- 配置即代码:提供大量可直接使用的配置模板,涵盖 Husky + lint-staged、GitHub Actions、GitLab CI、pre-commit 框架等主流工具链
- 量化可执行:明确定义覆盖率阈值(80% 行覆盖率)、性能预算(150KB 主包体积)、响应时间 SLA(P95 < 300ms)等可度量指标
- 安全优先:内置 Secrets 扫描(gitleaks、TruffleHog)、依赖漏洞审计(npm audit、Trivy)、CODEOWNERS 强制评审等多重安全机制
- 灵活有原则:提供 Gate Bypass 协议,在紧急情况下允许有记录的例外处理,既保证流程刚性又保留必要灵活性
潜在局限
- 配置示例以 Node.js 和 Python 为主,Go、Rust、Java 等其他语言生态的示例相对较少
- 性能阈值和覆盖率标准偏激进(如 80% 行覆盖率),小型团队或遗留项目可能难以立即达标
- 未涉及混沌工程、渐进式发布等进阶质量实践
- 作为纯文档型 Skill,不提供自动化工具或脚手架生成能力
适合人群
- 正在建立或优化 CI/CD 流程的 DevOps/SRE 工程师
- 需要规范团队代码质量标准的 Tech Lead 或架构师
- 希望从"救火模式"转向"预防模式"的研发团队
- 需要通过 SOC2、ISO27001 等合规认证的企业技术团队
常规风险
- 配置误用风险:直接复制粘贴阈值配置可能导致与现有项目不匹配,引发流水线频繁失败或开发者绕过门禁
- 工具版本漂移:引用的 GitHub Action 版本(如
actions/checkout@v4)可能随时间推移需要更新 - Bypass 滥用:虽然有明确协议,但紧急通道在实际操作中可能被滥用,需要配套审计机制
- 性能测试环境差异:CI 环境的性能基准与生产环境可能存在差异,导致"通过门禁但生产仍慢"的盲区
技能正文
name: quality-gates
model: fast
category: testing
description: Quality checkpoints at every development stage — pre-commit through post-deploy — with configuration examples, threshold tables, bypass protocols, and CI/CD integration. Use when setting up quality automation, configuring CI pipelines, establishing coverage thresholds, or defining deployment requirements.
version: 1.0
Quality Gates
Enforce quality checkpoints at every stage of the development lifecycle. Each gate defines what is checked, when it runs, and whether it blocks progression.
When to Use
- Before committing — catch lint errors, formatting issues, type errors, and secrets before they enter history
- Before merging — ensure full test suites pass, coverage thresholds are met, and code has been reviewed
- Before deploying — validate integration tests, security scans, and performance budgets in staging
- During code review — verify that all automated gates have passed and manual review criteria are satisfied
- After deploying — monitor health checks, error rates, and performance baselines
Gate Overview
Gate
When
Checks
Blocking?
Pre-commit
git commit
Lint, format, type-check, secrets scan
Yes
Pre-push
git push
Unit tests, build verification
Yes
Pre-merge
PR/MR approval
Full test suite, code review, coverage threshold
Yes
Pre-deploy (staging)
Deploy to staging
Integration tests, smoke tests, security scan
Yes
Pre-deploy (production)
Deploy to production
Staging verification, load test, rollback plan
Yes
Post-deploy
After production deploy
Health checks, error rate monitoring, perf baselines
Alerting
Pre-commit Setup
Husky + lint-staged (Node.js)
{
"lint-staged": {
"*.{js,ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md,yaml}": ["prettier --write"]
}
}
npx husky init
echo "npx lint-staged" > .husky/pre-commit
Pre-commit framework (Python)
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
hooks:
- id: mypy
Secrets Scanning (pre-commit hook)
| Gate | When | Checks | Blocking? |
|---|---|---|---|
| Pre-commit | git commit |
Lint, format, type-check, secrets scan | Yes |
| Pre-push | git push |
Unit tests, build verification | Yes |
| Pre-merge | PR/MR approval | Full test suite, code review, coverage threshold | Yes |
| Pre-deploy (staging) | Deploy to staging | Integration tests, smoke tests, security scan | Yes |
| Pre-deploy (production) | Deploy to production | Staging verification, load test, rollback plan | Yes |
| Post-deploy | After production deploy | Health checks, error rate monitoring, perf baselines | Alerting |
Pre-commit Setup
Husky + lint-staged (Node.js)
{
"lint-staged": {
"*.{js,ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md,yaml}": ["prettier --write"]
}
}
npx husky init
echo "npx lint-staged" > .husky/pre-commit
Pre-commit framework (Python)
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
hooks:
- id: mypy
#!/bin/sh
# .git/hooks/pre-commit
gitleaks protect --staged --verbose
if [ $? -ne 0 ]; then
echo "Secrets detected. Commit blocked."
exit 1
fi
CI/CD Gate Configuration
GitHub Actions
name: Quality Gates
on:
pull_request:
branches: [main]
jobs:
lint-and-typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm run lint
- run: npm run typecheck
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm test -- --coverage
- name: Check coverage threshold
run: |
COVERAGE=$(jq '.total.lines.pct' coverage/coverage-summary.json)
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage $COVERAGE% is below 80% threshold"
exit 1
fi
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm audit --audit-level=high
- uses: gitleaks/gitleaks-action@v2
build:
needs: [lint-and-typecheck, unit-tests, security-scan]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm run build
Set these as required status checks in branch protection rules so PRs cannot merge until all gates pass.
Coverage Gates
Type
Minimum Threshold
Notes
Unit tests
80% line coverage
Per-file and aggregate
Integration tests
60% of integration points
API endpoints, DB queries
E2E tests
100% of critical paths
Auth, checkout, core workflows
No decrease rule
0% regression allowed
New code must not lower overall coverage
Enforcing Thresholds
| Type | Minimum Threshold | Notes |
|---|---|---|
| Unit tests | 80% line coverage | Per-file and aggregate |
| Integration tests | 60% of integration points | API endpoints, DB queries |
| E2E tests | 100% of critical paths | Auth, checkout, core workflows |
| No decrease rule | 0% regression allowed | New code must not lower overall coverage |
// jest.config.js or vitest.config.ts
{
"coverageThreshold": {
"global": {
"branches": 75,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}
For the no decrease rule, compare coverage against the base branch in CI and fail if the delta is negative.
Security Gates
Dependency Scanning
| Ecosystem | Tool | Command |
|---|---|---|
| Node.js | npm audit | npm audit --audit-level=high |
| Python | pip-audit | pip-audit --strict |
| Rust | cargo audit | cargo audit |
| Go | govulncheck | govulncheck ./... |
| Universal | Trivy | trivy fs --severity HIGH,CRITICAL . |
Secret Detection
Tool
Use Case
Command
gitleaks
Pre-commit and CI
gitleaks protect --staged
TruffleHog
Deep history scan
trufflehog git file://. --only-verified
detect-secrets
Baseline-aware scanning
detect-secrets scan --baseline .secrets.baseline
Performance Gates
Bundle Size Budgets
{
"bundlesize": [
{ "path": "dist/main.*.js", "maxSize": "150 kB" },
{ "path": "dist/vendor.*.js", "maxSize": "250 kB" },
{ "path": "dist/**/*.css", "maxSize": "30 kB" }
]
}
Lighthouse CI Thresholds
{
"ci": {
"assert": {
"assertions": {
"categories:performance": ["error", { "minScore": 0.9 }],
"categories:accessibility": ["error", { "minScore": 0.95 }],
"categories:best-practices": ["error", { "minScore": 0.9 }],
"first-contentful-paint": ["error", { "maxNumericValue": 2000 }],
"largest-contentful-paint": ["error", { "maxNumericValue": 2500 }],
"cumulative-layout-shift": ["error", { "maxNumericValue": 0.1 }]
}
}
}
}
API Response Time Limits
Endpoint Type
P50
P95
P99
Read (GET)
< 100ms
< 300ms
< 500ms
Write (POST/PUT)
< 200ms
< 500ms
< 1000ms
Search/aggregate
< 300ms
< 800ms
< 2000ms
Health check
< 50ms
< 100ms
< 200ms
| Tool | Use Case | Command |
|---|---|---|
| gitleaks | Pre-commit and CI | gitleaks protect --staged |
| TruffleHog | Deep history scan | trufflehog git file://. --only-verified |
| detect-secrets | Baseline-aware scanning | detect-secrets scan --baseline .secrets.baseline |
Bundle Size Budgets
{
"bundlesize": [
{ "path": "dist/main.*.js", "maxSize": "150 kB" },
{ "path": "dist/vendor.*.js", "maxSize": "250 kB" },
{ "path": "dist/**/*.css", "maxSize": "30 kB" }
]
}
{
"ci": {
"assert": {
"assertions": {
"categories:performance": ["error", { "minScore": 0.9 }],
"categories:accessibility": ["error", { "minScore": 0.95 }],
"categories:best-practices": ["error", { "minScore": 0.9 }],
"first-contentful-paint": ["error", { "maxNumericValue": 2000 }],
"largest-contentful-paint": ["error", { "maxNumericValue": 2500 }],
"cumulative-layout-shift": ["error", { "maxNumericValue": 0.1 }]
}
}
}
}
API Response Time Limits
Endpoint Type
P50
P95
P99
Read (GET)
< 100ms
< 300ms
< 500ms
Write (POST/PUT)
< 200ms
< 500ms
< 1000ms
Search/aggregate
< 300ms
< 800ms
< 2000ms
Health check
< 50ms
< 100ms
< 200ms
| Endpoint Type | P50 | P95 | P99 |
|---|---|---|---|
| Read (GET) | < 100ms | < 300ms | < 500ms |
| Write (POST/PUT) | < 200ms | < 500ms | < 1000ms |
| Search/aggregate | < 300ms | < 800ms | < 2000ms |
| Health check | < 50ms | < 100ms | < 200ms |
Enforce via load testing tools (k6, Artillery) in CI with pass/fail thresholds.
Review Gates
Required Approvals
| Change Scope | Approvals Required |
|---|---|
| Standard code changes | 1 approval minimum |
| Infrastructure, auth, payments, data models | 2 approvals |
| Dependency updates, cryptographic changes | Security team approval |
CODEOWNERS
# .github/CODEOWNERS
* @team/engineering
/infra/ @team/platform
/src/auth/ @team/security
/src/payments/ @team/payments @team/security
*.sql @team/data-engineering
Dockerfile @team/platform
Gate Bypass Protocol
When Bypass Is Acceptable
- Hotfixes for production incidents with active user impact
- Trivial changes (typos, comments) where automated checks are overkill
- Dependency updates that break CI due to upstream issues (not your code)
Required Documentation for Every Bypass
- Reason — why the gate cannot pass right now
- Risk assessment — what could go wrong by skipping
- Follow-up ticket — link to an issue that tracks resolving the bypass
- Approver — name of the senior engineer or lead who authorized the bypass
NEVER Do
- NEVER disable gates permanently — fix the root cause, don't remove the guardrail
- NEVER commit secrets — even to "test" branches; git history is forever
- NEVER skip tests to unblock a deploy — if tests fail, the code is not ready
- NEVER merge with failing required checks — admin merge bypasses erode team trust
- NEVER set coverage thresholds to 0% — even a low threshold is better than none
- NEVER bypass security scans for speed — vulnerabilities in production cost far more than CI minutes
- NEVER rely solely on post-deploy gates — catching issues after users are impacted is damage control, not quality
- NEVER treat alerting gates as optional — post-deploy monitoring exists because pre-deploy gates cannot catch everything; ignoring alerts defeats the purpose
# .github/CODEOWNERS
* @team/engineering
/infra/ @team/platform
/src/auth/ @team/security
/src/payments/ @team/payments @team/security
*.sql @team/data-engineering
Dockerfile @team/platform
When Bypass Is Acceptable
- Reason — why the gate cannot pass right now
- Risk assessment — what could go wrong by skipping
- Follow-up ticket — link to an issue that tracks resolving the bypass
- Approver — name of the senior engineer or lead who authorized the bypass
NEVER Do
- NEVER disable gates permanently — fix the root cause, don't remove the guardrail
- NEVER commit secrets — even to "test" branches; git history is forever
- NEVER skip tests to unblock a deploy — if tests fail, the code is not ready
- NEVER merge with failing required checks — admin merge bypasses erode team trust
- NEVER set coverage thresholds to 0% — even a low threshold is better than none
- NEVER bypass security scans for speed — vulnerabilities in production cost far more than CI minutes
- NEVER rely solely on post-deploy gates — catching issues after users are impacted is damage control, not quality
- NEVER treat alerting gates as optional — post-deploy monitoring exists because pre-deploy gates cannot catch everything; ignoring alerts defeats the purpose
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。