Skip to content

fix: frontend upload option method error #4

fix: frontend upload option method error

fix: frontend upload option method error #4

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
NODE_VERSION: '18'
PYTHON_VERSION: '3.11'
jobs:
# 前端测试和构建
frontend-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
- name: Run Prettier check
run: npm run format -- --check
- name: Run tests
run: npm run test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./frontend/coverage/lcov.info
flags: frontend
- name: Build frontend
run: npm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: frontend-build
path: frontend/dist
# 后端测试
backend-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: test_password
POSTGRES_USER: test_user
POSTGRES_DB: test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run Black formatter check
run: black --check .
- name: Run isort check
run: isort --check-only .
- name: Run flake8 linter
run: flake8 .
- name: Run mypy type checker
run: mypy .
- name: Run tests with pytest
env:
DATABASE_URL: postgresql://test_user:test_password@localhost:5432/test_db
REDIS_URL: redis://localhost:6379/0
SECRET_KEY: test-secret-key
run: pytest --cov=app --cov-report=xml --cov-report=html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./backend/coverage.xml
flags: backend
# Docker 构建测试
docker-build:
runs-on: ubuntu-latest
needs: [frontend-test, backend-test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build backend Docker image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: false
tags: kb-backend:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build frontend Docker image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: false
tags: kb-frontend:test
cache-from: type=gha
cache-to: type=gha,mode=max
# 集成测试
integration-test:
runs-on: ubuntu-latest
needs: [docker-build]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Start services with Docker Compose
run: |
docker-compose -f docker-compose.test.yml up -d
sleep 30 # 等待服务启动
- name: Run integration tests
run: |
# 这里可以添加集成测试脚本
docker-compose -f docker-compose.test.yml exec -T backend pytest tests/integration/
- name: Stop services
run: docker-compose -f docker-compose.test.yml down
# 部署到开发环境
deploy-dev:
runs-on: ubuntu-latest
needs: [integration-test]
if: github.ref == 'refs/heads/develop'
steps:
- name: Deploy to development
run: |
echo "Deploying to development environment..."
# 这里添加部署脚本
# 部署到生产环境
deploy-prod:
runs-on: ubuntu-latest
needs: [integration-test]
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to production
run: |
echo "Deploying to production environment..."
# 这里添加生产部署脚本