|
| 1 | +name: E2E Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main, develop] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + # Next.js rewrites /api/* to ${NEXT_PUBLIC_API_URL}/api/*, so only set the base URL |
| 10 | + NEXT_PUBLIC_API_URL: http://localhost:8000 |
| 11 | + # Use pymysql driver (installed via requirements.txt) |
| 12 | + DATABASE_URL: mysql+pymysql://root:123456@localhost:3306/task_manager |
| 13 | + REDIS_URL: redis://localhost:6379 |
| 14 | + ENVIRONMENT: development |
| 15 | + # Enable auto migration on backend startup |
| 16 | + DB_AUTO_MIGRATE: 'True' |
| 17 | + |
| 18 | +jobs: |
| 19 | + e2e-tests: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + timeout-minutes: 30 |
| 22 | + |
| 23 | + services: |
| 24 | + mysql: |
| 25 | + image: mysql:8.4 |
| 26 | + env: |
| 27 | + MYSQL_ROOT_PASSWORD: '123456' |
| 28 | + MYSQL_DATABASE: task_manager |
| 29 | + ports: |
| 30 | + - 3306:3306 |
| 31 | + options: >- |
| 32 | + --health-cmd="mysqladmin ping -h localhost" |
| 33 | + --health-interval=10s |
| 34 | + --health-timeout=5s |
| 35 | + --health-retries=5 |
| 36 | +
|
| 37 | + redis: |
| 38 | + image: redis:7 |
| 39 | + ports: |
| 40 | + - 6379:6379 |
| 41 | + options: >- |
| 42 | + --health-cmd="redis-cli ping" |
| 43 | + --health-interval=10s |
| 44 | + --health-timeout=5s |
| 45 | + --health-retries=5 |
| 46 | +
|
| 47 | + steps: |
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up Python |
| 52 | + uses: actions/setup-python@v5 |
| 53 | + with: |
| 54 | + python-version: '3.11' |
| 55 | + cache: 'pip' |
| 56 | + cache-dependency-path: backend/requirements.txt |
| 57 | + |
| 58 | + - name: Install backend dependencies |
| 59 | + working-directory: backend |
| 60 | + run: | |
| 61 | + python -m pip install --upgrade pip |
| 62 | + pip install -r requirements.txt |
| 63 | +
|
| 64 | + - name: Set up Node.js |
| 65 | + uses: actions/setup-node@v4 |
| 66 | + with: |
| 67 | + node-version: '20' |
| 68 | + cache: 'npm' |
| 69 | + cache-dependency-path: frontend/package-lock.json |
| 70 | + |
| 71 | + - name: Install frontend dependencies |
| 72 | + working-directory: frontend |
| 73 | + run: npm ci |
| 74 | + |
| 75 | + - name: Build frontend |
| 76 | + working-directory: frontend |
| 77 | + env: |
| 78 | + # Next.js rewrites /api/* to ${NEXT_PUBLIC_API_URL}/api/*, so only set the base URL |
| 79 | + NEXT_PUBLIC_API_URL: http://localhost:8000 |
| 80 | + run: npm run build |
| 81 | + |
| 82 | + - name: Install Playwright browsers |
| 83 | + working-directory: frontend |
| 84 | + run: npx playwright install chromium --with-deps |
| 85 | + |
| 86 | + - name: Start backend server |
| 87 | + working-directory: backend |
| 88 | + env: |
| 89 | + DATABASE_URL: mysql+pymysql://root:[email protected]:3306/task_manager |
| 90 | + REDIS_URL: redis://127.0.0.1:6379 |
| 91 | + ENVIRONMENT: development |
| 92 | + DB_AUTO_MIGRATE: 'True' |
| 93 | + INIT_DATA_ENABLED: 'True' |
| 94 | + INIT_DATA_DIR: ${{ github.workspace }}/backend/init_data |
| 95 | + # Add project root to PYTHONPATH so 'shared' module can be imported |
| 96 | + PYTHONPATH: ${{ github.workspace }} |
| 97 | + run: | |
| 98 | + uvicorn app.main:app --host 0.0.0.0 --port 8000 & |
| 99 | + echo "Backend server starting (with auto migration and YAML init enabled)..." |
| 100 | +
|
| 101 | + - name: Start frontend server |
| 102 | + working-directory: frontend |
| 103 | + env: |
| 104 | + # Next.js rewrites /api/* to ${NEXT_PUBLIC_API_URL}/api/*, so only set the base URL |
| 105 | + NEXT_PUBLIC_API_URL: http://localhost:8000 |
| 106 | + run: | |
| 107 | + npm start & |
| 108 | + echo "Frontend server starting..." |
| 109 | +
|
| 110 | + - name: Wait for services to be ready |
| 111 | + run: | |
| 112 | + echo "Waiting for backend..." |
| 113 | + for i in {1..60}; do |
| 114 | + if curl -s http://localhost:8000/api/health > /dev/null 2>&1 || curl -s http://localhost:8000/ > /dev/null 2>&1; then |
| 115 | + echo "Backend is ready!" |
| 116 | + break |
| 117 | + fi |
| 118 | + echo "Waiting for backend... ($i/60)" |
| 119 | + sleep 2 |
| 120 | + done |
| 121 | +
|
| 122 | + echo "Waiting for frontend..." |
| 123 | + for i in {1..30}; do |
| 124 | + if curl -s http://localhost:3000 > /dev/null 2>&1; then |
| 125 | + echo "Frontend is ready!" |
| 126 | + break |
| 127 | + fi |
| 128 | + echo "Waiting for frontend... ($i/30)" |
| 129 | + sleep 2 |
| 130 | + done |
| 131 | +
|
| 132 | + - name: Run E2E tests |
| 133 | + working-directory: frontend |
| 134 | + env: |
| 135 | + E2E_BASE_URL: http://localhost:3000 |
| 136 | + CI: true |
| 137 | + run: npm run e2e |
| 138 | + |
| 139 | + - name: Upload test results |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + if: always() |
| 142 | + with: |
| 143 | + name: e2e-test-results |
| 144 | + path: | |
| 145 | + frontend/e2e-results.json |
| 146 | + frontend/playwright-report/ |
| 147 | + frontend/test-results/ |
| 148 | + retention-days: 7 |
| 149 | + |
| 150 | + - name: Upload failure screenshots |
| 151 | + uses: actions/upload-artifact@v4 |
| 152 | + if: failure() |
| 153 | + with: |
| 154 | + name: e2e-failure-screenshots |
| 155 | + path: frontend/test-results/**/*.png |
| 156 | + retention-days: 7 |
0 commit comments