From e519b78a5faa38dda78a976610f4d37b4cb0c861 Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Wed, 25 Nov 2026 12:50:09 +0200 Subject: [PATCH 1/4] ci: cache the Yarn cache and node_modules between runs Without its cache folder Yarn downloads every package again even when node_modules is there, so both are restored, on an exact key match only. yarn install --immutable still runs. --- .github/actions/setup/action.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 4fd9305..9bd2464 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -14,6 +14,36 @@ runs: with: node-version-file: .nvmrc + # Without its cache folder Yarn downloads every package again, even when + # node_modules is there (about 3 minutes on macOS), and without + # node_modules it links the whole tree again. The key covers everything + # that decides what gets installed, and there is no partial match, so a + # restored tree always belongs to this exact lockfile. The install below + # still runs with --immutable and checks it. + - name: Restore dependencies + id: cache + uses: actions/cache/restore@v4 + with: + path: | + .yarn/cache + .yarn/install-state.gz + node_modules + example/node_modules + key: yarn-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', '.yarnrc.yml', '.yarn/releases/**', '.yarn/patches/**', 'yarn.lock', 'package.json', 'example/package.json') }} + - name: Install dependencies run: yarn install --immutable shell: bash + + # Saved right after the install, before pod install or a build writes + # anything into node_modules. + - name: Save dependencies + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + .yarn/cache + .yarn/install-state.gz + node_modules + example/node_modules + key: ${{ steps.cache.outputs.cache-primary-key }} From 75891f2dda22b98c31365799a6ac90f6aa93dfae Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Wed, 25 Nov 2026 12:50:09 +0200 Subject: [PATCH 2/4] ci: cache Pods and compiled objects, build arm64 only, and bundle while building Xcode's compilation cache is kept between runs, keyed on the Xcode build and the lockfiles. The runner is Apple silicon, so x86_64 is no longer built. Metro is asked for the app's bundle while Xcode builds. --- .github/workflows/ci.yml | 77 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83822e7..847497a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,14 +85,64 @@ jobs: - name: Install xcpretty run: command -v xcpretty >/dev/null || sudo gem install xcpretty --no-document + # The compilation cache is only valid for the Xcode that wrote it. It + # lives outside the checkout so that Jest and ESLint never walk it. + - name: Show Xcode version + id: xcode + run: | + xcodebuild -version + echo "build=$(xcodebuild -version | awk '/Build version/ { print $3 }')" >> "$GITHUB_OUTPUT" + echo "XCODE_CAS=$RUNNER_TEMP/xcode-cas" >> "$GITHUB_ENV" + + # Pods holds the React Native, Hermes and Skia prebuilts unpacked, which + # is most of pod install's time. pod install still runs and brings Pods + # in line with the Podfile when anything differs. + - name: Restore Pods + id: pods + uses: actions/cache/restore@v4 + with: + path: example/ios/Pods + key: pods-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('example/ios/Podfile', 'example/ios/Podfile.lock', 'yarn.lock') }} + - name: Install CocoaPods working-directory: example/ios run: pod install + - name: Save Pods + if: steps.pods.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: example/ios/Pods + key: ${{ steps.pods.outputs.cache-primary-key }} + + # Asks Metro for the bundle the app will load while Xcode builds, so the + # first launch does not wait for it. The URL is the one the debug app + # requests; a different one would bundle with other options and warm + # nothing. - name: Start Package Manager working-directory: example - run: CI=true yarn start --port $METRO_PORT --reset-cache & - + run: | + CI=true yarn start --port "$METRO_PORT" --reset-cache & + ( + until curl -sf "http://localhost:$METRO_PORT/status" > /dev/null; do sleep 1; done + curl -sf -o /dev/null "http://localhost:$METRO_PORT/index.bundle?platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server&app=com.reactnativewebcodecs.example" + ) > /dev/null 2>&1 & + + # Xcode's compilation cache stores each compile's output under a hash of + # all its inputs (sources, headers, flags, compiler), so a stale entry is + # never used: anything that changed is a miss and compiles as usual. + - name: Restore compilation cache + id: cas + uses: actions/cache/restore@v4 + with: + path: ${{ env.XCODE_CAS }} + key: xcode-cas-${{ runner.os }}-${{ runner.arch }}-${{ steps.xcode.outputs.build }}-${{ hashFiles('example/ios/Podfile.lock', 'yarn.lock') }} + restore-keys: | + xcode-cas-${{ runner.os }}-${{ runner.arch }}-${{ steps.xcode.outputs.build }}- + + # The runner is Apple silicon, so only arm64 is built: the generic + # destination alone would build x86_64 as well. The raw log is kept to + # count the compilation cache hits. - name: Build example for iOS working-directory: example/ios run: | @@ -103,9 +153,26 @@ jobs: -sdk iphonesimulator \ -destination "generic/platform=iOS Simulator" \ -derivedDataPath build \ + ARCHS=arm64 \ COMPILER_INDEX_STORE_ENABLE=NO \ - build | xcpretty + COMPILATION_CACHE_ENABLE_CACHING=YES \ + COMPILATION_CACHE_CAS_PATH="$XCODE_CAS" \ + COMPILATION_CACHE_ENABLE_DIAGNOSTIC_REMARKS=YES \ + build 2>&1 | tee "$RUNNER_TEMP/xcodebuild.log" | xcpretty + echo "Compilation cache: $(grep -c '^Cache hit' "$RUNNER_TEMP/xcodebuild.log") hits, $(grep -c '^Cache miss' "$RUNNER_TEMP/xcodebuild.log") misses, $(du -sh "$XCODE_CAS" | cut -f1)" + + # Saved right after the build, so a failing e2e run still keeps it. + - name: Save compilation cache + if: steps.cas.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ env.XCODE_CAS }} + key: ${{ steps.cas.outputs.cache-primary-key }} + # Booted only now, not in the background during the earlier steps: on + # the runner a booting simulator slowed the steps running beside it for + # minutes (unpacking Node.js went from 5 s to over a minute), more than + # the boot itself takes. - name: Prepare iOS simulator run: | RUNTIME=$(xcrun simctl list runtimes available --json | jq -r ' @@ -115,8 +182,8 @@ jobs: .devicetypes | map(select(.name | test("^iPhone [0-9]+ Pro$"))) | sort_by(.name | capture("^iPhone (?[0-9]+) Pro$").n | tonumber) | last | .identifier') UDID=$(xcrun simctl create "$IOS_SIMULATOR" "$DEVICE_TYPE" "$RUNTIME") - echo "IOS_SIMULATOR_UDID=$UDID" >> $GITHUB_ENV - echo "SIMULATOR_UDID=$UDID" >> $GITHUB_ENV + echo "IOS_SIMULATOR_UDID=$UDID" >> "$GITHUB_ENV" + echo "SIMULATOR_UDID=$UDID" >> "$GITHUB_ENV" xcrun simctl boot "$UDID" xcrun simctl bootstatus "$UDID" -b From a926ac4902e23cd51514020556848197f759dd59 Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Wed, 25 Nov 2026 13:28:51 +0200 Subject: [PATCH 3/4] ci: cache Homebrew's downloads for ffmpeg Keyed on the runner image and the ffmpeg version, with Homebrew's auto update, cleanup and dependents check off for the install. --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 847497a..773630d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,9 +78,40 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} + # Most of installing ffmpeg is downloading its bottles and those of its + # dependencies. They are kept between runs, keyed on the runner image + # and the ffmpeg version Homebrew would install, so a new image or a new + # ffmpeg starts from an empty download cache. brew still installs from + # them and checks their checksums. + - name: Find ffmpeg version + id: ffmpeg + env: + HOMEBREW_NO_AUTO_UPDATE: 1 + run: | + echo "version=$(brew info --json=v2 ffmpeg | jq -r '.formulae[0].versions.stable')" >> "$GITHUB_OUTPUT" + echo "dir=$(brew --cache)/downloads" >> "$GITHUB_OUTPUT" + + - name: Restore Homebrew downloads + id: brew + uses: actions/cache/restore@v4 + with: + path: ${{ steps.ffmpeg.outputs.dir }} + key: brew-${{ runner.os }}-${{ runner.arch }}-${{ env.ImageOS }}-${{ env.ImageVersion }}-ffmpeg-${{ steps.ffmpeg.outputs.version }} + - name: Install ffmpeg + env: + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 run: command -v ffprobe >/dev/null || brew install ffmpeg + - name: Save Homebrew downloads + if: steps.brew.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ steps.ffmpeg.outputs.dir }} + key: ${{ steps.brew.outputs.cache-primary-key }} + # xcpretty is a gem, not part of the macOS runner image. - name: Install xcpretty run: command -v xcpretty >/dev/null || sudo gem install xcpretty --no-document From 9e328243d70cf9970941e223917c034eb27bea62 Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Wed, 25 Nov 2026 13:51:08 +0200 Subject: [PATCH 4/4] ci: key the Homebrew cache on the runner image ImageOS and ImageVersion are set on the runner, not in the workflow's env context, so read them in the shell. --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 773630d..e876f53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,15 +88,18 @@ jobs: env: HOMEBREW_NO_AUTO_UPDATE: 1 run: | - echo "version=$(brew info --json=v2 ffmpeg | jq -r '.formulae[0].versions.stable')" >> "$GITHUB_OUTPUT" - echo "dir=$(brew --cache)/downloads" >> "$GITHUB_OUTPUT" + { + echo "version=$(brew info --json=v2 ffmpeg | jq -r '.formulae[0].versions.stable')" + echo "dir=$(brew --cache)/downloads" + echo "image=$ImageOS-$ImageVersion" + } >> "$GITHUB_OUTPUT" - name: Restore Homebrew downloads id: brew uses: actions/cache/restore@v4 with: path: ${{ steps.ffmpeg.outputs.dir }} - key: brew-${{ runner.os }}-${{ runner.arch }}-${{ env.ImageOS }}-${{ env.ImageVersion }}-ffmpeg-${{ steps.ffmpeg.outputs.version }} + key: brew-${{ runner.os }}-${{ runner.arch }}-${{ steps.ffmpeg.outputs.image }}-ffmpeg-${{ steps.ffmpeg.outputs.version }} - name: Install ffmpeg env: