# Woodpecker CI/CD 流水线配置
# TDD工作流规范 - 质量门禁配置

pipeline:
  # 后端测试阶段
  test-backend:
    image: maven:3.9-openjdk-21
    commands:
      - echo "开始后端测试..."
      - mvn clean test jacoco:report
      - echo "后端测试完成，生成覆盖率报告"
    when:
      event: [push, pull_request]
    
  # 前端测试阶段
  test-frontend:
    image: node:18
    commands:
      - echo "开始前端测试..."
      - cd novalon-manage-web
      - npm install
      - npm run test:unit
      - npm run test:e2e
      - echo "前端测试完成"
    when:
      event: [push, pull_request]
    
  # 质量门禁检查
  quality-gates:
    image: maven:3.9-openjdk-21
    commands:
      - echo "开始质量门禁检查..."
      - mvn jacoco:check
      - echo "✅ 测试覆盖率检查通过"
      - echo "✅ 所有测试用例通过"
      - echo "✅ 代码规范检查通过"
    when:
      event: [pull_request]
    
  # 构建阶段
  build:
    image: maven:3.9-openjdk-21
    commands:
      - echo "开始构建..."
      - mvn clean package -DskipTests
      - echo "✅ 构建成功"
    when:
      event: [push]
      branch: [main, develop]
    
  # 安全扫描
  security-scan:
    image: aquasec/trivy:latest
    commands:
      - echo "开始安全漏洞扫描..."
      - trivy filesystem --severity HIGH,CRITICAL --exit-code 1 .
      - echo "✅ 安全扫描通过"
    when:
      event: [pull_request]
    
  # 部署到测试环境
  deploy-staging:
    image: alpine/k8s:1.29
    commands:
      - echo "部署到测试环境..."
      - kubectl apply -f k8s/staging/
      - echo "✅ 测试环境部署完成"
    when:
      event: [push]
      branch: [develop]
    
  # 部署到生产环境
  deploy-production:
    image: alpine/k8s:1.29
    commands:
      - echo "部署到生产环境..."
      - kubectl apply -f k8s/production/
      - echo "✅ 生产环境部署完成"
    when:
      event: [push]
      branch: [main]

# 工作流配置
workflows:
  # 开发分支工作流
  develop:
    when:
      event: [push]
      branch: [develop]
    steps:
      - test-backend
      - test-frontend
      - build
      - deploy-staging
  
  # 主分支工作流
  main:
    when:
      event: [push]
      branch: [main]
    steps:
      - test-backend
      - test-frontend
      - security-scan
      - build
      - deploy-production
  
  # Pull Request工作流
  pull-request:
    when:
      event: [pull_request]
    steps:
      - test-backend
      - test-frontend
      - quality-gates
      - security-scan

# 通知配置
notifications:
  slack:
    webhook: ${SLACK_WEBHOOK_URL}
    channel: '#ci-cd'
    on_success: true
    on_failure: true
    on_start: false

# 环境变量
environment:
  - JAVA_HOME=/usr/lib/jvm/java-21-openjdk
  - NODE_ENV=test

# 缓存配置
cache:
  paths:
    - ~/.m2/repository
    - novalon-manage-web/node_modules