Skip to content

Commit a08c99e

Browse files
committed
fix: dependency caching in Playwright workflow
1 parent 450c137 commit a08c99e

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

.github/workflows/playwright.yml

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ concurrency:
2323
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2424

2525
jobs:
26-
# build-plugin:
27-
# if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
28-
# name: Build plugin
29-
# uses: ./.github/workflows/build.yml
30-
3126
Playwright:
3227
name: Playwright test on PHP 8.1
3328
runs-on: ubuntu-22.04
34-
# needs: [build-plugin]
3529
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
3630
steps:
3731
- name: Checkout source code
@@ -43,13 +37,48 @@ jobs:
4337
node-version: 20.x
4438
cache: 'npm'
4539

46-
- name: Install & Build
47-
id: build
40+
- name: Compute dependency hash
41+
id: deps-hash
4842
run: |
49-
npm install && npm run bundle
43+
set -euo pipefail
44+
# concatenate existing lock files (src/composer.lock and package-lock.json)
45+
tmpfile=$(mktemp)
46+
for f in src/composer.lock package-lock.json; do
47+
if [ -f "$f" ]; then
48+
cat "$f" >> "$tmpfile"
49+
fi
50+
done
51+
if [ -s "$tmpfile" ]; then
52+
deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8)
53+
else
54+
# no lock files found, fall back to short commit sha
55+
deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8)
56+
fi
57+
echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT"
58+
59+
- name: Get build cache
60+
id: deps-cache
61+
uses: actions/cache/restore@v4
62+
with:
63+
path: |
64+
node_modules
65+
src/vendor
66+
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
67+
restore-keys: |
68+
${{ runner.os }}-deps-
5069
5170
- name: Install workflow dependencies (wp-env, playwright)
52-
run: npm run prepare-environment:ci
71+
if: steps.deps-cache.outputs.cache-hit != 'true'
72+
run: npm run prepare-environment:ci && npm run bundle
73+
74+
- name: Save vendor and node_modules cache
75+
if: steps.deps-cache.outputs.cache-hit != 'true'
76+
uses: actions/cache/save@v4
77+
with:
78+
path: |
79+
vendor
80+
node_modules
81+
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
5382

5483
- name: Start WordPress environment
5584
run: |

0 commit comments

Comments
 (0)