feat: 重构测试框架并优化代码结构
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests style: 为Java类添加文档注释 docs: 更新.gitignore和配置文件 test: 添加性能测试和Playwright测试脚本 chore: 清理旧测试文件和配置
This commit is contained in:
+138
-133
@@ -1,155 +1,160 @@
|
||||
pipeline:
|
||||
name: Novalon Manage System CI/CD
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop ]
|
||||
pull_request:
|
||||
branches: [ main, develop ]
|
||||
|
||||
variables:
|
||||
DOCKER_REGISTRY: registry.example.com
|
||||
DOCKER_IMAGE: novalon-manage-system
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
environment:
|
||||
POSTGRES_DB: manage_system
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
ports:
|
||||
- 55432:5432
|
||||
|
||||
steps:
|
||||
- name: Backend Build
|
||||
build:
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- mvn clean compile -DskipTests
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: novalon-manage-api/**
|
||||
- mvn clean install -DskipTests -B
|
||||
|
||||
- name: Backend Test
|
||||
package:
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- mvn verify
|
||||
environment:
|
||||
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/manage_system
|
||||
SPRING_DATASOURCE_USERNAME: postgres
|
||||
SPRING_DATASOURCE_PASSWORD: postgres
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: novalon-manage-api/**
|
||||
- mvn package -DskipTests -B
|
||||
depends_on:
|
||||
- build
|
||||
|
||||
- name: Backend Coverage Report
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
docker-build-gateway:
|
||||
image: docker:latest
|
||||
commands:
|
||||
- cd novalon-manage-api/manage-sys
|
||||
- echo "Coverage report generated at target/site/jacoco/index.html"
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: novalon-manage-api/**
|
||||
- cd novalon-manage-api/manage-gateway
|
||||
- docker build -t novalon/manage-gateway:${CI_COMMIT_SHA:0:8} .
|
||||
- docker tag novalon/manage-gateway:${CI_COMMIT_SHA:0:8} novalon/manage-gateway:latest
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
depends_on:
|
||||
- package
|
||||
|
||||
- name: Frontend Install
|
||||
image: node:21-alpine
|
||||
docker-build-app:
|
||||
image: docker:latest
|
||||
commands:
|
||||
- cd novalon-manage-web
|
||||
- npm ci
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: novalon-manage-web/**
|
||||
- cd novalon-manage-api/manage-app
|
||||
- docker build -t novalon/manage-app:${CI_COMMIT_SHA:0:8} .
|
||||
- docker tag novalon/manage-app:${CI_COMMIT_SHA:0:8} novalon/manage-app:latest
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
depends_on:
|
||||
- package
|
||||
|
||||
- name: Frontend Build
|
||||
image: node:21-alpine
|
||||
commands:
|
||||
- cd novalon-manage-web
|
||||
- npm run build
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: novalon-manage-web/**
|
||||
|
||||
- name: Frontend Test
|
||||
image: node:21-alpine
|
||||
commands:
|
||||
- cd novalon-manage-web
|
||||
- npm run test
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: novalon-manage-web/**
|
||||
|
||||
- name: E2E Test Setup
|
||||
image: python:3.13-alpine
|
||||
commands:
|
||||
- cd e2e_tests
|
||||
- pip install -r requirements.txt
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: e2e_tests/**
|
||||
|
||||
- name: Start Backend
|
||||
image: docker:dind
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- docker build -t novalon-manage-api .
|
||||
- docker run -d --name backend -p 8080:8080 --network host novalon-manage-api
|
||||
detach: true
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: novalon-manage-api/** or e2e_tests/**
|
||||
|
||||
- name: Run E2E Tests
|
||||
image: python:3.13-alpine
|
||||
commands:
|
||||
- cd e2e_tests
|
||||
- pytest tests/ -v --cov=. --cov-report=xml --cov-report=html
|
||||
environment:
|
||||
API_BASE_URL: http://backend:8080
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_PORT: 5432
|
||||
DATABASE_NAME: manage_system
|
||||
DATABASE_USERNAME: postgres
|
||||
DATABASE_PASSWORD: postgres
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: e2e_tests/**
|
||||
|
||||
- name: Code Coverage Report
|
||||
image: plugins/coverage
|
||||
settings:
|
||||
server: https://coverage.example.com
|
||||
token: ${COVERAGE_TOKEN}
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
path: e2e_tests/**
|
||||
|
||||
- name: Build Docker Image
|
||||
image: docker:dind
|
||||
commands:
|
||||
- docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${CI_COMMIT_SHA:0:8} -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest .
|
||||
- docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${CI_COMMIT_SHA:0:8}
|
||||
- docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest
|
||||
when:
|
||||
branch: [main, develop]
|
||||
event: push
|
||||
|
||||
- name: Deploy to Staging
|
||||
deploy-staging:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- echo "Deploying to staging environment"
|
||||
- sh deploy-staging.sh
|
||||
secrets: [ staging_ssh_key, staging_host ]
|
||||
- echo "Branch: ${CI_COMMIT_BRANCH}"
|
||||
- echo "Commit: ${CI_COMMIT_SHA}"
|
||||
secrets: [ staging_ssh_key ]
|
||||
when:
|
||||
branch: [develop]
|
||||
event: push
|
||||
- event: push
|
||||
branch: develop
|
||||
depends_on:
|
||||
- docker-build-gateway
|
||||
- docker-build-app
|
||||
|
||||
- name: Deploy to Production
|
||||
deploy-production:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- echo "Deploying to production environment"
|
||||
- sh deploy-production.sh
|
||||
secrets: [ production_ssh_key, production_host ]
|
||||
- echo "Branch: ${CI_COMMIT_BRANCH}"
|
||||
- echo "Commit: ${CI_COMMIT_SHA}"
|
||||
secrets: [ production_ssh_key ]
|
||||
when:
|
||||
branch: [main]
|
||||
event: push
|
||||
- event: push
|
||||
branch: main
|
||||
depends_on:
|
||||
- docker-build-gateway
|
||||
- docker-build-app
|
||||
|
||||
# ========== 阶段1:快速反馈(提交时) ==========
|
||||
# 后端单元测试(在novalon-manage-api项目中运行)
|
||||
backend-unit-test:
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- mvn test -B
|
||||
depends_on:
|
||||
- build
|
||||
when:
|
||||
- event: push
|
||||
|
||||
# 前端单元测试(在novalon-manage-web项目中运行)
|
||||
frontend-unit-test:
|
||||
image: node:20
|
||||
commands:
|
||||
- cd novalon-manage-web
|
||||
- npm install
|
||||
- npm run test:unit
|
||||
when:
|
||||
- event: push
|
||||
|
||||
# ========== 阶段2:全面验证(合并前) ==========
|
||||
# 集成测试(在tests_suite中运行)
|
||||
integration-test:
|
||||
image: python:3.13
|
||||
commands:
|
||||
- cd tests_suite
|
||||
- pip install -r requirements.txt
|
||||
- playwright install chromium
|
||||
- pytest tests/integration/ -v --tb=short --no-cov
|
||||
depends_on:
|
||||
- build
|
||||
when:
|
||||
- event: pull_request
|
||||
|
||||
# E2E测试(在tests_suite中运行)
|
||||
e2e-test:
|
||||
image: python:3.13
|
||||
commands:
|
||||
- cd tests_suite
|
||||
- pip install -r requirements.txt
|
||||
- playwright install chromium
|
||||
- pytest tests/e2e/ -v --tb=short --no-cov
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
when:
|
||||
- event: pull_request
|
||||
|
||||
# ========== 阶段3:生产验证(部署前) ==========
|
||||
# 性能测试(在tests_suite中运行)
|
||||
performance-test:
|
||||
image: python:3.13
|
||||
commands:
|
||||
- cd tests_suite
|
||||
- pip install -r requirements.txt
|
||||
- pytest tests/performance/ -v --no-cov
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
when:
|
||||
- event: tag
|
||||
|
||||
# 安全测试(在tests_suite中运行)
|
||||
security-test:
|
||||
image: python:3.13
|
||||
commands:
|
||||
- cd tests_suite
|
||||
- pip install -r requirements.txt
|
||||
- pytest tests/security/ -v --no-cov
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
when:
|
||||
- event: deployment
|
||||
|
||||
notify:
|
||||
image: plugins/slack
|
||||
settings:
|
||||
webhook: ${SLACK_WEBHOOK}
|
||||
channel: ci-cd
|
||||
username: woodpecker
|
||||
icon_url: https://woodpecker-ci.org/img/logo.svg
|
||||
when:
|
||||
- status: [ success, failure ]
|
||||
depends_on:
|
||||
- build
|
||||
- test
|
||||
- package
|
||||
- backend-unit-test
|
||||
- frontend-unit-test
|
||||
- integration-test
|
||||
- e2e-test
|
||||
- performance-test
|
||||
- security-test
|
||||
- deploy-staging
|
||||
- deploy-production
|
||||
Reference in New Issue
Block a user