|
| 1 | +name: "(Test): Playwright" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled, synchronize, opened, reopened] |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - 'core' |
| 9 | + - 'pro' |
| 10 | + paths-ignore: |
| 11 | + - '**.md' |
| 12 | + - '**.txt' |
| 13 | + - '.gitignore' |
| 14 | + - 'docs/**' |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + pull-requests: write |
| 20 | + actions: read |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: playwright-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }} |
| 24 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 25 | + |
| 26 | +jobs: |
| 27 | + Playwright: |
| 28 | + name: Playwright test on PHP 8.1 |
| 29 | + runs-on: ubuntu-22.04 |
| 30 | + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') |
| 31 | + steps: |
| 32 | + - name: Checkout source code |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up PHP |
| 36 | + uses: codesnippetspro/setup-php@v2 |
| 37 | + with: |
| 38 | + php-version: "8.1" |
| 39 | + |
| 40 | + - name: Set up Node.js |
| 41 | + uses: actions/setup-node@v4 |
| 42 | + with: |
| 43 | + node-version-file: .node-version |
| 44 | + cache: 'npm' |
| 45 | + |
| 46 | + - name: Compute dependency hash |
| 47 | + id: deps-hash |
| 48 | + run: | |
| 49 | + set -euo pipefail |
| 50 | + # concatenate existing lock files (src/composer.lock and package-lock.json) |
| 51 | + tmpfile=$(mktemp) |
| 52 | + for f in src/composer.lock package-lock.json; do |
| 53 | + if [ -f "$f" ]; then |
| 54 | + cat "$f" >> "$tmpfile" |
| 55 | + fi |
| 56 | + done |
| 57 | + if [ -s "$tmpfile" ]; then |
| 58 | + deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8) |
| 59 | + else |
| 60 | + # no lock files found, fall back to short commit sha |
| 61 | + deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8) |
| 62 | + fi |
| 63 | + echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT" |
| 64 | +
|
| 65 | + - name: Get build cache |
| 66 | + id: deps-cache |
| 67 | + uses: actions/cache/restore@v4 |
| 68 | + with: |
| 69 | + path: | |
| 70 | + node_modules |
| 71 | + src/vendor |
| 72 | + key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }} |
| 73 | + restore-keys: | |
| 74 | + ${{ runner.os }}-deps- |
| 75 | +
|
| 76 | + - name: Install workflow dependencies (wp-env, playwright) |
| 77 | + if: steps.deps-cache.outputs.cache-hit != 'true' |
| 78 | + run: npm run prepare-environment:ci && npm run bundle |
| 79 | + |
| 80 | + - name: Save vendor and node_modules cache |
| 81 | + if: steps.deps-cache.outputs.cache-hit != 'true' |
| 82 | + uses: actions/cache/save@v4 |
| 83 | + with: |
| 84 | + path: | |
| 85 | + src/vendor |
| 86 | + node_modules |
| 87 | + key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }} |
| 88 | + |
| 89 | + - name: Start WordPress environment |
| 90 | + run: | |
| 91 | + npx wp-env start |
| 92 | +
|
| 93 | + - name: Activate code-snippets plugin |
| 94 | + run: npx wp-env run cli wp plugin activate code-snippets |
| 95 | + |
| 96 | + - name: WordPress debug information |
| 97 | + run: | |
| 98 | + npx wp-env run cli wp core version |
| 99 | + npx wp-env run cli wp --info |
| 100 | +
|
| 101 | + - name: Install playwright/test |
| 102 | + run: | |
| 103 | + npx playwright install chromium |
| 104 | +
|
| 105 | + - name: Run Playwright tests |
| 106 | + run: npm run test:playwright |
| 107 | + |
| 108 | + - name: Stop WordPress environment |
| 109 | + if: always() |
| 110 | + run: npx wp-env stop |
| 111 | + |
| 112 | + - uses: actions/upload-artifact@v4 |
| 113 | + if: always() |
| 114 | + with: |
| 115 | + name: playwright-test-results |
| 116 | + path: test-results/ |
| 117 | + if-no-files-found: ignore |
| 118 | + retention-days: 2 |
| 119 | + |
| 120 | + test-result: |
| 121 | + needs: [Playwright] |
| 122 | + if: always() && (needs.Playwright.result != 'skipped') |
| 123 | + runs-on: ubuntu-22.04 |
| 124 | + name: Playwright - Test Results |
| 125 | + steps: |
| 126 | + - name: Test status |
| 127 | + run: echo "Test status is - ${{ needs.Playwright.result }}" |
| 128 | + - name: Check Playwright status |
| 129 | + if: ${{ needs.Playwright.result != 'success' && needs.Playwright.result != 'skipped' }} |
| 130 | + run: exit 1 |
0 commit comments