# CI/CD Configuration ## Gitea Actions 本项目使用 Gitea Actions 实现 CI/CD 流水线。 ### 工作流文件 **1. `.gitea/workflows/tests.yml` - 自动化测试** 触发条件: - 每次 push 到 main 分支 - 每次创建 Pull Request 包含任务: - `test` - 运行集成测试,生成覆盖率报告 - `lint` - 代码质量检查(Black、Flake8、MyPy) **2. `.gitea/workflows/deploy.yml` - 自动化部署** 触发条件: - push 到 main 分支 → 部署到 staging 环境 - 创建 tag (v*) → 部署到 production 环境 当前状态:占位,待补充真实部署脚本 --- ## 本地验证 在推送前,可以本地运行验证: ### 运行测试 ```bash pytest tests/integration/ -v --cov=packages --cov=apps --cov-report=html ``` ### 代码格式化 ```bash black packages/ apps/ tests/ ``` ### 代码检查 ```bash # Flake8 flake8 packages/ apps/ tests/ --max-line-length=120 --extend-ignore=E203,W503 # MyPy mypy packages/ apps/ --ignore-missing-imports ``` ### 排序 imports ```bash isort packages/ apps/ tests/ ``` --- ## Gitea Actions 配置 ### 前提条件 1. Gitea 服务器需要启用 Actions 功能 2. 需要配置 Actions Runner ### 启用步骤 **在 Gitea 服务器上**: 1. 编辑 `/etc/gitea/app.ini`(或对应配置文件): ```ini [actions] ENABLED = true ``` 2. 重启 Gitea: ```bash systemctl restart gitea ``` 3. 安装 Actions Runner: ```bash # 下载 act_runner wget https://dl.gitea.com/act_runner/latest/act_runner-linux-amd64 chmod +x act_runner-linux-amd64 mv act_runner-linux-amd64 /usr/local/bin/act_runner # 注册 runner act_runner register --instance http://your-gitea-server --token YOUR_RUNNER_TOKEN # 运行 runner act_runner daemon ``` 4. 在仓库设置中启用 Actions --- ## 验证 CI/CD 推送代码后,在 Gitea 仓库页面查看: - Actions 标签页 - 查看工作流运行状态 - 查看测试结果和覆盖率报告 --- ## 故障排查 ### Actions 未触发 - 检查 Gitea 是否启用 Actions - 检查工作流文件路径是否正确(`.gitea/workflows/`) - 检查 YAML 语法是否正确 ### 测试失败 - 查看 Actions 日志 - 本地运行 `pytest tests/integration/ -v` - 检查依赖是否完整 ### Linting 失败 - 本地运行 `black --check packages/` - 本地运行 `flake8 packages/` - 修复后重新推送 --- ## 未来扩展 - [ ] 添加性能测试 - [ ] 添加安全扫描 - [ ] 添加 Docker 镜像构建 - [ ] 添加自动化部署脚本 - [ ] 添加 Slack/钉钉通知 --- **最后更新**: 2026-06-15 **状态**: 配置完成,待 Gitea Actions 启用