Skip to content

Commit 7137cbe

Browse files
authored
fix: restore the og-image render cache, save it only on main (#214)
1 parent 57803ab commit 7137cbe

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

.github/workflows/build_website.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,19 @@ jobs:
119119
- name: Install Dependencies
120120
run: npm install
121121
working-directory: 'website'
122-
# nuxt-og-image fetches its satori font on first render, and that download is the only
123-
# thing the og-image cache directory holds at any size. Keyed on the lockfile that
124-
# pins the module, so an unchanged lockfile hits exactly and writes nothing back.
125-
- name: Cache the nuxt-og-image font download
126-
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
122+
# nuxt-og-image content-addresses each rendered image by component, props and module
123+
# version, so an entry is only ever added and never goes stale. Restoring the newest
124+
# entry means only the pages whose title or section actually changed pay to render.
125+
# Restore and save are separate steps because the entry has to keep accumulating:
126+
# actions/cache writes nothing back when the key it restored from was an exact hit.
127+
- name: Restore the nuxt-og-image caches
128+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
127129
with:
128-
path: website/nuxt/node_modules/.cache/nuxt/.nuxt/cache/og-image
129-
key: og-image-font-${{ runner.os }}-${{ hashFiles('website/package-lock.json') }}
130-
restore-keys: og-image-font-${{ runner.os }}-
130+
path: |
131+
website/nuxt/node_modules/.cache/nuxt/.nuxt/cache/og-image
132+
website/nuxt/node_modules/.cache/nuxt/.nuxt/cache/og-image-render
133+
key: og-image-cache-${{ runner.os }}-${{ github.run_id }}
134+
restore-keys: og-image-cache-${{ runner.os }}-
131135
- name: Run unit tests
132136
if: inputs.run_unit_tests
133137
run: npm test
@@ -137,6 +141,17 @@ jobs:
137141
- name: Build the forge
138142
run: npm run ${{ inputs.deploy_preview && 'build:nuxt' || 'build:nuxt:skip-images' }}
139143
working-directory: 'website'
144+
# Only the default branch writes an entry. Saving on every run left one entry per push
145+
# in a cache the repository shares across workflows, and the default branch builds
146+
# often enough for the accumulated entry to stay useful to pull requests restoring it.
147+
- name: Save the nuxt-og-image caches
148+
if: github.ref == 'refs/heads/main'
149+
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
150+
with:
151+
path: |
152+
website/nuxt/node_modules/.cache/nuxt/.nuxt/cache/og-image
153+
website/nuxt/node_modules/.cache/nuxt/.nuxt/cache/og-image-render
154+
key: og-image-cache-${{ runner.os }}-${{ github.run_id }}
140155
# A preview processes images, and Nuxt Image then points every <img> at
141156
# /.netlify/images, which Netlify only answers at runtime. That path is absent from the
142157
# static tree hyperlink walks, so every image reads as a broken link. hyperlink 0.3.2

0 commit comments

Comments
 (0)