Skip to content

Commit

Permalink
ci: Cache playwright separately (#13226)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mydea authored Aug 5, 2024
1 parent 957324e commit b6cf7b0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 61 deletions.
28 changes: 28 additions & 0 deletions .github/actions/install-playwright/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Install Playwright dependencies"
description: "Installs Playwright dependencies and caches them."

runs:
using: "composite"
steps:
- name: Get Playwright version
id: playwright-version
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
shell: bash

- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}

- name: Install Playwright dependencies (uncached)
run: npx playwright install chromium webkit firefox --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: bash

- name: Install Playwright system dependencies only (cached)
run: npx playwright install-deps chromium webkit firefox
if: steps.playwright-cache.outputs.cache-hit == 'true'
shell: bash
60 changes: 19 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ env:
${{ github.workspace }}/node_modules
${{ github.workspace }}/packages/*/node_modules
${{ github.workspace }}/dev-packages/*/node_modules
~/.cache/ms-playwright/
~/.cache/mongodb-binaries/
# DEPENDENCY_CACHE_KEY: can't be set here because we don't have access to yarn.lock
Expand Down Expand Up @@ -659,26 +658,10 @@ jobs:
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Get npm cache directory
id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: Get Playwright version
id: playwright-version
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Check if Playwright browser is cached
id: playwright-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
- name: Install Playwright browser if not cached
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
env:
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
- name: Install OS dependencies of Playwright if cache hit
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps

- name: Install Playwright
uses: ./.github/actions/install-playwright

- name: Run Playwright tests
env:
PW_BUNDLE: ${{ matrix.bundle }}
Expand Down Expand Up @@ -723,26 +706,10 @@ jobs:
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Get npm cache directory
id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: Get Playwright version
id: playwright-version
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Check if Playwright browser is cached
id: playwright-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
- name: Install Playwright browser if not cached
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
env:
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
- name: Install OS dependencies of Playwright if cache hit
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps

- name: Install Playwright
uses: ./.github/actions/install-playwright

- name: Run Playwright Loader tests
env:
PW_BUNDLE: ${{ matrix.bundle }}
Expand Down Expand Up @@ -854,6 +821,8 @@ jobs:
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Install Playwright
uses: ./.github/actions/install-playwright
- name: Run integration tests
env:
NODE_VERSION: ${{ matrix.node }}
Expand Down Expand Up @@ -1052,6 +1021,9 @@ jobs:
path: ${{ github.workspace }}/packages/*/*.tgz
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}

- name: Install Playwright
uses: ./.github/actions/install-playwright

- name: Get node version
id: versions
run: |
Expand Down Expand Up @@ -1146,6 +1118,9 @@ jobs:
path: ${{ github.workspace }}/packages/*/*.tgz
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}

- name: Install Playwright
uses: ./.github/actions/install-playwright

- name: Get node version
id: versions
run: |
Expand Down Expand Up @@ -1243,6 +1218,9 @@ jobs:
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
fail-on-cache-miss : true

- name: Install Playwright
uses: ./.github/actions/install-playwright

- name: Get node version
id: versions
run: |
Expand Down
22 changes: 2 additions & 20 deletions .github/workflows/flaky-test-detector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,8 @@ jobs:
- name: Build packages
run: yarn build

- name: Get npm cache directory
id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: Get Playwright version
id: playwright-version
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Check if Playwright browser is cached
id: playwright-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
- name: Install Playwright browser if not cached
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
env:
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
- name: Install OS dependencies of Playwright if cache hit
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps
- name: Install Playwright
uses: ./.github/actions/install-playwright

- name: Determine changed tests
uses: dorny/paths-filter@v3.0.1
Expand Down

0 comments on commit b6cf7b0

Please sign in to comment.