|
| 1 | +name: Playwright Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + pull_request: |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +jobs: |
| 10 | + mysql-test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v5 |
| 19 | + |
| 20 | + - name: Set up Python ${{ matrix.python-version }} |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: ${{ matrix.python-version }} |
| 24 | + |
| 25 | + - name: Cache Docker layers |
| 26 | + uses: actions/cache@v5 |
| 27 | + with: |
| 28 | + path: /tmp/.docker_cache |
| 29 | + key: ${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('**/Dockerfile*', '**/requirements.txt') }} |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v3 |
| 33 | + |
| 34 | + - name: Create temporary Dockerfile with Python ${{ matrix.python-version }} |
| 35 | + run: | |
| 36 | + # Save original Dockerfile.my |
| 37 | + cp ruoyi-fastapi-backend/Dockerfile.my ruoyi-fastapi-backend/Dockerfile.my.bak |
| 38 | + # Create temporary Dockerfile with target Python version |
| 39 | + sed "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" ruoyi-fastapi-backend/Dockerfile.my.bak > ruoyi-fastapi-backend/Dockerfile.my |
| 40 | +
|
| 41 | + - name: Start services with docker-compose |
| 42 | + run: | |
| 43 | + cd ruoyi-fastapi-test |
| 44 | + docker compose -f docker-compose.test.my.yml up -d --build |
| 45 | +
|
| 46 | + - name: Wait for services to be ready |
| 47 | + run: | |
| 48 | + cd ruoyi-fastapi-test |
| 49 | + # Wait for backend to be running |
| 50 | + timeout 180 bash -c 'until docker compose -f docker-compose.test.my.yml ps ruoyi-backend-my | grep -q "Up"; do sleep 5; done' |
| 51 | + # Wait for frontend to be running |
| 52 | + timeout 120 bash -c 'until docker compose -f docker-compose.test.my.yml ps ruoyi-frontend | grep -q "Up"; do sleep 5; done' |
| 53 | + # Additional wait for services to be fully ready and listening on ports |
| 54 | + sleep 30 |
| 55 | + # Check that backend is actually responding on the API endpoint |
| 56 | + echo "Checking if backend service is ready..." |
| 57 | + for i in {1..30}; do |
| 58 | + if curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then |
| 59 | + echo "Backend service is ready!" |
| 60 | + break |
| 61 | + fi |
| 62 | + echo "Waiting for backend service to be ready... ($i/30)" |
| 63 | + sleep 5 |
| 64 | + done |
| 65 | + # Final check |
| 66 | + if ! curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then |
| 67 | + echo "Backend service failed to start properly. Checking logs..." |
| 68 | + docker logs ruoyi-backend-my-test |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + - name: Run tests |
| 73 | + run: | |
| 74 | + cd ruoyi-fastapi-test |
| 75 | + pip install -r requirements.txt |
| 76 | + playwright install |
| 77 | + pytest -v |
| 78 | +
|
| 79 | + - name: Stop services |
| 80 | + if: always() |
| 81 | + run: | |
| 82 | + cd ruoyi-fastapi-test |
| 83 | + docker compose -f docker-compose.test.my.yml down |
| 84 | +
|
| 85 | + - name: Restore original Dockerfile.my |
| 86 | + if: always() |
| 87 | + run: | |
| 88 | + # Restore original Dockerfile.my after test |
| 89 | + mv ruoyi-fastapi-backend/Dockerfile.my.bak ruoyi-fastapi-backend/Dockerfile.my |
| 90 | +
|
| 91 | + pg-test: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + strategy: |
| 94 | + fail-fast: false |
| 95 | + matrix: |
| 96 | + python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 97 | + |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v5 |
| 100 | + |
| 101 | + - name: Set up Python ${{ matrix.python-version }} |
| 102 | + uses: actions/setup-python@v5 |
| 103 | + with: |
| 104 | + python-version: ${{ matrix.python-version }} |
| 105 | + |
| 106 | + - name: Cache Docker layers |
| 107 | + uses: actions/cache@v5 |
| 108 | + with: |
| 109 | + path: /tmp/.docker_cache |
| 110 | + key: ${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('**/Dockerfile*', '**/requirements.txt') }} |
| 111 | + |
| 112 | + - name: Set up Docker Buildx |
| 113 | + uses: docker/setup-buildx-action@v3 |
| 114 | + |
| 115 | + - name: Create temporary Dockerfile with Python ${{ matrix.python-version }} |
| 116 | + run: | |
| 117 | + # Save original Dockerfile.my |
| 118 | + cp ruoyi-fastapi-backend/Dockerfile.my ruoyi-fastapi-backend/Dockerfile.my.bak |
| 119 | + # Create temporary Dockerfile with target Python version |
| 120 | + sed "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" ruoyi-fastapi-backend/Dockerfile.my.bak > ruoyi-fastapi-backend/Dockerfile.my |
| 121 | +
|
| 122 | + - name: Start services with docker-compose |
| 123 | + run: | |
| 124 | + cd ruoyi-fastapi-test |
| 125 | + docker compose -f docker-compose.test.pg.yml up -d --build |
| 126 | +
|
| 127 | + - name: Wait for services to be ready |
| 128 | + run: | |
| 129 | + cd ruoyi-fastapi-test |
| 130 | + # Wait for backend to be running |
| 131 | + timeout 180 bash -c 'until docker compose -f docker-compose.test.pg.yml ps ruoyi-backend-pg | grep -q "Up"; do sleep 5; done' |
| 132 | + # Wait for frontend to be running |
| 133 | + timeout 120 bash -c 'until docker compose -f docker-compose.test.pg.yml ps ruoyi-frontend | grep -q "Up"; do sleep 5; done' |
| 134 | + # Additional wait for services to be fully ready and listening on ports |
| 135 | + sleep 30 |
| 136 | + # Check that backend is actually responding on the API endpoint |
| 137 | + echo "Checking if backend service is ready..." |
| 138 | + for i in {1..30}; do |
| 139 | + if curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then |
| 140 | + echo "Backend service is ready!" |
| 141 | + break |
| 142 | + fi |
| 143 | + echo "Waiting for backend service to be ready... ($i/30)" |
| 144 | + sleep 5 |
| 145 | + done |
| 146 | + # Final check |
| 147 | + if ! curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then |
| 148 | + echo "Backend service failed to start properly. Checking logs..." |
| 149 | + docker logs ruoyi-backend-pg-test |
| 150 | + exit 1 |
| 151 | + fi |
| 152 | +
|
| 153 | + - name: Run tests |
| 154 | + run: | |
| 155 | + cd ruoyi-fastapi-test |
| 156 | + pip install -r requirements.txt |
| 157 | + playwright install |
| 158 | + pytest -v |
| 159 | +
|
| 160 | + - name: Stop services |
| 161 | + if: always() |
| 162 | + run: | |
| 163 | + cd ruoyi-fastapi-test |
| 164 | + docker compose -f docker-compose.test.pg.yml down |
| 165 | +
|
| 166 | + - name: Restore original Dockerfile.my |
| 167 | + if: always() |
| 168 | + run: | |
| 169 | + # Restore original Dockerfile.my after test |
| 170 | + mv ruoyi-fastapi-backend/Dockerfile.my.bak ruoyi-fastapi-backend/Dockerfile.my |
0 commit comments