Feature/ha #557
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Playwright Tests | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| paths-ignore: | |
| - 'apps/docs/**' | |
| - '*.md' | |
| - 'README.md' | |
| - 'CHANGELOG.md' | |
| - 'LICENSE' | |
| pull_request: | |
| paths-ignore: | |
| - 'apps/docs/**' | |
| - '*.md' | |
| - 'README.md' | |
| - 'CHANGELOG.md' | |
| - 'LICENSE' | |
| branches: [ main, master ] | |
| jobs: | |
| playwright-tests: | |
| timeout-minutes: 60 | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| database: [postgres, mongo, sqlite] | |
| config: [dev, bundle] | |
| steps: | |
| # Prepare environment and dependencies | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| - name: Install dependencies | |
| run: npm install -g pnpm && pnpm install | |
| - name: Install Playwright Browsers | |
| run: pnpm exec playwright install --with-deps | |
| # Prepare environment file | |
| - name: Create .env file | |
| run: | | |
| cat > .env << EOF | |
| # Database Configuration | |
| DB_TYPE=${{ matrix.database }} | |
| DB_HOST=database | |
| DB_PORT=${{ matrix.database == 'postgres' && '5432' || matrix.database == 'mongo' && '27017' }} | |
| DB_NAME=${{ matrix.database == 'sqlite' && '/app/data/peekaping.db' || 'peekaping' }} | |
| DB_USER=${{ matrix.database == 'postgres' && 'peekaping' || matrix.database == 'mongo' && 'root' || 'root' }} | |
| DB_PASS=password | |
| REDIS_HOST="redis" | |
| REDIS_PORT=6379 | |
| REDIS_PASSWORD="" | |
| REDIS_DB=0 | |
| # Server Configuration | |
| CLIENT_URL=http://localhost:8383 | |
| SERVER_PORT=8034 | |
| BUNDEBUG=2 | |
| EOF | |
| # Create and prepare data directories with proper permissions | |
| - name: Prepare data directories | |
| run: | | |
| mkdir -p .data/postgres .data/mongodb .data/logs .data/caddy-data .data/caddy-config | |
| sudo chown -R 999:999 .data/postgres .data/logs # postgres user is typically uid 999 | |
| sudo chown -R 999:999 .data/mongodb # mongodb user is typically uid 999 | |
| sudo chmod -R 755 .data/logs | |
| sudo chmod -R 700 .data/postgres | |
| sudo chmod -R 755 .data/mongodb | |
| ls -la .data/ | |
| echo "Directory permissions set successfully" | |
| # Build and start services using appropriate docker-compose file | |
| - name: Start services with docker-compose | |
| run: docker compose -f docker-compose.${{ matrix.config }}.${{ matrix.database }}.yml up -d --build | |
| - name: Show container logs | |
| run: | | |
| echo "=== Container Status ===" | |
| docker compose -f docker-compose.${{ matrix.config }}.${{ matrix.database }}.yml ps | |
| echo "=== Container Logs ===" | |
| docker compose -f docker-compose.${{ matrix.config }}.${{ matrix.database }}.yml logs | |
| - name: Wait for services to be ready | |
| run: | | |
| echo "Waiting for services to be healthy..." | |
| HEALTH_URL="http://localhost:${{ matrix.config == 'bundle' && '8383' || '8034' }}/api/v1/health" | |
| timeout 120 bash -c ' | |
| attempt=1 | |
| until curl -f '"$HEALTH_URL"'; do | |
| echo "Attempt $attempt: Health check failed, retrying in 5 seconds..." | |
| response=$(curl -s '"$HEALTH_URL"' || echo "connection failed") | |
| status_code=$(curl -s -o /dev/null -w "%{http_code}" '"$HEALTH_URL"' || echo "000") | |
| echo " Status Code: $status_code" | |
| echo " Response Body: $response" | |
| attempt=$((attempt + 1)) | |
| sleep 5 | |
| if [ $attempt -gt 20 ]; then | |
| echo "=== Container Status ===" | |
| docker compose -f docker-compose.${{ matrix.config }}.${{ matrix.database }}.yml ps | |
| echo "=== Logs ===" | |
| docker compose -f docker-compose.${{ matrix.config }}.${{ matrix.database }}.yml logs | |
| fi | |
| done | |
| ' || echo "Health check timed out after 120 seconds" | |
| echo "Health check succeeded! Waiting additional 5 seconds for stability..." | |
| sleep 5 | |
| - name: Run Playwright tests | |
| run: pnpm exec playwright test | |
| - name: Stop services | |
| if: always() | |
| run: docker compose -f docker-compose.${{ matrix.config }}.${{ matrix.database }}.yml down | |
| - uses: actions/upload-artifact@v4 | |
| if: ${{ !cancelled() }} | |
| with: | |
| name: playwright-report-${{ matrix.config }}-${{ matrix.database }} | |
| path: playwright-report/ | |
| retention-days: 30 |