# ============================================================ # CI/CD 工作流 # ============================================================ # 触发:push / PR # 任务:flake8 → type-check → pytest(含 MySQL/Redis 服务) # ============================================================ name: CI on: push: branches: [master, main] pull_request: jobs: lint-and-test: runs-on: ubuntu-latest # 依赖服务(供集成测试使用) services: mysql: image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: ci_password MYSQL_DATABASE: djangoadmin_flask_elevue_ci ports: - 3306:3306 options: >- --health-cmd="mysqladmin ping -h localhost" --health-interval=10s --health-timeout=5s --health-retries=5 redis: image: redis:7 ports: - 6379:6379 options: >- --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=5 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.12' cache: pip - name: 安装依赖 run: pip install -r requirements-dev.txt - name: 静态检查(flake8) run: flake8 src config tests --max-complexity=30 - name: 类型检查(mypy) run: mypy src || true - name: 单元测试(pytest) env: DB_HOST: 127.0.0.1 DB_PORT: 3306 DB_DATABASE: djangoadmin_flask_elevue_ci DB_USERNAME: root DB_PASSWORD: ci_password DB_SSL: 'False' REDIS_HOST: 127.0.0.1 REDIS_PORT: 6379 REDIS_AUTH: 'False' FLASK_DEBUG: 'False' FLASK_SECRET_KEY: ci-secret-key-0123456789abcdef JWT_SALT: ci-jwt-salt-0123456789abcdef run: pytest -v