Skip to content

Commit 9ce2a0f

Browse files
Saadnajmiclaude
andcommitted
feat(0.81, ci): add content-hash caching for SPM slice and compose jobs
- Cache slice builds keyed on source file hashes (Package.swift, ios-prebuild scripts, React/**, ReactCommon/**, Libraries/**) - Cache composed xcframework with same hash key - Skip toolchain setup, yarn install, and build steps on cache hit - Only save caches on main/0.81-stable to avoid cache explosion Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 099df39 commit 9ce2a0f

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/microsoft-build-spm.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,35 +226,59 @@ jobs:
226226
filter: blob:none
227227
fetch-depth: 0
228228

229+
- name: Restore slice cache
230+
id: cache-slice
231+
uses: actions/cache/restore@v4
232+
with:
233+
key: v1-macos-core-${{ matrix.platform }}-Debug-${{ hashFiles('packages/react-native/Package.swift', 'packages/react-native/scripts/ios-prebuild/*.js', 'packages/react-native/scripts/ios-prebuild.js', 'packages/react-native/React/**/*', 'packages/react-native/ReactCommon/**/*', 'packages/react-native/Libraries/**/*') }}
234+
path: |
235+
packages/react-native/.build/output/spm/Debug/Build/Products
236+
packages/react-native/.build/headers
237+
229238
- name: Setup toolchain
239+
if: steps.cache-slice.outputs.cache-hit != 'true'
230240
uses: ./.github/actions/microsoft-setup-toolchain
231241
with:
232242
node-version: '22'
233243
platform: ${{ matrix.platform }}
234244

235245
- name: Install npm dependencies
246+
if: steps.cache-slice.outputs.cache-hit != 'true'
236247
run: yarn install
237248

238249
- name: Download Hermes artifacts
250+
if: steps.cache-slice.outputs.cache-hit != 'true'
239251
uses: actions/download-artifact@v4
240252
with:
241253
name: hermes-artifacts
242254
path: packages/react-native/.build/artifacts/hermes/destroot
243255

244256
- name: Create Hermes version marker
257+
if: steps.cache-slice.outputs.cache-hit != 'true'
245258
working-directory: packages/react-native
246259
run: |
247260
VERSION=$(node -p "require('./package.json').version")
248261
echo "${VERSION}-Debug" > .build/artifacts/hermes/version.txt
249262
250263
- name: Setup SPM workspace (using prebuilt Hermes)
264+
if: steps.cache-slice.outputs.cache-hit != 'true'
251265
working-directory: packages/react-native
252266
run: node scripts/ios-prebuild.js -s -f Debug
253267

254268
- name: Build SPM (${{ matrix.platform }})
269+
if: steps.cache-slice.outputs.cache-hit != 'true'
255270
working-directory: packages/react-native
256271
run: node scripts/ios-prebuild.js -b -f Debug -p ${{ matrix.platform }}
257272

273+
- name: Save slice cache
274+
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/0.81-stable' }}
275+
uses: actions/cache/save@v4
276+
with:
277+
key: v1-macos-core-${{ matrix.platform }}-Debug-${{ hashFiles('packages/react-native/Package.swift', 'packages/react-native/scripts/ios-prebuild/*.js', 'packages/react-native/scripts/ios-prebuild.js', 'packages/react-native/React/**/*', 'packages/react-native/ReactCommon/**/*', 'packages/react-native/Libraries/**/*') }}
278+
path: |
279+
packages/react-native/.build/output/spm/Debug/Build/Products
280+
packages/react-native/.build/headers
281+
258282
- name: Upload headers
259283
uses: actions/upload-artifact@v4
260284
with:
@@ -278,50 +302,76 @@ jobs:
278302
with:
279303
filter: blob:none
280304

305+
- name: Restore compose cache
306+
id: cache-xcframework
307+
uses: actions/cache/restore@v4
308+
with:
309+
key: v1-macos-core-xcframework-Debug-${{ hashFiles('packages/react-native/Package.swift', 'packages/react-native/scripts/ios-prebuild/*.js', 'packages/react-native/scripts/ios-prebuild.js', 'packages/react-native/React/**/*', 'packages/react-native/ReactCommon/**/*', 'packages/react-native/Libraries/**/*') }}
310+
path: |
311+
packages/react-native/.build/output/xcframeworks/ReactCoreDebug.xcframework.tar.gz
312+
packages/react-native/.build/output/xcframeworks/ReactCoreDebug.framework.dSYM.tar.gz
313+
281314
- name: Setup toolchain
315+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
282316
uses: ./.github/actions/microsoft-setup-toolchain
283317
with:
284318
node-version: '22'
285319
platform: ios
286320

287321
- name: Install npm dependencies
322+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
288323
run: yarn install
289324

290325
- name: Download slice artifacts
326+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
291327
uses: actions/download-artifact@v4
292328
with:
293329
pattern: prebuild-macos-core-slice-Debug-*
294330
path: packages/react-native/.build/output/spm/Debug/Build/Products
295331
merge-multiple: true
296332

297333
- name: Download headers
334+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
298335
uses: actions/download-artifact@v4
299336
with:
300337
pattern: prebuild-macos-core-headers-Debug-*
301338
path: packages/react-native/.build/headers
302339
merge-multiple: true
303340

304341
- name: Verify downloaded artifacts
342+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
305343
run: |
306344
echo "=== Products directory ==="
307345
ls -R packages/react-native/.build/output/spm/Debug/Build/Products/ | head -40
308346
echo "=== Headers directory ==="
309347
ls packages/react-native/.build/headers/ | head -20
310348
311349
- name: Create XCFramework
350+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
312351
working-directory: packages/react-native
313352
run: node scripts/ios-prebuild -c -f Debug
314353

315354
- name: Compress XCFramework
355+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
316356
run: |
317357
cd packages/react-native/.build/output/xcframeworks/Debug
318358
tar -cz -f ../ReactCoreDebug.xcframework.tar.gz React.xcframework
319359
320360
- name: Compress dSYMs
361+
if: steps.cache-xcframework.outputs.cache-hit != 'true'
321362
run: |
322363
cd packages/react-native/.build/output/xcframeworks/Debug/Symbols
323364
tar -cz -f ../../ReactCoreDebug.framework.dSYM.tar.gz .
324365
366+
- name: Save compose cache
367+
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/0.81-stable' }}
368+
uses: actions/cache/save@v4
369+
with:
370+
key: v1-macos-core-xcframework-Debug-${{ hashFiles('packages/react-native/Package.swift', 'packages/react-native/scripts/ios-prebuild/*.js', 'packages/react-native/scripts/ios-prebuild.js', 'packages/react-native/React/**/*', 'packages/react-native/ReactCommon/**/*', 'packages/react-native/Libraries/**/*') }}
371+
path: |
372+
packages/react-native/.build/output/xcframeworks/ReactCoreDebug.xcframework.tar.gz
373+
packages/react-native/.build/output/xcframeworks/ReactCoreDebug.framework.dSYM.tar.gz
374+
325375
- name: Upload XCFramework
326376
uses: actions/upload-artifact@v4
327377
with:

0 commit comments

Comments
 (0)