Skip to content

Commit 84d39b3

Browse files
committed
ci: cache playwright
1 parent 11608bd commit 84d39b3

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

.github/actions/setup-and-cache/action.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,47 @@ runs:
1010
using: "composite"
1111
steps:
1212
- name: Install pnpm
13-
uses: pnpm/action-setup@v2
13+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
1414

15-
- uses: actions/setup-node@v4
15+
- name: Set node version to ${{ inputs.node-version }}
16+
uses: actions/setup-node@v4
1617
with:
1718
node-version: ${{ inputs.node-version }}
1819
registry-url: "https://registry.npmjs.org"
1920

21+
- name: Resolve package versions
22+
id: resolve-package-versions
23+
shell: bash
24+
run: >
25+
echo "$(
26+
node -e "
27+
const fs = require('fs');
28+
const lockfile = fs.readFileSync('./pnpm-lock.yaml', 'utf8');
29+
const pattern = (name) => new RegExp(name + ':\\\s+specifier: [\\\s\\\w\\\.^]+version: (\\\d+\\\.\\\d+\\\.\\\d+)');
30+
const playwrightVersion = lockfile.match(pattern('playwright'))[1];
31+
console.log('PLAYWRIGHT_VERSION=' + playwrightVersion);
32+
"
33+
)" >> $GITHUB_OUTPUT
34+
35+
- name: Print versions
36+
shell: bash
37+
run: echo "${{ toJson(steps.resolve-package-versions.outputs) }}"
38+
39+
- name: Check resolved package versions
40+
shell: bash
41+
if: |
42+
contains(fromJSON('[null, "", "undefined"]'), steps.resolve-package-versions.outputs.PLAYWRIGHT_VERSION)
43+
run: echo "Failed to resolve package versions. See log above." && exit 1
44+
45+
- name: Cache Playwright v${{ steps.resolve-package-versions.outputs.PLAYWRIGHT_VERSION }}
46+
uses: actions/cache@v4
47+
id: playwright-cache
48+
with:
49+
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
50+
key: ${{ runner.os }}-playwright-${{ steps.resolve-package-versions.outputs.PLAYWRIGHT_VERSION }}
51+
restore-keys: |
52+
${{ runner.os }}-playwright-
53+
2054
- uses: actions/cache@v4
2155
with:
2256
path: |

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10+
env:
11+
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright
12+
1013
jobs:
1114
test:
1215
runs-on: ubuntu-latest
@@ -41,6 +44,14 @@ jobs:
4144
- name: Test
4245
run: pnpm test
4346

47+
- name: Upload screenshots
48+
uses: actions/upload-artifact@v4
49+
if: failure()
50+
with:
51+
name: vitest-screenshots
52+
path: test/__screenshots__
53+
retention-days: 30
54+
4455
publish-preview:
4556
runs-on: ubuntu-latest
4657
if: ${{ false }} # TODO: Set up preview deployments

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
- minor
1212
- major
1313

14+
env:
15+
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright
16+
1417
jobs:
1518
build:
1619
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)