From 6a5c0b444c91728bb99511890e375e3461e9608d Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 11 Nov 2026 04:17:58 -0800 Subject: [PATCH] Fix iOS prebuild cache reuse (#59931) Summary: Fix iOS prebuild cache reuse within the existing slice and composition jobs. Restore and save identical paths, and save the original cache-primary-key rather than hashing the post-build workspace. Correct the dependency dSYM cache path. Hash native sources, Codegen and dependency inputs before build setup, without invalidating native caches for ordinary library JavaScript changes. Resolve Hermes before cache lookup and include its exact version in the key. No new jobs, workflows or cross-job outputs are needed. Keep version-stamped builds out of the unstamped CI caches and bump the affected namespaces. Android jobs are unchanged. Changelog: [Internal] Differential Revision: D131180216 --- .github/workflows/prebuild-ios-core.yml | 74 ++++++++++--------- .../workflows/prebuild-ios-dependencies.yml | 25 ++++--- 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/.github/workflows/prebuild-ios-core.yml b/.github/workflows/prebuild-ios-core.yml index ae1fdb916675..32030ea60e86 100644 --- a/.github/workflows/prebuild-ios-core.yml +++ b/.github/workflows/prebuild-ios-core.yml @@ -25,12 +25,27 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 + - name: Set Hermes version + shell: bash + env: + USE_HERMES_PREBUILT: ${{ inputs.use-hermes-prebuilt }} + run: | + if [ "$USE_HERMES_PREBUILT" == "true" ]; then + HERMES_VERSION=$(curl --fail --silent --show-error --retry 3 https://registry.npmjs.org/hermes-compiler/latest-v1 | jq -er '.version') + else + HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties) + fi + test -n "$HERMES_VERSION" + echo "HERMES_VERSION=$HERMES_VERSION" >> "$GITHUB_ENV" - name: Restore cache if present id: restore-ios-slice + if: inputs.version-type == '' uses: actions/cache/restore@v5 with: - key: v3-ios-core-${{ matrix.slice }}-${{ matrix.flavor }}-${{ 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/**/*') }} - path: packages/react-native/ + key: v4-ios-core-${{ matrix.slice }}-${{ matrix.flavor }}-${{ hashFiles('.github/workflows/prebuild-ios-*.yml', '.github/actions/setup-*/action.yml', '.github/actions/yarn-install/action.yml', 'package.json', 'yarn.lock', 'babel.config.js', 'scripts/build/**/*', 'scripts/releases/ios-prebuild/**/*', 'scripts/releases/prepare-ios-prebuilds.js', 'packages/react-native/package.json', 'packages/react-native/Package.swift', 'packages/react-native/scripts/**/*', 'packages/react-native-codegen/**/*', 'packages/react-native/React/**/*', 'packages/react-native/ReactApple/**/*', 'packages/react-native/ReactCommon/**/*', 'packages/react-native/Libraries/**/*', 'packages/react-native/src/private/specs*/**/*', 'packages/react-native/src/**/Native*.js', 'packages/react-native/src/**/*NativeComponent.js', 'packages/react-native/third-party-podspecs/**/PrivacyInfo.xcprivacy', 'packages/react-native/sdks/hermes-engine/version.properties', '!packages/react-native/Libraries/**/*.js', '!packages/react-native/Libraries/**/*.js.flow', '!packages/react-native/Libraries/**/*.ts', '!packages/react-native/Libraries/**/*.tsx') }}-${{ env.HERMES_VERSION }} + path: | + packages/react-native/.build/output/spm/${{ matrix.flavor }}/Build/Products + packages/react-native/.build/headers - name: Setup node.js if: steps.restore-ios-slice.outputs.cache-hit != 'true' uses: ./.github/actions/setup-node @@ -40,19 +55,6 @@ jobs: - name: Yarn Install if: steps.restore-ios-slice.outputs.cache-hit != 'true' uses: ./.github/actions/yarn-install - - name: Set Hermes version - shell: bash - run: | - # Non-stable RN builds resolve Hermes from npm's latest-v1 dist-tag. - # TODO: rename 'latest-v1' to 'latest' once V1 is the only Hermes on npm. - # Stable builds use the version pinned in version.properties. - if [ "${{ inputs.use-hermes-prebuilt }}" == "true" ]; then - HERMES_VERSION="latest-v1" - else - HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties) - fi - echo "Using Hermes version: $HERMES_VERSION" - echo "HERMES_VERSION=$HERMES_VERSION" >> $GITHUB_ENV - name: Set React Native version shell: bash run: | @@ -108,9 +110,9 @@ jobs: packages/react-native/.build/output/spm/${{ matrix.flavor }}/Build/Products - name: Save Cache uses: actions/cache/save@v5 - if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode + if: ${{ github.ref == 'refs/heads/main' && inputs.version-type == '' && steps.restore-ios-slice.outputs.cache-hit != 'true' }} with: - key: v3-ios-core-${{ matrix.slice }}-${{ matrix.flavor }}-${{ 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/**/*') }} + key: ${{ steps.restore-ios-slice.outputs.cache-primary-key }} path: | packages/react-native/.build/output/spm/${{ matrix.flavor }}/Build/Products packages/react-native/.build/headers @@ -128,12 +130,28 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 + - name: Set Hermes version + shell: bash + env: + USE_HERMES_PREBUILT: ${{ inputs.use-hermes-prebuilt }} + run: | + if [ "$USE_HERMES_PREBUILT" == "true" ]; then + HERMES_VERSION=$(curl --fail --silent --show-error --retry 3 https://registry.npmjs.org/hermes-compiler/latest-v1 | jq -er '.version') + else + HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties) + fi + test -n "$HERMES_VERSION" + echo "HERMES_VERSION=$HERMES_VERSION" >> "$GITHUB_ENV" - name: Restore cache if present id: restore-ios-xcframework + if: inputs.version-type == '' uses: actions/cache/restore@v5 with: - path: packages/react-native/.build/output/xcframeworks - key: v4-ios-core-xcframework-${{ matrix.flavor }}-${{ 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/**/*') }} + path: | + packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.xcframework.tar.gz + packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.framework.dSYM.tar.gz + packages/react-native/.build/output/xcframeworks/ReactNativeHeaders${{matrix.flavor}}.xcframework.tar.gz + key: v5-ios-core-xcframework-${{ matrix.flavor }}-${{ hashFiles('.github/workflows/prebuild-ios-*.yml', '.github/actions/setup-*/action.yml', '.github/actions/yarn-install/action.yml', 'package.json', 'yarn.lock', 'babel.config.js', 'scripts/build/**/*', 'scripts/releases/ios-prebuild/**/*', 'scripts/releases/prepare-ios-prebuilds.js', 'packages/react-native/package.json', 'packages/react-native/Package.swift', 'packages/react-native/scripts/**/*', 'packages/react-native-codegen/**/*', 'packages/react-native/React/**/*', 'packages/react-native/ReactApple/**/*', 'packages/react-native/ReactCommon/**/*', 'packages/react-native/Libraries/**/*', 'packages/react-native/src/private/specs*/**/*', 'packages/react-native/src/**/Native*.js', 'packages/react-native/src/**/*NativeComponent.js', 'packages/react-native/third-party-podspecs/**/PrivacyInfo.xcprivacy', 'packages/react-native/sdks/hermes-engine/version.properties', '!packages/react-native/Libraries/**/*.js', '!packages/react-native/Libraries/**/*.js.flow', '!packages/react-native/Libraries/**/*.ts', '!packages/react-native/Libraries/**/*.tsx') }}-${{ env.HERMES_VERSION }} - name: Setup node.js if: steps.restore-ios-xcframework.outputs.cache-hit != 'true' uses: ./.github/actions/setup-node @@ -175,20 +193,6 @@ jobs: tar -xzf /tmp/third-party/ReactNativeDependencies${{ matrix.flavor }}.xcframework.tar.gz -C /tmp/third-party/ mkdir -p packages/react-native/third-party/ mv /tmp/third-party/packages/react-native/third-party/ReactNativeDependencies.xcframework packages/react-native/third-party/ReactNativeDependencies.xcframework - - name: Set Hermes version - if: steps.restore-ios-xcframework.outputs.cache-hit != 'true' - shell: bash - run: | - # Non-stable RN builds resolve Hermes from npm's latest-v1 dist-tag. - # TODO: rename 'latest-v1' to 'latest' once V1 is the only Hermes on npm. - # Stable builds use the version pinned in version.properties. - if [ "${{ inputs.use-hermes-prebuilt }}" == "true" ]; then - HERMES_VERSION="latest-v1" - else - HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties) - fi - echo "Using Hermes version: $HERMES_VERSION" - echo "HERMES_VERSION=$HERMES_VERSION" >> $GITHUB_ENV - name: Stage Hermes headers if: steps.restore-ios-xcframework.outputs.cache-hit != 'true' working-directory: packages/react-native @@ -260,11 +264,11 @@ jobs: name: ReactNativeHeaders${{ matrix.flavor }}.xcframework.tar.gz path: packages/react-native/.build/output/xcframeworks/ReactNativeHeaders${{matrix.flavor}}.xcframework.tar.gz - name: Save cache if present - if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode + if: ${{ github.ref == 'refs/heads/main' && inputs.version-type == '' && steps.restore-ios-xcframework.outputs.cache-hit != 'true' }} uses: actions/cache/save@v5 with: path: | packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.xcframework.tar.gz packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.framework.dSYM.tar.gz packages/react-native/.build/output/xcframeworks/ReactNativeHeaders${{matrix.flavor}}.xcframework.tar.gz - key: v4-ios-core-xcframework-${{ matrix.flavor }}-${{ 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/**/*') }} + key: ${{ steps.restore-ios-xcframework.outputs.cache-primary-key }} diff --git a/.github/workflows/prebuild-ios-dependencies.yml b/.github/workflows/prebuild-ios-dependencies.yml index d4afaed08eb5..2d6949832f43 100644 --- a/.github/workflows/prebuild-ios-dependencies.yml +++ b/.github/workflows/prebuild-ios-dependencies.yml @@ -17,7 +17,7 @@ jobs: uses: actions/cache/restore@v5 with: path: packages/react-native/third-party/ - key: v3-ios-dependencies-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js') }} + key: v4-ios-dependencies-${{ hashfiles('scripts/releases/ios-prebuild/**/*', 'scripts/releases/prepare-ios-prebuilds.js', 'packages/react-native/scripts/ios-configure-glog.sh', 'packages/react-native/third-party-podspecs/**/PrivacyInfo.xcprivacy', '.github/workflows/prebuild-ios-dependencies.yml') }} enableCrossOsArchive: true - name: Yarn Install if: steps.restore-ios-prebuilds.outputs.cache-hit != 'true' @@ -37,9 +37,9 @@ jobs: path: packages/react-native/third-party/ - name: Save Cache uses: actions/cache/save@v5 - if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode + if: ${{ github.ref == 'refs/heads/main' && steps.restore-ios-prebuilds.outputs.cache-hit != 'true' }} with: - key: v3-ios-dependencies-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js') }} + key: ${{ steps.restore-ios-prebuilds.outputs.cache-primary-key }} enableCrossOsArchive: true path: packages/react-native/third-party/ @@ -72,7 +72,7 @@ jobs: uses: actions/cache/restore@v5 with: path: packages/react-native/third-party/.build/Build/Products - key: v3-ios-dependencies-slice-folder-${{ matrix.slice }}-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js', 'scripts/releases/ios-prebuild/build.js') }} + key: v4-ios-dependencies-slice-folder-${{ matrix.slice }}-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/**/*', 'scripts/releases/prepare-ios-prebuilds.js', 'packages/react-native/scripts/ios-configure-glog.sh', 'packages/react-native/third-party-podspecs/**/PrivacyInfo.xcprivacy', '.github/workflows/prebuild-ios-dependencies.yml', '.github/actions/setup-xcode/action.yml') }} - name: Setup xcode if: steps.restore-slice-folder.outputs.cache-hit != 'true' uses: ./.github/actions/setup-xcode @@ -99,10 +99,9 @@ jobs: packages/react-native/third-party/.build/Build/Products - name: Save Cache uses: actions/cache/save@v5 - if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode + if: ${{ github.ref == 'refs/heads/main' && steps.restore-slice-folder.outputs.cache-hit != 'true' }} with: - key: v3-ios-dependencies-slice-folder-${{ matrix.slice }}-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js', 'scripts/releases/ios-prebuild/build.js') }} - enableCrossOsArchive: true + key: ${{ steps.restore-slice-folder.outputs.cache-primary-key }} path: | packages/react-native/third-party/.build/Build/Products @@ -129,8 +128,10 @@ jobs: uses: actions/cache/restore@v5 with: path: | - packages/react-native/third-party/ - key: v5-ios-dependencies-xcframework-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js', 'scripts/releases/ios-prebuild/build.js', 'scripts/releases/ios-prebuild/compose-framework.js', 'packages/react-native/scripts/ios-prebuild/headers-xcframework.js', 'packages/react-native/scripts/ios-prebuild/headers-spec.js') }} + packages/react-native/third-party/ReactNativeDependencies${{ matrix.flavor }}.xcframework.tar.gz + packages/react-native/third-party/ReactNativeDependenciesHeaders${{ matrix.flavor }}.xcframework.tar.gz + packages/react-native/third-party/Symbols/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz + key: v6-ios-dependencies-xcframework-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/**/*', 'scripts/releases/prepare-ios-prebuilds.js', 'packages/react-native/scripts/ios-configure-glog.sh', 'packages/react-native/third-party-podspecs/**/PrivacyInfo.xcprivacy', '.github/workflows/prebuild-ios-dependencies.yml', '.github/actions/setup-xcode/action.yml', 'packages/react-native/scripts/ios-prebuild/headers-xcframework.js', 'packages/react-native/scripts/ios-prebuild/headers-spec.js') }} # If cache hit, we already have our binary. We don't need to do anything. - name: Yarn Install if: steps.restore-xcframework.outputs.cache-hit != 'true' @@ -197,11 +198,11 @@ jobs: path: | packages/react-native/third-party/Symbols/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz - name: Save XCFramework in Cache - if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode + if: ${{ github.ref == 'refs/heads/main' && steps.restore-xcframework.outputs.cache-hit != 'true' }} uses: actions/cache/save@v5 with: path: | packages/react-native/third-party/ReactNativeDependencies${{ matrix.flavor }}.xcframework.tar.gz packages/react-native/third-party/ReactNativeDependenciesHeaders${{ matrix.flavor }}.xcframework.tar.gz - packages/react-native/third-party/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz - key: v5-ios-dependencies-xcframework-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js', 'scripts/releases/ios-prebuild/build.js', 'scripts/releases/ios-prebuild/compose-framework.js', 'packages/react-native/scripts/ios-prebuild/headers-xcframework.js', 'packages/react-native/scripts/ios-prebuild/headers-spec.js') }} + packages/react-native/third-party/Symbols/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz + key: ${{ steps.restore-xcframework.outputs.cache-primary-key }}