钉钉 AI 客服:CI/CD 流水线配置
自动化部署是高效开发的关键。
一、CI/CD 概念
| 概念 | 说明 |
|---|---|
| CI | 持续集成:代码提交后自动测试 |
| CD | 持续部署:测试通过后自动部署 |
二、GitHub Actions 配置
2.1 基础配置
# .github/workflows/ci.yml
name: CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npm test
- run: npm run lint
2.2 部署配置
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker image
run: docker build -t ai-chat:${{ github.sha }} .
- name: Push to registry
run: |
docker tag ai-chat:${{ github.sha }} registry.example.com/ai-chat:latest
docker push registry.example.com/ai-chat:latest
- name: Deploy to production
run: kubectl set image deployment/ai-chat ai-chat=registry.example.com/ai-chat:latest
三、代码质量检查
3.1 ESLint 配置
// .eslintrc.js
module.exports = {
env: { node: true, es2021: true },
extends: 'eslint:recommended',
rules: {
'no-unused-vars': 'error',
'no-console': 'warn',
'prefer-const': 'error'
}
};
3.2 测试覆盖率
- name: Coverage
run: npm test -- --coverage
- name: Upload coverage
uses: codecov/codecov-action@v3
四、自动化测试
4.1 单元测试
- name: Run unit tests
run: npm run test:unit
4.2 集成测试
- name: Run integration tests
run: npm run test:integration
4.3 E2E 测试
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run E2E tests
run: npm run test:e2e
五、安全扫描
5.1 依赖扫描
- name: Security scan
run: npm audit
- name: Upload results
uses: github/codeql-action/upload-sarif@v2
5.2 镜像扫描
- name: Scan image
uses: aquasecurity/trivy-action@master
with:
image-ref: 'ai-chat:latest'
format: 'table'
六、环境管理
6.1 多环境部署
jobs:
deploy-dev:
environment: development
steps:
- name: Deploy to dev
run: kubectl apply -f k8s/dev/
deploy-prod:
environment: production
needs: deploy-dev
steps:
- name: Deploy to prod
run: kubectl apply -f k8s/prod/
七、通知机制
7.1 钉钉通知
- name: Notify
if: always()
run: |
curl -X POST ${{ secrets.DINGTALK_WEBHOOK }} \
-H 'Content-Type: application/json' \
-d '{"msgtype":"text","text":{"content":"部署完成"}}'
八、版本管理
8.1 自动版本号
- name: Bump version
run: |
git config user.name "CI Bot"
git config user.email "ci@example.com"
npm version patch
git push --tags
项目地址:GitHub - dingtalk-connector-pro 有问题欢迎 Issue 或评论区交流