mirror of
https://github.com/insistence/RuoYi-Vue3-FastAPI.git
synced 2026-10-16 22:51:11 +00:00
feat: 新增E2E测试 (#57)
* feat: 新增E2E测试 * fix: 修复docker compose命令书写错误 * fix: 运行测试前执行`playwright install` * fix: 增强检查以尝试修复3.11连接拒绝的问题 * fix: 增加mysql服务检查 * fix: 修复python 3.9兼容性问题 * perf: 优化禁用验证码脚本 * feat: 新增pg测试 * fix: 修复pg测试检查服务名书写错误 * perf: 优化测试 * style: 格式化代码
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
name: Playwright Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
mysql-test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: /tmp/.docker_cache
|
||||
key: ${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('**/Dockerfile*', '**/requirements.txt') }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Create temporary Dockerfile with Python ${{ matrix.python-version }}
|
||||
run: |
|
||||
# Save original Dockerfile.my
|
||||
cp ruoyi-fastapi-backend/Dockerfile.my ruoyi-fastapi-backend/Dockerfile.my.bak
|
||||
# Create temporary Dockerfile with target Python version
|
||||
sed "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" ruoyi-fastapi-backend/Dockerfile.my.bak > ruoyi-fastapi-backend/Dockerfile.my
|
||||
|
||||
- name: Start services with docker-compose
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
docker compose -f docker-compose.test.my.yml up -d --build
|
||||
|
||||
- name: Wait for services to be ready
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
# Wait for backend to be running
|
||||
timeout 180 bash -c 'until docker compose -f docker-compose.test.my.yml ps ruoyi-backend-my | grep -q "Up"; do sleep 5; done'
|
||||
# Wait for frontend to be running
|
||||
timeout 120 bash -c 'until docker compose -f docker-compose.test.my.yml ps ruoyi-frontend | grep -q "Up"; do sleep 5; done'
|
||||
# Additional wait for services to be fully ready and listening on ports
|
||||
sleep 30
|
||||
# Check that backend is actually responding on the API endpoint
|
||||
echo "Checking if backend service is ready..."
|
||||
for i in {1..30}; do
|
||||
if curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
|
||||
echo "Backend service is ready!"
|
||||
break
|
||||
fi
|
||||
echo "Waiting for backend service to be ready... ($i/30)"
|
||||
sleep 5
|
||||
done
|
||||
# Final check
|
||||
if ! curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
|
||||
echo "Backend service failed to start properly. Checking logs..."
|
||||
docker logs ruoyi-backend-my-test
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
pip install -r requirements.txt
|
||||
playwright install
|
||||
pytest -v
|
||||
|
||||
- name: Stop services
|
||||
if: always()
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
docker compose -f docker-compose.test.my.yml down
|
||||
|
||||
- name: Restore original Dockerfile.my
|
||||
if: always()
|
||||
run: |
|
||||
# Restore original Dockerfile.my after test
|
||||
mv ruoyi-fastapi-backend/Dockerfile.my.bak ruoyi-fastapi-backend/Dockerfile.my
|
||||
|
||||
pg-test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: /tmp/.docker_cache
|
||||
key: ${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('**/Dockerfile*', '**/requirements.txt') }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Create temporary Dockerfile with Python ${{ matrix.python-version }}
|
||||
run: |
|
||||
# Save original Dockerfile.my
|
||||
cp ruoyi-fastapi-backend/Dockerfile.my ruoyi-fastapi-backend/Dockerfile.my.bak
|
||||
# Create temporary Dockerfile with target Python version
|
||||
sed "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" ruoyi-fastapi-backend/Dockerfile.my.bak > ruoyi-fastapi-backend/Dockerfile.my
|
||||
|
||||
- name: Start services with docker-compose
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
docker compose -f docker-compose.test.pg.yml up -d --build
|
||||
|
||||
- name: Wait for services to be ready
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
# Wait for backend to be running
|
||||
timeout 180 bash -c 'until docker compose -f docker-compose.test.pg.yml ps ruoyi-backend-pg | grep -q "Up"; do sleep 5; done'
|
||||
# Wait for frontend to be running
|
||||
timeout 120 bash -c 'until docker compose -f docker-compose.test.pg.yml ps ruoyi-frontend | grep -q "Up"; do sleep 5; done'
|
||||
# Additional wait for services to be fully ready and listening on ports
|
||||
sleep 30
|
||||
# Check that backend is actually responding on the API endpoint
|
||||
echo "Checking if backend service is ready..."
|
||||
for i in {1..30}; do
|
||||
if curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
|
||||
echo "Backend service is ready!"
|
||||
break
|
||||
fi
|
||||
echo "Waiting for backend service to be ready... ($i/30)"
|
||||
sleep 5
|
||||
done
|
||||
# Final check
|
||||
if ! curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
|
||||
echo "Backend service failed to start properly. Checking logs..."
|
||||
docker logs ruoyi-backend-pg-test
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
pip install -r requirements.txt
|
||||
playwright install
|
||||
pytest -v
|
||||
|
||||
- name: Stop services
|
||||
if: always()
|
||||
run: |
|
||||
cd ruoyi-fastapi-test
|
||||
docker compose -f docker-compose.test.pg.yml down
|
||||
|
||||
- name: Restore original Dockerfile.my
|
||||
if: always()
|
||||
run: |
|
||||
# Restore original Dockerfile.my after test
|
||||
mv ruoyi-fastapi-backend/Dockerfile.my.bak ruoyi-fastapi-backend/Dockerfile.my
|
||||
Reference in New Issue
Block a user