Skip to content

Commit 6125a5d

Browse files
authored
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 Pull Request resolved: #59931
1 parent b160320 commit 6125a5d

2 files changed

Lines changed: 52 additions & 47 deletions

File tree

‎.github/workflows/prebuild-ios-core.yml‎

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,27 @@ jobs:
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v6
28+
- name: Set Hermes version
29+
shell: bash
30+
env:
31+
USE_HERMES_PREBUILT: ${{ inputs.use-hermes-prebuilt }}
32+
run: |
33+
if [ "$USE_HERMES_PREBUILT" == "true" ]; then
34+
HERMES_VERSION=$(curl --fail --silent --show-error --retry 3 https://registry.npmjs.org/hermes-compiler/latest-v1 | jq -er '.version')
35+
else
36+
HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties)
37+
fi
38+
test -n "$HERMES_VERSION"
39+
echo "HERMES_VERSION=$HERMES_VERSION" >> "$GITHUB_ENV"
2840
- name: Restore cache if present
2941
id: restore-ios-slice
42+
if: inputs.version-type == ''
3043
uses: actions/cache/restore@v5
3144
with:
32-
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/**/*') }}
33-
path: packages/react-native/
45+
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 }}
46+
path: |
47+
packages/react-native/.build/output/spm/${{ matrix.flavor }}/Build/Products
48+
packages/react-native/.build/headers
3449
- name: Setup node.js
3550
if: steps.restore-ios-slice.outputs.cache-hit != 'true'
3651
uses: ./.github/actions/setup-node
@@ -40,19 +55,6 @@ jobs:
4055
- name: Yarn Install
4156
if: steps.restore-ios-slice.outputs.cache-hit != 'true'
4257
uses: ./.github/actions/yarn-install
43-
- name: Set Hermes version
44-
shell: bash
45-
run: |
46-
# Non-stable RN builds resolve Hermes from npm's latest-v1 dist-tag.
47-
# TODO: rename 'latest-v1' to 'latest' once V1 is the only Hermes on npm.
48-
# Stable builds use the version pinned in version.properties.
49-
if [ "${{ inputs.use-hermes-prebuilt }}" == "true" ]; then
50-
HERMES_VERSION="latest-v1"
51-
else
52-
HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties)
53-
fi
54-
echo "Using Hermes version: $HERMES_VERSION"
55-
echo "HERMES_VERSION=$HERMES_VERSION" >> $GITHUB_ENV
5658
- name: Set React Native version
5759
shell: bash
5860
run: |
@@ -108,9 +110,9 @@ jobs:
108110
packages/react-native/.build/output/spm/${{ matrix.flavor }}/Build/Products
109111
- name: Save Cache
110112
uses: actions/cache/save@v5
111-
if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode
113+
if: ${{ github.ref == 'refs/heads/main' && inputs.version-type == '' && steps.restore-ios-slice.outputs.cache-hit != 'true' }}
112114
with:
113-
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/**/*') }}
115+
key: ${{ steps.restore-ios-slice.outputs.cache-primary-key }}
114116
path: |
115117
packages/react-native/.build/output/spm/${{ matrix.flavor }}/Build/Products
116118
packages/react-native/.build/headers
@@ -128,12 +130,28 @@ jobs:
128130
steps:
129131
- name: Checkout
130132
uses: actions/checkout@v6
133+
- name: Set Hermes version
134+
shell: bash
135+
env:
136+
USE_HERMES_PREBUILT: ${{ inputs.use-hermes-prebuilt }}
137+
run: |
138+
if [ "$USE_HERMES_PREBUILT" == "true" ]; then
139+
HERMES_VERSION=$(curl --fail --silent --show-error --retry 3 https://registry.npmjs.org/hermes-compiler/latest-v1 | jq -er '.version')
140+
else
141+
HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties)
142+
fi
143+
test -n "$HERMES_VERSION"
144+
echo "HERMES_VERSION=$HERMES_VERSION" >> "$GITHUB_ENV"
131145
- name: Restore cache if present
132146
id: restore-ios-xcframework
147+
if: inputs.version-type == ''
133148
uses: actions/cache/restore@v5
134149
with:
135-
path: packages/react-native/.build/output/xcframeworks
136-
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/**/*') }}
150+
path: |
151+
packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.xcframework.tar.gz
152+
packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.framework.dSYM.tar.gz
153+
packages/react-native/.build/output/xcframeworks/ReactNativeHeaders${{matrix.flavor}}.xcframework.tar.gz
154+
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 }}
137155
- name: Setup node.js
138156
if: steps.restore-ios-xcframework.outputs.cache-hit != 'true'
139157
uses: ./.github/actions/setup-node
@@ -175,20 +193,6 @@ jobs:
175193
tar -xzf /tmp/third-party/ReactNativeDependencies${{ matrix.flavor }}.xcframework.tar.gz -C /tmp/third-party/
176194
mkdir -p packages/react-native/third-party/
177195
mv /tmp/third-party/packages/react-native/third-party/ReactNativeDependencies.xcframework packages/react-native/third-party/ReactNativeDependencies.xcframework
178-
- name: Set Hermes version
179-
if: steps.restore-ios-xcframework.outputs.cache-hit != 'true'
180-
shell: bash
181-
run: |
182-
# Non-stable RN builds resolve Hermes from npm's latest-v1 dist-tag.
183-
# TODO: rename 'latest-v1' to 'latest' once V1 is the only Hermes on npm.
184-
# Stable builds use the version pinned in version.properties.
185-
if [ "${{ inputs.use-hermes-prebuilt }}" == "true" ]; then
186-
HERMES_VERSION="latest-v1"
187-
else
188-
HERMES_VERSION=$(sed -n 's/^HERMES_VERSION_NAME=//p' packages/react-native/sdks/hermes-engine/version.properties)
189-
fi
190-
echo "Using Hermes version: $HERMES_VERSION"
191-
echo "HERMES_VERSION=$HERMES_VERSION" >> $GITHUB_ENV
192196
- name: Stage Hermes headers
193197
if: steps.restore-ios-xcframework.outputs.cache-hit != 'true'
194198
working-directory: packages/react-native
@@ -260,11 +264,11 @@ jobs:
260264
name: ReactNativeHeaders${{ matrix.flavor }}.xcframework.tar.gz
261265
path: packages/react-native/.build/output/xcframeworks/ReactNativeHeaders${{matrix.flavor}}.xcframework.tar.gz
262266
- name: Save cache if present
263-
if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode
267+
if: ${{ github.ref == 'refs/heads/main' && inputs.version-type == '' && steps.restore-ios-xcframework.outputs.cache-hit != 'true' }}
264268
uses: actions/cache/save@v5
265269
with:
266270
path: |
267271
packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.xcframework.tar.gz
268272
packages/react-native/.build/output/xcframeworks/ReactCore${{matrix.flavor}}.framework.dSYM.tar.gz
269273
packages/react-native/.build/output/xcframeworks/ReactNativeHeaders${{matrix.flavor}}.xcframework.tar.gz
270-
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/**/*') }}
274+
key: ${{ steps.restore-ios-xcframework.outputs.cache-primary-key }}

‎.github/workflows/prebuild-ios-dependencies.yml‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: actions/cache/restore@v5
1818
with:
1919
path: packages/react-native/third-party/
20-
key: v3-ios-dependencies-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js') }}
20+
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') }}
2121
enableCrossOsArchive: true
2222
- name: Yarn Install
2323
if: steps.restore-ios-prebuilds.outputs.cache-hit != 'true'
@@ -37,9 +37,9 @@ jobs:
3737
path: packages/react-native/third-party/
3838
- name: Save Cache
3939
uses: actions/cache/save@v5
40-
if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode
40+
if: ${{ github.ref == 'refs/heads/main' && steps.restore-ios-prebuilds.outputs.cache-hit != 'true' }}
4141
with:
42-
key: v3-ios-dependencies-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js') }}
42+
key: ${{ steps.restore-ios-prebuilds.outputs.cache-primary-key }}
4343
enableCrossOsArchive: true
4444
path: packages/react-native/third-party/
4545

@@ -72,7 +72,7 @@ jobs:
7272
uses: actions/cache/restore@v5
7373
with:
7474
path: packages/react-native/third-party/.build/Build/Products
75-
key: v3-ios-dependencies-slice-folder-${{ matrix.slice }}-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js', 'scripts/releases/ios-prebuild/build.js') }}
75+
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') }}
7676
- name: Setup xcode
7777
if: steps.restore-slice-folder.outputs.cache-hit != 'true'
7878
uses: ./.github/actions/setup-xcode
@@ -99,10 +99,9 @@ jobs:
9999
packages/react-native/third-party/.build/Build/Products
100100
- name: Save Cache
101101
uses: actions/cache/save@v5
102-
if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode
102+
if: ${{ github.ref == 'refs/heads/main' && steps.restore-slice-folder.outputs.cache-hit != 'true' }}
103103
with:
104-
key: v3-ios-dependencies-slice-folder-${{ matrix.slice }}-${{ matrix.flavor }}-${{ hashfiles('scripts/releases/ios-prebuild/configuration.js', 'scripts/releases/ios-prebuild/build.js') }}
105-
enableCrossOsArchive: true
104+
key: ${{ steps.restore-slice-folder.outputs.cache-primary-key }}
106105
path: |
107106
packages/react-native/third-party/.build/Build/Products
108107
@@ -129,8 +128,10 @@ jobs:
129128
uses: actions/cache/restore@v5
130129
with:
131130
path: |
132-
packages/react-native/third-party/
133-
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') }}
131+
packages/react-native/third-party/ReactNativeDependencies${{ matrix.flavor }}.xcframework.tar.gz
132+
packages/react-native/third-party/ReactNativeDependenciesHeaders${{ matrix.flavor }}.xcframework.tar.gz
133+
packages/react-native/third-party/Symbols/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz
134+
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') }}
134135
# If cache hit, we already have our binary. We don't need to do anything.
135136
- name: Yarn Install
136137
if: steps.restore-xcframework.outputs.cache-hit != 'true'
@@ -197,11 +198,11 @@ jobs:
197198
path: |
198199
packages/react-native/third-party/Symbols/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz
199200
- name: Save XCFramework in Cache
200-
if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode
201+
if: ${{ github.ref == 'refs/heads/main' && steps.restore-xcframework.outputs.cache-hit != 'true' }}
201202
uses: actions/cache/save@v5
202203
with:
203204
path: |
204205
packages/react-native/third-party/ReactNativeDependencies${{ matrix.flavor }}.xcframework.tar.gz
205206
packages/react-native/third-party/ReactNativeDependenciesHeaders${{ matrix.flavor }}.xcframework.tar.gz
206-
packages/react-native/third-party/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz
207-
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') }}
207+
packages/react-native/third-party/Symbols/ReactNativeDependencies${{ matrix.flavor }}.framework.dSYM.tar.gz
208+
key: ${{ steps.restore-xcframework.outputs.cache-primary-key }}

0 commit comments

Comments
 (0)