|
| 1 | +--- |
| 2 | +name: 'Playwright Browser Tests' |
| 3 | +description: | |
| 4 | + Run Playwright browser tests for workbench images. |
| 5 | +
|
| 6 | + Features: |
| 7 | + - Runs Playwright tests inside the official Microsoft Playwright container |
| 8 | + - Uses Podman to run the test container with proper isolation |
| 9 | + - Supports testcontainers for container orchestration |
| 10 | + - Uploads test reports as artifacts on pull requests |
| 11 | +
|
| 12 | + Requirements: |
| 13 | + - Podman must be installed and running |
| 14 | + - The workbench image must be available in the local Podman storage |
| 15 | + - tests/browser directory must contain the Playwright test configuration |
| 16 | +
|
| 17 | +inputs: |
| 18 | + test-target: |
| 19 | + description: 'The workbench image to test (full image reference).' |
| 20 | + required: true |
| 21 | + podman-socket: |
| 22 | + description: 'Path to Podman socket' |
| 23 | + required: false |
| 24 | + default: '/var/run/podman/podman.sock' |
| 25 | + playwright-version: |
| 26 | + description: 'Version of the Playwright container to use (e.g., v1.58.1-noble). If not provided, extracted from package.json5' |
| 27 | + required: false |
| 28 | + default: '' |
| 29 | + working-directory: |
| 30 | + description: 'Directory containing the Playwright tests' |
| 31 | + required: false |
| 32 | + default: 'tests/browser' |
| 33 | + upload-report: |
| 34 | + description: 'Whether to upload the Playwright report as an artifact' |
| 35 | + required: false |
| 36 | + default: 'false' |
| 37 | + artifact-name: |
| 38 | + description: 'Name for the uploaded artifact (required if upload-report is true)' |
| 39 | + required: false |
| 40 | + default: 'playwright-report' |
| 41 | + artifact-retention-days: |
| 42 | + description: 'Number of days to retain the artifact' |
| 43 | + required: false |
| 44 | + default: '30' |
| 45 | + |
| 46 | +outputs: |
| 47 | + outcome: |
| 48 | + description: 'The outcome of the Playwright tests (success or failure)' |
| 49 | + value: ${{ steps.playwright.outcome }} |
| 50 | + |
| 51 | +runs: |
| 52 | + using: 'composite' |
| 53 | + steps: |
| 54 | + - name: Determine Playwright version |
| 55 | + id: playwright-version |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + if [[ -n "${INPUT_PLAYWRIGHT_VERSION}" ]]; then |
| 59 | + echo "version=${INPUT_PLAYWRIGHT_VERSION}" >> "$GITHUB_OUTPUT" |
| 60 | + else |
| 61 | + # Extract version from package.json5 (single source of truth) |
| 62 | + # package.json5 has: "@playwright/test": "=1.58.1" |
| 63 | + # Container tag format is: v1.58.1-noble |
| 64 | + PKG_VERSION=$(grep -oP '"@playwright/test":\s*"=?\K[0-9.]+' "${WORKING_DIRECTORY}/package.json5") |
| 65 | + if [[ -z "$PKG_VERSION" ]]; then |
| 66 | + echo "::error::Failed to extract Playwright version from package.json5" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + echo "version=v${PKG_VERSION}-noble" >> "$GITHUB_OUTPUT" |
| 70 | + echo "Extracted Playwright version: v${PKG_VERSION}-noble" |
| 71 | + fi |
| 72 | + env: |
| 73 | + INPUT_PLAYWRIGHT_VERSION: ${{ inputs.playwright-version }} |
| 74 | + WORKING_DIRECTORY: ${{ inputs.working-directory }} |
| 75 | + |
| 76 | + - name: Run Playwright tests |
| 77 | + id: playwright |
| 78 | + shell: bash |
| 79 | + # --ipc=host because Microsoft says so in Playwright docs |
| 80 | + # --net=host because testcontainers connects to the Reaper container's exposed port |
| 81 | + # we need to pass through the relevant environment variables |
| 82 | + # DEBUG configures Node.js debuggers, sets different verbosity as needed |
| 83 | + # CI=true is set on every CI nowadays |
| 84 | + # PODMAN_SOCK should be mounted to /var/run/docker.sock, other likely mounting locations may not exist (mkdir -p) |
| 85 | + # TEST_TARGET is the workbench image the test will run |
| 86 | + # --volume(s) let us access docker socket and not clobber host's node_modules |
| 87 | + run: | |
| 88 | + podman run \ |
| 89 | + --interactive --rm \ |
| 90 | + --ipc=host \ |
| 91 | + --net=host \ |
| 92 | + --env "CI=true" \ |
| 93 | + --env "NPM_CONFIG_fund=false" \ |
| 94 | + --env "DEBUG=testcontainers:*" \ |
| 95 | + --env "PODMAN_SOCK=/var/run/docker.sock" \ |
| 96 | + --env "TEST_TARGET" \ |
| 97 | + --volume "${PODMAN_SOCKET}":/var/run/docker.sock \ |
| 98 | + --volume "${PWD}":/mnt \ |
| 99 | + --volume /mnt/node_modules \ |
| 100 | + "mcr.microsoft.com/playwright:${PLAYWRIGHT_VERSION}" \ |
| 101 | + /bin/bash <<EOF |
| 102 | + set -Eeuxo pipefail |
| 103 | + cd /mnt |
| 104 | + npm install -g pnpm && pnpm install |
| 105 | + pnpm exec playwright test |
| 106 | + exit 0 |
| 107 | + EOF |
| 108 | + working-directory: ${{ inputs.working-directory }} |
| 109 | + env: |
| 110 | + # Only set TEST_TARGET if provided, otherwise playwright.config.ts uses its default |
| 111 | + TEST_TARGET: ${{ inputs.test-target || '' }} |
| 112 | + PODMAN_SOCKET: ${{ inputs.podman-socket }} |
| 113 | + PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.version }} |
| 114 | + |
| 115 | + - name: Upload Playwright report |
| 116 | + if: ${{ !cancelled() && inputs.upload-report == 'true' }} |
| 117 | + uses: actions/upload-artifact@v6 |
| 118 | + with: |
| 119 | + name: ${{ inputs.artifact-name }} |
| 120 | + path: ${{ inputs.working-directory }}/playwright-report/ |
| 121 | + retention-days: ${{ inputs.artifact-retention-days }} |
0 commit comments