Merge pull request #470 from ets-cfuhrman-pfe/Minh-Khoi-Le/issue469 #2
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: Integration - Frontend E2E Tests on Preprod | |
| on: | |
| push: | |
| branches: [ staging ] | |
| workflow_dispatch: | |
| jobs: | |
| e2e-tests: | |
| name: Run Frontend E2E Tests Against Preprod | |
| runs-on: [self-hosted, preprod] | |
| env: | |
| PREPROD_PATH: ${{ vars.PREPROD_PATH || '/opt/EvalueTonSavoir' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Verify runner environment | |
| run: | | |
| echo "=== Runner Information ===" | |
| echo "Runner OS: $RUNNER_OS" | |
| echo "Runner Architecture: $RUNNER_ARCH" | |
| echo "Runner Name: $RUNNER_NAME" | |
| echo "Runner Workspace: $RUNNER_WORKSPACE" | |
| echo "=== System Information ===" | |
| uname -a | |
| whoami | |
| pwd | |
| echo "=== Docker Information ===" | |
| docker --version | |
| docker compose version | |
| - name: Verify preprod environment is running | |
| run: | | |
| echo "Checking if preprod services are running..." | |
| # Check if services are running | |
| if ! docker compose -f ${{ env.PREPROD_PATH }}/docker-compose.yaml ps | grep -q "Up"; then | |
| echo "Preprod services are not running. Please start them manually or ensure they are running." | |
| echo "Run: cd ${{ env.PREPROD_PATH }} && docker compose up -d" | |
| exit 1 | |
| fi | |
| echo "Preprod services are running:" | |
| docker compose -f ${{ env.PREPROD_PATH }}/docker-compose.yaml ps | |
| - name: Copy test files to runner workspace | |
| run: | | |
| # Copy the client directory with E2E tests to the runner workspace | |
| cp -r ${{ github.workspace }}/client /tmp/e2e-client-${{ github.run_id }} | |
| - name: Ensure test user exists | |
| run: | | |
| echo "Ensuring test user exists..." | |
| # Try to login with the test user to check if it exists | |
| LOGIN_RESPONSE=$(curl -s -X POST http://localhost:3000/api/auth/simple-auth/login \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"email\": \"${TEST_USER_EMAIL}\", \"password\": \"${TEST_USER_PASSWORD}\"}") | |
| if echo "$LOGIN_RESPONSE" | grep -q "error\|User not found"; then | |
| echo "Test user does not exist or login failed. Creating test user..." | |
| # Create the test user via simple auth register | |
| CREATE_RESPONSE=$(curl -s -X POST http://localhost:3000/api/auth/simple-auth/register \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"email\": \"${TEST_USER_EMAIL}\", \"password\": \"${TEST_USER_PASSWORD}\", \"name\": \"Integration Test Bot\"}") | |
| if echo "$CREATE_RESPONSE" | grep -q "\"message\":\"User created\"\|\"success\":true"; then | |
| echo "Test user created successfully" | |
| else | |
| echo "Failed to create test user: $CREATE_RESPONSE" | |
| exit 1 | |
| fi | |
| else | |
| echo "Test user already exists" | |
| fi | |
| env: | |
| TEST_USER_EMAIL: ${{ secrets.E2E_TEST_USER_EMAIL || secrets.TEST_USER_EMAIL }} | |
| TEST_USER_PASSWORD: ${{ secrets.E2E_TEST_USER_PASSWORD || secrets.TEST_USER_PASSWORD }} | |
| - name: Build Playwright test image | |
| run: | | |
| cd /tmp/e2e-client-${{ github.run_id }} | |
| docker build -f Dockerfile.playwright -t evaluetonsavoir-e2e-${{ github.run_id }} . | |
| - name: Validate E2E secrets | |
| run: | | |
| if [ -z "${{ secrets.E2E_TEST_USER_EMAIL }}" ] || [ -z "${{ secrets.E2E_TEST_USER_PASSWORD }}" ]; then | |
| echo "E2E_TEST_USER_EMAIL or E2E_TEST_USER_PASSWORD secret missing. Please add them to the repo secrets." | |
| exit 1 | |
| fi | |
| - name: Run Playwright tests in Docker | |
| run: | | |
| docker run --rm \ | |
| --add-host host.docker.internal:host-gateway \ | |
| -v /tmp/e2e-client-${{ github.run_id }}/playwright-report:/app/client/playwright-report \ | |
| -v /tmp/e2e-client-${{ github.run_id }}/test-results:/app/client/test-results \ | |
| -e PLAYWRIGHT_BASE_URL=http://host.docker.internal:80 \ | |
| -e PLAYWRIGHT_BACKEND_URL=http://host.docker.internal:3000 \ | |
| -e PLAYWRIGHT_FRONTEND_URL=http://host.docker.internal:5173 \ | |
| -e PLAYWRIGHT_KEYCLOAK_URL=http://host.docker.internal:8080 \ | |
| -e E2E_TEST_USER_EMAIL=${{ secrets.E2E_TEST_USER_EMAIL }} \ | |
| -e E2E_TEST_USER_PASSWORD=${{ secrets.E2E_TEST_USER_PASSWORD }} \ | |
| -e TEST_USER_EMAIL=${{ secrets.E2E_TEST_USER_EMAIL }} \ | |
| -e TEST_USER_PASSWORD=${{ secrets.E2E_TEST_USER_PASSWORD }} \ | |
| -e CI=true \ | |
| evaluetonsavoir-e2e-${{ github.run_id }} | |
| - name: Copy test results back to workspace | |
| if: always() | |
| run: | | |
| mkdir -p ${{ github.workspace }}/client/playwright-report | |
| mkdir -p ${{ github.workspace }}/client/test-results | |
| cp -r /tmp/e2e-client-${{ github.run_id }}/playwright-report/* ${{ github.workspace }}/client/playwright-report/ 2>/dev/null || true | |
| cp -r /tmp/e2e-client-${{ github.run_id }}/test-results/* ${{ github.workspace }}/client/test-results/ 2>/dev/null || true | |
| - name: Show test logs on failure | |
| if: failure() | |
| run: | | |
| echo "=== Docker containers status ===" | |
| docker compose -f ${{ env.PREPROD_PATH }}/docker-compose.yaml ps | |
| echo "=== Backend logs ===" | |
| docker logs backend --tail 50 | |
| echo "=== Frontend logs ===" | |
| docker logs frontend --tail 50 | |
| echo "=== MongoDB logs ===" | |
| docker logs mongo --tail 20 | |
| echo "=== Nginx logs ===" | |
| docker logs nginx --tail 20 | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: playwright-report | |
| path: client/playwright-report/ | |
| retention-days: 7 | |
| - name: Cleanup test artifacts | |
| if: always() | |
| run: | | |
| # Clean up temporary test files and images only | |
| sudo rm -rf /tmp/e2e-client-${{ github.run_id }} 2>/dev/null || true | |
| docker rmi evaluetonsavoir-e2e-${{ github.run_id }} 2>/dev/null || true |