Skip to content

Commit da84739

Browse files
committed
fix: improve caching strategy for Playwright tests to avoid collisions in concurrent runs
1 parent e4af12e commit da84739

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

.github/workflows/playwright-test.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ jobs:
9090
path: |
9191
node_modules
9292
src/vendor
93-
key: ${{ runner.os }}-${{ inputs.test-mode }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
93+
key: ${{ runner.os }}-${{ inputs.test-mode }}-deps-${{ steps.deps-hash.outputs.deps_hash }}-${{ github.run_id }}-${{ github.job }}
9494
restore-keys: |
95-
${{ runner.os }}-${{ inputs.test-mode }}-deps-
95+
${{ runner.os }}-${{ inputs.test-mode }}-deps-${{ steps.deps-hash.outputs.deps_hash }}-
9696
9797
- name: Install workflow dependencies
98-
if: steps.deps-cache.outputs.cache-hit != 'true'
98+
if: steps.deps-cache.outputs.cache-matched-key == ''
9999
run: npm run prepare-environment:ci && npm run bundle
100100

101101
- name: Save vendor and node_modules cache
102-
if: steps.deps-cache.outputs.cache-hit != 'true'
102+
if: steps.deps-cache.outputs.cache-matched-key == ''
103103
uses: actions/cache/save@v4
104104
with:
105105
path: |
106106
src/vendor
107107
node_modules
108-
key: ${{ runner.os }}-${{ inputs.test-mode }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
108+
key: ${{ steps.deps-cache.outputs.cache-primary-key }}
109109

110110
- name: Wait for WordPress to be reachable
111111
run: |
@@ -199,10 +199,29 @@ jobs:
199199
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core version --allow-root
200200
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar --allow-root --info
201201
202+
- name: Restore Playwright browsers cache
203+
id: playwright-browsers-cache
204+
uses: actions/cache/restore@v4
205+
with:
206+
path: |
207+
~/.cache/ms-playwright
208+
key: ${{ runner.os }}-playwright-browsers-${{ hashFiles('package-lock.json') }}-${{ github.run_id }}-${{ github.job }}
209+
restore-keys: |
210+
${{ runner.os }}-playwright-browsers-${{ hashFiles('package-lock.json') }}-
211+
202212
- name: Install playwright/test
213+
if: steps.playwright-browsers-cache.outputs.cache-matched-key == ''
203214
run: |
204215
npx playwright install chromium
205216
217+
- name: Save Playwright browsers cache
218+
if: steps.playwright-browsers-cache.outputs.cache-matched-key == ''
219+
uses: actions/cache/save@v4
220+
with:
221+
path: |
222+
~/.cache/ms-playwright
223+
key: ${{ steps.playwright-browsers-cache.outputs.cache-primary-key }}
224+
206225
- name: Run Playwright tests
207226
env:
208227
WP_E2E_WPCLI_MODE: gh-actions-ci

0 commit comments

Comments
 (0)