Files
novalon-website/docs/deployment/quality-gates-ci.md
T
2026-03-24 13:32:01 +08:00

105 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CI/CD中的质量门禁
## 概述
质量门禁不仅在本地的Git hooks中运行,也在CI/CD流水线中执行,确保所有合并到主分支的代码都符合质量标准。
## Woodpecker CI配置
### 质量检查步骤
`.woodpecker.yml` 中添加质量检查步骤:
```yaml
pipeline:
quality-check:
image: node:18-alpine
environment:
NODE_ENV: test
commands:
- npm ci
- npm run lint
- npm run type-check
- npm run test:coverage
when:
event:
- push
- pull_request
coverage-report:
image: node:18-alpine
environment:
NODE_ENV: test
commands:
- npm ci
- npm run test:coverage
# 上传覆盖率报告到Codecov或其他服务
secrets: [codecov_token]
when:
event:
- pull_request
```
### 质量门禁规则
CI/CD中的质量门禁规则:
1. **代码检查**: ESLint必须通过,无错误
2. **类型检查**: TypeScript编译必须成功
3. **测试通过**: 所有测试必须通过
4. **覆盖率达标**: 代码覆盖率必须≥70%
### 失败处理
如果质量检查失败:
1. CI/CD流水线失败
2. 阻止合并到主分支
3. 发送通知给开发者
4. 显示详细的错误信息
## 本地开发 vs CI/CD
### 本地开发
- **优点**: 快速反馈,立即发现问题
- **缺点**: 可能被绕过(--no-verify
### CI/CD
- **优点**: 强制执行,无法绕过
- **缺点**: 反馈延迟,需要等待CI运行
### 最佳实践
1. **本地优先**: 在本地运行质量检查,确保通过后再推送
2. **CI兜底**: CI/CD作为最后一道防线,确保质量
3. **快速反馈**: CI/CD配置为快速失败,尽早发现问题
## 持续改进
### 监控质量指标
定期监控以下指标:
- 代码覆盖率趋势
- ESLint错误数量
- TypeScript错误数量
- 测试失败率
- CI/CD通过率
### 优化质量门禁
根据监控数据优化质量门禁:
1. 调整覆盖率阈值
2. 添加新的质量检查
3. 优化检查性能
4. 改进错误提示
## 参考资料
- [Woodpecker CI文档](https://woodpecker-ci.org/)
- [Codecov文档](https://docs.codecov.com/)
- [GitHub Actions文档](https://docs.github.com/en/actions)