Skip to content

Commit 84b3b62

Browse files
committed
BUILD: Cache netlify deploy builds
1 parent 73a6807 commit 84b3b62

File tree

1 file changed

+164
-1
lines changed

1 file changed

+164
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 164 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,49 @@ jobs:
4949
steps:
5050
- name: Checkout repository
5151
uses: actions/checkout@v4
52+
with:
53+
# Need full history for `git log` for cache key
54+
fetch-depth: 0
55+
56+
- name: Compute cache key
57+
id: cache-key
58+
run: |
59+
hash=$(git log -1 --format="%H" -- dev-docs)
60+
echo "git-hash=${hash}" >> $GITHUB_OUTPUT
61+
echo "Dev docs hash: ${hash}"
62+
63+
- name: Cache dev docs build
64+
id: cache-dev-docs-build
65+
uses: actions/cache@v4
66+
with:
67+
path: dev-docs/output
68+
key: dev-docs-build-${{ steps.cache-key.outputs.git-hash }}
5269

5370
- name: Setup pnpm
71+
if: steps.cache-dev-docs-build.outputs.cache-hit != 'true'
5472
uses: pnpm/action-setup@v4
5573

5674
- name: Setup NodeJS
75+
if: steps.cache-dev-docs-build.outputs.cache-hit != 'true'
5776
uses: actions/setup-node@v4
5877
with:
5978
node-version: 24
6079
cache: "pnpm"
6180

6281
- name: Build developer docs
82+
if: steps.cache-dev-docs-build.outputs.cache-hit != 'true'
6383
run: |
6484
pnpm install
6585
pnpm --filter ./dev-docs run doc
6686
87+
- name: Report cache status
88+
run: |
89+
if [ "${{ steps.cache-dev-docs-build.outputs.cache-hit }}" = "true" ]; then
90+
echo "✅ Dev docs restored from cache"
91+
else
92+
echo "🔨 Dev docs built and cached"
93+
fi
94+
6795
- name: Upload developer docs
6896
uses: actions/upload-artifact@v4
6997
with:
@@ -76,24 +104,48 @@ jobs:
76104
steps:
77105
- name: Checkout repository
78106
uses: actions/checkout@v4
107+
with:
108+
# Need full history for `git log` for cache key
109+
fetch-depth: 0
110+
111+
- name: Compute cache key
112+
id: cache-key
113+
run: |
114+
# Get git hash of the most recent commit affecting frontend or any of its dependencies
115+
hash=$(git log -1 --format="%H" -- packages/frontend packages/catlog-wasm packages/catlog packages/backend/pkg packages/ui-components)
116+
echo "git-hash=${hash}" >> $GITHUB_OUTPUT
117+
echo "Frontend git hash: ${git_hash}"
118+
119+
- name: Cache frontend build
120+
id: cache-frontend-build
121+
# Skip caching for production builds
122+
if: github.event_name != 'release'
123+
uses: actions/cache@v4
124+
with:
125+
path: |
126+
packages/frontend/dist
127+
key: frontend-build-${{ steps.cache-key.outputs.git-hash }}-${{ github.event_name == 'release' && 'production' || 'staging' }}
79128

80129
- name: Setup pnpm
130+
if: github.event_name == 'release' || steps.cache-frontend-build.outputs.cache-hit != 'true'
81131
uses: pnpm/action-setup@v4
82132

83133
- name: Setup NodeJS
134+
if: github.event_name == 'release' || steps.cache-frontend-build.outputs.cache-hit != 'true'
84135
uses: actions/setup-node@v4
85136
with:
86137
node-version: 24
87138
cache: "pnpm"
88139

89140
- name: Install Rust toolchain from file
141+
if: github.event_name == 'release' || steps.cache-frontend-build.outputs.cache-hit != 'true'
90142
uses: actions-rust-lang/setup-rust-toolchain@v1
91143
with:
92144
# Don't override flags in cargo config files.
93145
rustflags: ""
94146

95147
- name: Build for Staging
96-
if: github.event_name == 'push' || github.event_name == 'pull_request'
148+
if: (github.event_name == 'push' || github.event_name == 'pull_request') && steps.cache-frontend-build.outputs.cache-hit != 'true'
97149
run: |
98150
pnpm install
99151
# Uses env from packages/frontend/.env.staging
@@ -106,16 +158,42 @@ jobs:
106158
# Uses env from packages/frontend/.env.production
107159
pnpm --filter ./packages/frontend run build
108160
161+
- name: Report cache status
162+
run: |
163+
if [ "${{ github.event_name }}" = "release" ]; then
164+
echo "🔨 Frontend production build completed (cache disabled)"
165+
elif [ "${{ steps.cache-frontend-build.outputs.cache-hit }}" = "true" ]; then
166+
echo "✅ Frontend build restored from cache"
167+
else
168+
echo "🔨 Frontend build completed and cached"
169+
fi
170+
109171
- name: Upload
110172
uses: actions/upload-artifact@v4
111173
with:
112174
name: app
113175
path: packages/frontend/dist
114176

177+
- name: Cache frontend docs build
178+
id: cache-frontend-docs
179+
uses: actions/cache@v4
180+
with:
181+
path: packages/frontend/docs
182+
key: frontend-docs-${{ steps.cache-key.outputs.git-hash }}
183+
115184
- name: Build frontend docs
185+
if: steps.cache-frontend-docs.outputs.cache-hit != 'true'
116186
run: |
117187
pnpm --filter ./packages/frontend run doc
118188
189+
- name: Report frontend docs cache status
190+
run: |
191+
if [ "${{ steps.cache-frontend-docs.outputs.cache-hit }}" = "true" ]; then
192+
echo "✅ Frontend docs restored from cache"
193+
else
194+
echo "🔨 Frontend docs built and cached"
195+
fi
196+
119197
- name: Upload frontend docs
120198
uses: actions/upload-artifact@v4
121199
with:
@@ -128,14 +206,42 @@ jobs:
128206
steps:
129207
- name: Checkout repository
130208
uses: actions/checkout@v4
209+
with:
210+
# Need full history for `git log` for cache key
211+
fetch-depth: 0
212+
213+
- name: Compute cache key
214+
id: cache-key
215+
run: |
216+
# Get git hash for all Rust packages
217+
hash=$(git log -1 --format="%H" -- packages/catlog packages/catlog-wasm packages/backend packages/notebook-types Cargo.toml Cargo.lock)
218+
echo "git-hash=${hash}" >> $GITHUB_OUTPUT
219+
echo "Rust hash: ${hash}"
220+
221+
- name: Cache Rust docs build
222+
id: cache-rust-docs
223+
uses: actions/cache@v4
224+
with:
225+
path: target/doc
226+
key: rust-docs-${{ steps.cache-key.outputs.git-hash }}
131227

132228
- name: Install Rust toolchain from file
229+
if: steps.cache-rust-docs.outputs.cache-hit != 'true'
133230
uses: actions-rust-lang/setup-rust-toolchain@v1
134231

135232
- name: Build Rust docs
233+
if: steps.cache-rust-docs.outputs.cache-hit != 'true'
136234
run: |
137235
cargo doc --all-features --no-deps --workspace --exclude "migrator"
138236
237+
- name: Report cache status
238+
run: |
239+
if [ "${{ steps.cache-rust-docs.outputs.cache-hit }}" = "true" ]; then
240+
echo "✅ Rust docs restored from cache"
241+
else
242+
echo "🔨 Rust docs built and cached"
243+
fi
244+
139245
- name: Upload Rust docs
140246
uses: actions/upload-artifact@v4
141247
with:
@@ -148,11 +254,30 @@ jobs:
148254
steps:
149255
- name: Repository Checkout
150256
uses: actions/checkout@v4
257+
with:
258+
# Need full history for `git log` for cache key
259+
fetch-depth: 0
260+
261+
- name: Compute cache key
262+
id: cache-key
263+
run: |
264+
hash=$(git log -1 --format="%H" -- math-docs)
265+
echo "git-hash=${hash}" >> $GITHUB_OUTPUT
266+
echo "Math docs hash: ${hash}"
267+
268+
- name: Cache math docs build
269+
id: cache-math-docs
270+
uses: actions/cache@v4
271+
with:
272+
path: math-docs/output
273+
key: math-docs-${{ steps.cache-key.outputs.git-hash }}
151274

152275
- name: Setup TinyTeX
276+
if: steps.cache-math-docs.outputs.cache-hit != 'true'
153277
uses: r-lib/actions/setup-tinytex@v2
154278

155279
- name: Install TeX Packages
280+
if: steps.cache-math-docs.outputs.cache-hit != 'true'
156281
run: |
157282
tlmgr update --self
158283
tlmgr install dvisvgm
@@ -164,10 +289,19 @@ jobs:
164289
tlmgr install spath3
165290
166291
- name: Build mathematical docs
292+
if: steps.cache-math-docs.outputs.cache-hit != 'true'
167293
run: |
168294
cd math-docs
169295
./forester build
170296
297+
- name: Report cache status
298+
run: |
299+
if [ "${{ steps.cache-math-docs.outputs.cache-hit }}" = "true" ]; then
300+
echo "✅ Math docs restored from cache"
301+
else
302+
echo "🔨 Math docs built and cached"
303+
fi
304+
171305
- name: Upload mathematical docs
172306
uses: actions/upload-artifact@v4
173307
with:
@@ -180,22 +314,51 @@ jobs:
180314
steps:
181315
- name: Checkout repository
182316
uses: actions/checkout@v4
317+
with:
318+
# Need full history for `git log` for cache key
319+
fetch-depth: 0
320+
321+
- name: Compute cache key
322+
id: cache-key
323+
run: |
324+
hash=$(git log -1 --format="%H" -- packages/ui-components)
325+
echo "git-hash=${hash}" >> $GITHUB_OUTPUT
326+
echo "UI Components hash: ${hash}"
327+
328+
- name: Cache ui-components build
329+
id: cache-ui-components
330+
uses: actions/cache@v4
331+
with:
332+
path: packages/ui-components/storybook-static
333+
key: ui-components-${{ steps.cache-key.outputs.git-hash }}
183334

184335
- name: Setup pnpm
336+
if: steps.cache-ui-components.outputs.cache-hit != 'true'
185337
uses: pnpm/action-setup@v4
186338

187339
- name: Setup NodeJS
340+
if: steps.cache-ui-components.outputs.cache-hit != 'true'
188341
uses: actions/setup-node@v4
189342
with:
190343
node-version: 24
191344
cache: "pnpm"
192345

193346
- name: Install dependencies
347+
if: steps.cache-ui-components.outputs.cache-hit != 'true'
194348
run: pnpm install
195349

196350
- name: Build ui-components Storybook
351+
if: steps.cache-ui-components.outputs.cache-hit != 'true'
197352
run: pnpm --filter ./packages/ui-components run build
198353

354+
- name: Report cache status
355+
run: |
356+
if [ "${{ steps.cache-ui-components.outputs.cache-hit }}" = "true" ]; then
357+
echo "✅ UI Components Storybook restored from cache"
358+
else
359+
echo "🔨 UI Components Storybook built and cached"
360+
fi
361+
199362
- name: Upload ui-components Storybook
200363
uses: actions/upload-artifact@v4
201364
with:

0 commit comments

Comments
 (0)