Skip to content

Commit 1d3bc1e

Browse files
refactor: align Playwright setup with module-federation/core patterns
- Separate Cypress and Playwright installation into distinct steps - Use pnpm-lock.yaml hash for Playwright cache key (more stable) - Add PLAYWRIGHT_CACHE_HIT environment variable - Check for Playwright in dependencies before installing browsers - Improve cache detection logic for conditional browser installation - Follow the same pattern as module-federation/core repository
1 parent c58a705 commit 1d3bc1e

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

.github/workflows/on-pull-request.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,34 @@ jobs:
140140
141141
- name: Cache Playwright browsers
142142
uses: actions/cache@v4
143+
id: playwright-cache
143144
with:
144145
path: ~/.cache/ms-playwright
145-
key: playwright-${{ runner.os }}-${{ hashFiles('**/package.json') }}
146+
key: playwright-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
146147
restore-keys: |
147148
playwright-${{ runner.os }}-
149+
150+
- name: Set Playwright cache status
151+
run: echo "PLAYWRIGHT_CACHE_HIT=${{ steps.playwright-cache.outputs.cache-hit }}" >> $GITHUB_ENV
148152

149153
- name: Install dependencies
150154
run: |
151155
echo "Installing all dependencies to populate cache..."
152156
pnpm install --frozen-lockfile --prefer-offline
153-
npx cypress install
154157
155-
# Install Playwright globally for future migration
156-
npm install -g [email protected]
157-
npx playwright install --with-deps chromium
158+
- name: Install Cypress
159+
run: npx cypress install
160+
161+
- name: Install Playwright browsers
162+
run: |
163+
# Install Playwright browsers for projects that have it as a dependency
164+
# This prepares the cache for future migration
165+
if command -v playwright &> /dev/null || [ -f "$(npm root -g)/playwright/cli.js" ]; then
166+
echo "Installing Playwright browsers..."
167+
npx playwright install --with-deps chromium
168+
else
169+
echo "Playwright not found in dependencies, skipping browser installation"
170+
fi
158171
159172
- name: Create matrix
160173
id: set-matrix
@@ -257,13 +270,13 @@ jobs:
257270
echo "Setting up Playwright for bi-directional example..."
258271
cd ${{ matrix.container }}
259272
260-
# Check if Playwright browsers are already cached
261-
if [ "${{ steps.playwright-cache.outputs.cache-hit }}" = "true" ] && [ -d "$HOME/.cache/ms-playwright" ]; then
262-
echo "Playwright browsers already cached, installing system dependencies only..."
263-
npx playwright install-deps chromium
264-
else
273+
# Check if we need to install Playwright browsers
274+
if [ ! -d "$HOME/.cache/ms-playwright" ] || [ -z "$(ls -A $HOME/.cache/ms-playwright 2>/dev/null)" ]; then
265275
echo "Installing Playwright browsers and dependencies..."
266276
npx playwright install --with-deps chromium
277+
else
278+
echo "Playwright browsers already cached, installing system dependencies only..."
279+
npx playwright install-deps chromium
267280
fi
268281
269282
cd ..

.github/workflows/on-push.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ jobs:
9696
9797
- name: Cache Playwright browsers
9898
uses: actions/cache@v4
99+
id: playwright-cache
99100
with:
100101
path: ~/.cache/ms-playwright
101-
key: playwright-${{ runner.os }}-${{ hashFiles('**/package.json') }}
102+
key: playwright-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
102103
restore-keys: |
103104
playwright-${{ runner.os }}-
105+
106+
- name: Set Playwright cache status
107+
run: echo "PLAYWRIGHT_CACHE_HIT=${{ steps.playwright-cache.outputs.cache-hit }}" >> $GITHUB_ENV
104108

105109
- name: Install deps
106110
env:
@@ -110,12 +114,22 @@ jobs:
110114
echo "Installing dependencies from pnpm store..."
111115
pnpm install --frozen-lockfile --prefer-offline
112116
117+
- name: Install Cypress
118+
run: |
113119
# Install Cypress binary if not cached
114120
if [ -z "$(ls -A ~/.cache/Cypress 2>/dev/null)" ]; then
115121
echo "Installing Cypress binary..."
116122
npx cypress install
123+
else
124+
echo "Cypress binary already cached"
117125
fi
118126
119-
# Install Playwright globally for future migration
120-
npm install -g [email protected]
121-
npx playwright install --with-deps chromium
127+
- name: Install Playwright browsers
128+
run: |
129+
# Install Playwright browsers for projects that have it as a dependency
130+
if command -v playwright &> /dev/null || [ -f "$(npm root -g)/playwright/cli.js" ]; then
131+
echo "Installing Playwright browsers..."
132+
npx playwright install --with-deps chromium
133+
else
134+
echo "Playwright not found in dependencies, skipping browser installation"
135+
fi

0 commit comments

Comments
 (0)