|
| 1 | +name: Visual Regression Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +concurrency: |
| 7 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 8 | + cancel-in-progress: true |
| 9 | + |
| 10 | +# Disable permissions for all available scopes by default. |
| 11 | +# Any needed permissions should be configured at the job level. |
| 12 | +permissions: {} |
| 13 | + |
| 14 | +env: |
| 15 | + LOCAL_DIR: build |
| 16 | + PUPPETEER_SKIP_DOWNLOAD: ${{ true }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + visual-regression: |
| 20 | + name: Visual Regression |
| 21 | + runs-on: ubuntu-24.04 |
| 22 | + timeout-minutes: 30 |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Configure environment variables |
| 28 | + run: | |
| 29 | + echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV" |
| 30 | + echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV" |
| 31 | +
|
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 34 | + with: |
| 35 | + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} |
| 36 | + fetch-depth: 0 |
| 37 | + persist-credentials: false |
| 38 | + |
| 39 | + - name: Determine baseline commit |
| 40 | + id: baseline |
| 41 | + run: | |
| 42 | + echo "current_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
| 43 | + echo "base_sha=$(git merge-base HEAD origin/trunk)" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + - name: Set up Node.js |
| 46 | + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 |
| 47 | + with: |
| 48 | + node-version-file: '.nvmrc' |
| 49 | + cache: npm |
| 50 | + |
| 51 | + - name: Install npm dependencies |
| 52 | + run: npm ci |
| 53 | + |
| 54 | + - name: Install Playwright browsers |
| 55 | + run: npx playwright install --with-deps chromium |
| 56 | + |
| 57 | + - name: Checkout merge base |
| 58 | + run: git checkout ${{ steps.baseline.outputs.base_sha }} |
| 59 | + |
| 60 | + - name: Build WordPress (baseline) |
| 61 | + run: npm run build |
| 62 | + |
| 63 | + - name: Start Docker environment |
| 64 | + run: npm run env:start |
| 65 | + |
| 66 | + - name: Install WordPress |
| 67 | + run: npm run env:install |
| 68 | + |
| 69 | + - name: Generate baseline snapshots |
| 70 | + run: npx wp-scripts test-playwright --config tests/visual-regression/playwright.config.js --update-snapshots |
| 71 | + |
| 72 | + - name: Checkout current commit |
| 73 | + run: git checkout ${{ steps.baseline.outputs.current_sha }} |
| 74 | + |
| 75 | + - name: Rebuild WordPress |
| 76 | + run: npm run build |
| 77 | + |
| 78 | + - name: Restart Docker environment |
| 79 | + run: npm run env:stop && npm run env:start |
| 80 | + |
| 81 | + - name: Reinstall WordPress |
| 82 | + run: npm run env:install |
| 83 | + |
| 84 | + - name: Run visual comparison |
| 85 | + run: npx wp-scripts test-playwright --config tests/visual-regression/playwright.config.js |
| 86 | + |
| 87 | + - name: Upload report artifacts |
| 88 | + if: always() |
| 89 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 90 | + with: |
| 91 | + name: visual-regression-report-${{ github.run_id }} |
| 92 | + path: | |
| 93 | + artifacts/visual-report |
| 94 | + artifacts/test-results |
| 95 | + if-no-files-found: ignore |
| 96 | + include-hidden-files: true |
| 97 | + |
0 commit comments