Skip to content

Commit b6cf7b0

Browse files
authored
ci: Cache playwright separately (#13226)
We used to include the playwright binaries in the general dependency cache, which inflated this for no reason. Now, this is not included there anymore. Additionally, I extracted the code to install & cache playwright into a composite action, making it easier to reuse it.
1 parent 957324e commit b6cf7b0

File tree

3 files changed

+49
-61
lines changed

3 files changed

+49
-61
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Install Playwright dependencies"
2+
description: "Installs Playwright dependencies and caches them."
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Get Playwright version
8+
id: playwright-version
9+
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
10+
shell: bash
11+
12+
- name: Cache playwright binaries
13+
uses: actions/cache@v4
14+
id: playwright-cache
15+
with:
16+
path: |
17+
~/.cache/ms-playwright
18+
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
19+
20+
- name: Install Playwright dependencies (uncached)
21+
run: npx playwright install chromium webkit firefox --with-deps
22+
if: steps.playwright-cache.outputs.cache-hit != 'true'
23+
shell: bash
24+
25+
- name: Install Playwright system dependencies only (cached)
26+
run: npx playwright install-deps chromium webkit firefox
27+
if: steps.playwright-cache.outputs.cache-hit == 'true'
28+
shell: bash

.github/workflows/build.yml

+19-41
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ env:
3232
${{ github.workspace }}/node_modules
3333
${{ github.workspace }}/packages/*/node_modules
3434
${{ github.workspace }}/dev-packages/*/node_modules
35-
~/.cache/ms-playwright/
3635
~/.cache/mongodb-binaries/
3736
3837
# DEPENDENCY_CACHE_KEY: can't be set here because we don't have access to yarn.lock
@@ -659,26 +658,10 @@ jobs:
659658
uses: ./.github/actions/restore-cache
660659
env:
661660
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
662-
- name: Get npm cache directory
663-
id: npm-cache-dir
664-
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
665-
- name: Get Playwright version
666-
id: playwright-version
667-
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
668-
- uses: actions/cache@v4
669-
name: Check if Playwright browser is cached
670-
id: playwright-cache
671-
with:
672-
path: ${{ steps.npm-cache-dir.outputs.dir }}
673-
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
674-
- name: Install Playwright browser if not cached
675-
if: steps.playwright-cache.outputs.cache-hit != 'true'
676-
run: npx playwright install --with-deps
677-
env:
678-
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
679-
- name: Install OS dependencies of Playwright if cache hit
680-
if: steps.playwright-cache.outputs.cache-hit == 'true'
681-
run: npx playwright install-deps
661+
662+
- name: Install Playwright
663+
uses: ./.github/actions/install-playwright
664+
682665
- name: Run Playwright tests
683666
env:
684667
PW_BUNDLE: ${{ matrix.bundle }}
@@ -723,26 +706,10 @@ jobs:
723706
uses: ./.github/actions/restore-cache
724707
env:
725708
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
726-
- name: Get npm cache directory
727-
id: npm-cache-dir
728-
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
729-
- name: Get Playwright version
730-
id: playwright-version
731-
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
732-
- uses: actions/cache@v4
733-
name: Check if Playwright browser is cached
734-
id: playwright-cache
735-
with:
736-
path: ${{ steps.npm-cache-dir.outputs.dir }}
737-
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
738-
- name: Install Playwright browser if not cached
739-
if: steps.playwright-cache.outputs.cache-hit != 'true'
740-
run: npx playwright install --with-deps
741-
env:
742-
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
743-
- name: Install OS dependencies of Playwright if cache hit
744-
if: steps.playwright-cache.outputs.cache-hit == 'true'
745-
run: npx playwright install-deps
709+
710+
- name: Install Playwright
711+
uses: ./.github/actions/install-playwright
712+
746713
- name: Run Playwright Loader tests
747714
env:
748715
PW_BUNDLE: ${{ matrix.bundle }}
@@ -854,6 +821,8 @@ jobs:
854821
uses: ./.github/actions/restore-cache
855822
env:
856823
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
824+
- name: Install Playwright
825+
uses: ./.github/actions/install-playwright
857826
- name: Run integration tests
858827
env:
859828
NODE_VERSION: ${{ matrix.node }}
@@ -1052,6 +1021,9 @@ jobs:
10521021
path: ${{ github.workspace }}/packages/*/*.tgz
10531022
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
10541023

1024+
- name: Install Playwright
1025+
uses: ./.github/actions/install-playwright
1026+
10551027
- name: Get node version
10561028
id: versions
10571029
run: |
@@ -1146,6 +1118,9 @@ jobs:
11461118
path: ${{ github.workspace }}/packages/*/*.tgz
11471119
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
11481120

1121+
- name: Install Playwright
1122+
uses: ./.github/actions/install-playwright
1123+
11491124
- name: Get node version
11501125
id: versions
11511126
run: |
@@ -1243,6 +1218,9 @@ jobs:
12431218
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
12441219
fail-on-cache-miss : true
12451220

1221+
- name: Install Playwright
1222+
uses: ./.github/actions/install-playwright
1223+
12461224
- name: Get node version
12471225
id: versions
12481226
run: |

.github/workflows/flaky-test-detector.yml

+2-20
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,8 @@ jobs:
4949
- name: Build packages
5050
run: yarn build
5151

52-
- name: Get npm cache directory
53-
id: npm-cache-dir
54-
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
55-
- name: Get Playwright version
56-
id: playwright-version
57-
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
58-
- uses: actions/cache@v4
59-
name: Check if Playwright browser is cached
60-
id: playwright-cache
61-
with:
62-
path: ${{ steps.npm-cache-dir.outputs.dir }}
63-
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
64-
- name: Install Playwright browser if not cached
65-
if: steps.playwright-cache.outputs.cache-hit != 'true'
66-
run: npx playwright install --with-deps
67-
env:
68-
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
69-
- name: Install OS dependencies of Playwright if cache hit
70-
if: steps.playwright-cache.outputs.cache-hit == 'true'
71-
run: npx playwright install-deps
52+
- name: Install Playwright
53+
uses: ./.github/actions/install-playwright
7254

7355
- name: Determine changed tests
7456
uses: dorny/[email protected]

0 commit comments

Comments
 (0)