Skip to content

Commit d09b345

Browse files
CI: install and cache playwright
1 parent 1d6733a commit d09b345

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

.github/workflows/astro.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
BUILD_PATH: ${{ vars.BUILD_PATH || '.' }}
2424
SITE_URL: ${{ vars.SITE_URL }}
2525
BASE_PATH: ${{ vars.BASE_PATH }}
26+
CACHE_KEY: ${{ vars.CACHE_KEY || 'v1' }}
2627

2728
steps:
2829
- name: Checkout
@@ -71,9 +72,24 @@ jobs:
7172
uses: actions/cache/restore@v4
7273
with:
7374
path: ${{ env.BUILD_PATH }}/node_modules/.astro
74-
key: ${{ runner.os }}-astro-cache-${{ hashFiles('**/astro.config.*','**/package-lock.json','**/pnpm-lock.yaml','**/yarn.lock','public/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','src/assets/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','content/**/*.{png,jpg,jpeg,webp,avif,gif,svg}') }}
75+
key: ${{ runner.os }}-astro-cache-${{ env.CACHE_KEY }}-${{ hashFiles('**/astro.config.*','**/package-lock.json','**/pnpm-lock.yaml','**/yarn.lock','public/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','src/assets/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','content/**/*.{png,jpg,jpeg,webp,avif,gif,svg}') }}
7576
restore-keys: |
76-
${{ runner.os }}-astro-cache-
77+
${{ runner.os }}-astro-cache-${{ env.CACHE_KEY }}-
78+
79+
# ===== Playwright browser cache =====
80+
- name: Get Playwright minor version
81+
id: playwright-version
82+
run: echo "version=$(npx playwright --version | sed 's/Version //' | cut -d. -f1,2)" >> $GITHUB_OUTPUT
83+
working-directory: ${{ env.BUILD_PATH }}
84+
85+
- name: Restore Playwright browser cache
86+
id: playwright-cache
87+
uses: actions/cache/restore@v4
88+
with:
89+
path: ~/.cache/ms-playwright
90+
key: ${{ runner.os }}-playwright-${{ env.CACHE_KEY }}-${{ steps.playwright-version.outputs.version }}
91+
restore-keys: |
92+
${{ runner.os }}-playwright-${{ env.CACHE_KEY }}-
7793
7894
# Fetch the latest data
7995
- name: Fetch data
@@ -96,6 +112,12 @@ jobs:
96112
SITE_URL: ${{ vars.SITE_URL }}
97113
BASE_PATH: ${{ vars.BASE_PATH }}
98114

115+
# Install Playwright browsers if not cached
116+
- name: Install Playwright browsers
117+
if: steps.playwright-cache.outputs.cache-hit != 'true'
118+
run: npx playwright install --with-deps
119+
working-directory: ${{ env.BUILD_PATH }}
120+
99121
- name: Run tests
100122
run: npm run test:dist
101123
working-directory: ${{ env.BUILD_PATH }}
@@ -133,7 +155,15 @@ jobs:
133155
uses: actions/cache/save@v4
134156
with:
135157
path: ${{ env.BUILD_PATH }}/node_modules/.astro
136-
key: ${{ runner.os }}-astro-cache-${{ hashFiles('**/astro.config.*','**/package-lock.json','**/pnpm-lock.yaml','**/yarn.lock','public/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','src/assets/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','content/**/*.{png,jpg,jpeg,webp,avif,gif,svg}') }}-${{ github.run_id }}
158+
key: ${{ runner.os }}-astro-cache-${{ env.CACHE_KEY }}-${{ hashFiles('**/astro.config.*','**/package-lock.json','**/pnpm-lock.yaml','**/yarn.lock','public/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','src/assets/**/*.{png,jpg,jpeg,webp,avif,gif,svg}','content/**/*.{png,jpg,jpeg,webp,avif,gif,svg}') }}-${{ github.run_id }}
159+
160+
# Save Playwright browser cache if it was downloaded
161+
- name: Save Playwright browser cache
162+
if: steps.playwright-cache.outputs.cache-hit != 'true'
163+
uses: actions/cache/save@v4
164+
with:
165+
path: ~/.cache/ms-playwright
166+
key: ${{ runner.os }}-playwright-${{ env.CACHE_KEY }}-${{ steps.playwright-version.outputs.version }}
137167

138168
- name: Upload artifact
139169
uses: actions/upload-pages-artifact@v3

0 commit comments

Comments
 (0)