mirror of
https://github.com/insistence/RuoYi-Vue3-FastAPI.git
synced 2026-09-22 13:05:19 +00:00
175 lines
6.3 KiB
YAML
175 lines
6.3 KiB
YAML
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.10", "3.11", "3.12", "3.13"]
|
|
|
|
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 and default PyPI index
|
|
sed -e "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" \
|
|
-e 's| -i https://pypi.tuna.tsinghua.edu.cn/simple||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.10", "3.11", "3.12", "3.13"]
|
|
|
|
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.pg
|
|
cp ruoyi-fastapi-backend/Dockerfile.pg ruoyi-fastapi-backend/Dockerfile.pg.bak
|
|
# Create temporary Dockerfile with target Python version and default PyPI index
|
|
sed -e "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" \
|
|
-e 's| -i https://pypi.tuna.tsinghua.edu.cn/simple||g' \
|
|
ruoyi-fastapi-backend/Dockerfile.pg.bak > ruoyi-fastapi-backend/Dockerfile.pg
|
|
|
|
- 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.pg
|
|
if: always()
|
|
run: |
|
|
# Restore original Dockerfile.pg after test
|
|
mv ruoyi-fastapi-backend/Dockerfile.pg.bak ruoyi-fastapi-backend/Dockerfile.pg
|