|
| 1 | +name: Run Playwright tests |
| 2 | +description: Run E2E tests with browsers from the matching official Playwright image. |
| 3 | +inputs: |
| 4 | + test-script: |
| 5 | + description: Composer script that runs the E2E tests. |
| 6 | + required: true |
| 7 | +runs: |
| 8 | + using: composite |
| 9 | + steps: |
| 10 | + - name: Resolve Playwright version |
| 11 | + id: playwright |
| 12 | + shell: bash |
| 13 | + working-directory: wordpress |
| 14 | + run: | |
| 15 | + node <<'NODE' >> "$GITHUB_ENV" |
| 16 | + const { createRequire } = require( 'node:module' ); |
| 17 | + const { realpathSync } = require( 'node:fs' ); |
| 18 | + const path = require( 'node:path' ); |
| 19 | + const testRequire = createRequire( require.resolve( '@playwright/test/package.json' ) ); |
| 20 | + const playwright = testRequire.resolve( 'playwright/package.json' ); |
| 21 | + console.log( `PLAYWRIGHT_VERSION=${require( playwright ).version}` ); |
| 22 | + console.log( `PLAYWRIGHT_PACKAGE=${path.dirname( playwright )}` ); |
| 23 | + console.log( `PLAYWRIGHT_NODE_MODULES=${realpathSync( 'node_modules' )}` ); |
| 24 | + NODE |
| 25 | +
|
| 26 | + - name: Start Playwright browser server |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + # Pull the WordPress images meanwhile, so the test script can start them sooner. |
| 30 | + npm --prefix wordpress run env:pull -- --quiet & |
| 31 | + wordpress_pull=$! |
| 32 | +
|
| 33 | + # Bound each attempt, as a stalled pull would otherwise run into the job timeout. |
| 34 | + for attempt in 1 2 3; do |
| 35 | + timeout 3m docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" pull && break |
| 36 | + if [ "$attempt" -eq 3 ]; then |
| 37 | + echo "Failed to pull the Playwright image after $attempt attempts." >&2 |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + echo "Pulling the Playwright image failed. Retrying in $(( attempt * 10 )) seconds..." |
| 41 | + sleep $(( attempt * 10 )) |
| 42 | + done |
| 43 | +
|
| 44 | + docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" up --wait --wait-timeout 60 |
| 45 | + wait "$wordpress_pull" |
| 46 | +
|
| 47 | + - name: Run E2E tests |
| 48 | + shell: bash |
| 49 | + env: |
| 50 | + TEST_SCRIPT: ${{ inputs.test-script }} |
| 51 | + PW_TEST_CONNECT_WS_ENDPOINT: ws://127.0.0.1:3000/ |
| 52 | + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' |
| 53 | + run: composer run "$TEST_SCRIPT" |
| 54 | + |
| 55 | + - name: Show browser server logs |
| 56 | + if: ( failure() || cancelled() ) && steps.playwright.outcome == 'success' |
| 57 | + shell: bash |
| 58 | + run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" logs |
| 59 | + |
| 60 | + - name: Stop Playwright browser server |
| 61 | + if: always() && steps.playwright.outcome == 'success' |
| 62 | + shell: bash |
| 63 | + run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" down |
0 commit comments