Skip to content

Commit b959dbd

Browse files
cipolleschiRiccardo Cipolleschi
authored and
Riccardo Cipolleschi
committedJun 8, 2023
Make CircleCI caches for hermesc be version dependent (#37452)
Summary: Pull Request resolved: #37452 Fixes #37428 We do have cache poisoning for hermesc on Windows and Linux due to reusing the same cache key among different React Native version. This fixes it by specifying a cache key which is version dependent + it invalidates the caches by defining a new key. Changelog: [Internal] [Fixed] - Make CircleCI caches for hermesc be version dependent Reviewed By: cortinico Differential Revision: D45909178 fbshipit-source-id: 830c87ae45739c7053342a68dac2ee7581945c1d
1 parent 8b9f371 commit b959dbd

File tree

1 file changed

+178
-6
lines changed

1 file changed

+178
-6
lines changed
 

‎.circleci/config.yml

+178-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,53 @@ references:
3030
attach_workspace:
3131
at: *hermes_workspace_root
3232

33+
main_only: &main_only
34+
filters:
35+
branches:
36+
only: main
37+
main_or_stable_only: &main_or_stable_only
38+
filters:
39+
branches:
40+
only:
41+
- main
42+
- /0\.[0-9]+[\.[0-9]+]?-stable/
43+
44+
45+
# -------------------------
46+
# Dependency Anchors
47+
# -------------------------
48+
dependency_versions:
49+
xcode_version: &xcode_version "14.0.1"
50+
nodelts_image: &nodelts_image "cimg/node:18.12.1"
51+
nodeprevlts_image: &nodeprevlts_image "cimg/node:16.18.1"
52+
53+
# -------------------------
54+
# Cache Key Anchors
55+
# -------------------------
56+
# Anchors for the cache keys
57+
58+
cache_keys:
59+
checkout_cache_key: &checkout_cache_key v5-checkout
60+
gems_cache_key: &gems_cache_key v1-gems-{{ checksum "Gemfile.lock" }}
61+
gradle_cache_key: &gradle_cache_key v1-gradle-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "ReactAndroid/gradle.properties" }}
62+
hermes_workspace_cache_key: &hermes_workspace_cache_key v4-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
63+
hermes_workspace_debug_cache_key: &hermes_workspace_debug_cache_key v2-hermes-{{ .Environment.CIRCLE_JOB }}-debug-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
64+
hermes_workspace_release_cache_key: &hermes_workspace_release_cache_key v2-hermes-{{ .Environment.CIRCLE_JOB }}-release-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
65+
hermes_linux_cache_key: &hermes_linux_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-linux-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
66+
hermes_windows_cache_key: &hermes_windows_cache_key v2-hermes-{{ .Environment.CIRCLE_JOB }}-windows-{{ checksum "/Users/circleci/project/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
67+
hermes_tarball_debug_cache_key: &hermes_tarball_debug_cache_key v4-hermes-tarball-debug-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
68+
hermes_tarball_release_cache_key: &hermes_tarball_release_cache_key v3-hermes-tarball-release-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
69+
pods_cache_key: &pods_cache_key v8-pods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock.bak" }}-{{ checksum "packages/rn-tester/Podfile" }}
70+
windows_yarn_cache_key: &windows_yarn_cache_key v1-win-yarn-cache-{{ arch }}-{{ checksum "yarn.lock" }}
71+
yarn_cache_key: &yarn_cache_key v5-yarn-cache-{{ .Environment.CIRCLE_JOB }}
72+
73+
cache_paths:
74+
hermes_workspace_macos_cache_paths: &hermes_workspace_macos_cache_paths
75+
- ~/react-native/sdks/hermes/build_macosx
76+
- ~/react-native/sdks/hermes/destroot
77+
hermes_tarball_cache_paths: &hermes_tarball_cache_paths
78+
- *hermes_tarball_artifacts_dir
79+
3380
# -------------------------
3481
# Filters
3582
# -------------------------
@@ -246,7 +293,124 @@ commands:
246293
name: Report size of RNTester.app (analysis-bot)
247294
command: GITHUB_TOKEN="$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A""$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B" scripts/circleci/report-bundle-size.sh << parameters.platform >> || true
248295

249-
with_hermes_sdk_cache_span:
296+
get_react_native_version:
297+
steps:
298+
- run:
299+
name: Get React Native version
300+
command: |
301+
VERSION=$(cat package.json | jq -r '.version')
302+
# Save the react native version we are building in a file so we can use that file as part of the cache key.
303+
echo "$VERSION" > /tmp/react-native-version
304+
echo "React Native Version is $(cat /tmp/react-native-version)"
305+
HERMES_VERSION="$(cat /tmp/hermes/hermesversion)"
306+
echo "Hermes commit is $HERMES_VERSION"
307+
308+
get_react_native_version_windows:
309+
steps:
310+
- run:
311+
name: Get React Native version on Windows
312+
command: |
313+
$VERSION=cat packages/react-native/package.json | jq -r '.version'
314+
# Save the react native version we are building in a file so we can use that file as part of the cache key.
315+
echo "$VERSION" > /tmp/react-native-version
316+
echo "React Native Version is $(cat /tmp/react-native-version)"
317+
$HERMES_VERSION=cat C:\Users\circleci\project\tmp\hermes\hermesversion
318+
echo "Hermes commit is $HERMES_VERSION"
319+
320+
with_hermes_tarball_cache_span:
321+
parameters:
322+
steps:
323+
type: steps
324+
set_tarball_path:
325+
type: boolean
326+
default: False
327+
flavor:
328+
default: "Debug"
329+
description: The Hermes build type. Must be one of "Debug", "Release".
330+
type: enum
331+
enum: ["Debug", "Release"]
332+
hermes_tarball_artifacts_dir:
333+
type: string
334+
default: *hermes_tarball_artifacts_dir
335+
steps:
336+
- get_react_native_version
337+
- when:
338+
condition:
339+
equal: [ << parameters.flavor >>, "Debug"]
340+
steps:
341+
- restore_cache:
342+
keys:
343+
- *hermes_tarball_debug_cache_key
344+
- when:
345+
condition:
346+
equal: [ << parameters.flavor >>, "Release"]
347+
steps:
348+
- restore_cache:
349+
keys:
350+
- *hermes_tarball_release_cache_key
351+
- when:
352+
condition: << parameters.set_tarball_path >>
353+
steps:
354+
- run:
355+
name: Set HERMES_ENGINE_TARBALL_PATH envvar if Hermes tarball is present
356+
command: |
357+
HERMES_TARBALL_ARTIFACTS_DIR=<< parameters.hermes_tarball_artifacts_dir >>
358+
if [ ! -d $HERMES_TARBALL_ARTIFACTS_DIR ]; then
359+
echo "Hermes tarball artifacts dir not present ($HERMES_TARBALL_ARTIFACTS_DIR). Build Hermes from source."
360+
exit 0
361+
fi
362+
363+
if [ ! -d ~/react-native ]; then
364+
echo "No React Native checkout found. Run `checkout` first."
365+
exit 0
366+
fi
367+
368+
TARBALL_FILENAME=$(node ~/react-native/scripts/hermes/get-tarball-name.js --buildType "<< parameters.flavor >>")
369+
TARBALL_PATH=$HERMES_TARBALL_ARTIFACTS_DIR/$TARBALL_FILENAME
370+
371+
echo "Looking for $TARBALL_FILENAME in $HERMES_TARBALL_ARTIFACTS_DIR"
372+
echo "$TARBALL_PATH"
373+
374+
if [ ! -f $TARBALL_PATH ]; then
375+
echo "Hermes tarball not present ($TARBALL_PATH). Build Hermes from source."
376+
exit 0
377+
fi
378+
379+
echo "Found Hermes tarball at $TARBALL_PATH"
380+
echo "export HERMES_ENGINE_TARBALL_PATH=$TARBALL_PATH" >> $BASH_ENV
381+
- run:
382+
name: Print Hermes version
383+
command: |
384+
HERMES_TARBALL_ARTIFACTS_DIR=<< parameters.hermes_tarball_artifacts_dir >>
385+
TARBALL_FILENAME=$(node ~/react-native/scripts/hermes/get-tarball-name.js --buildType "<< parameters.flavor >>")
386+
TARBALL_PATH=$HERMES_TARBALL_ARTIFACTS_DIR/$TARBALL_FILENAME
387+
if [[ -e $TARBALL_PATH ]]; then
388+
tar -xf $TARBALL_PATH
389+
echo 'print(HermesInternal?.getRuntimeProperties?.()["OSS Release Version"])' > test.js
390+
./destroot/bin/hermes test.js
391+
rm test.js
392+
rm -rf destroot
393+
else
394+
echo 'No Hermes tarball found.'
395+
fi
396+
- steps: << parameters.steps >>
397+
- when:
398+
condition:
399+
equal: [ << parameters.flavor >>, "Debug"]
400+
steps:
401+
- save_cache:
402+
key: *hermes_tarball_debug_cache_key
403+
paths: *hermes_tarball_cache_paths
404+
- when:
405+
condition:
406+
equal: [ << parameters.flavor >>, "Release"]
407+
steps:
408+
- save_cache:
409+
key: *hermes_tarball_release_cache_key
410+
paths: *hermes_tarball_cache_paths
411+
412+
with_hermesc_span:
413+
description: "Makes hermesc available to the provided steps, if hermesc is present."
250414
parameters:
251415
steps:
252416
type: steps
@@ -618,7 +782,12 @@ jobs:
618782
command: ./gradlew :ReactAndroid:packageReactNdkLibsForBuck -Pjobs=$BUILD_THREADS
619783
no_output_timeout: 30m
620784

621-
# Build JavaScript Bundle for instrumentation tests
785+
- store_test_results:
786+
path: ~/react-native/ReactAndroid/build/test-results
787+
788+
- store_test_results:
789+
path: ~/react-native/packages/react-native-gradle-plugin/build/test-results
790+
622791
- run:
623792
name: Build JavaScript Bundle
624793
command: node cli.js bundle --max-workers 2 --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
@@ -955,17 +1124,18 @@ jobs:
9551124
docker:
9561125
- image: debian:bullseye
9571126
resource_class: "xlarge"
958-
working_directory: /root
9591127
steps:
1128+
- checkout_code_with_cache
9601129
- run:
9611130
name: Install dependencies
9621131
command: |
9631132
apt update
9641133
apt install -y git openssh-client cmake build-essential \
965-
libreadline-dev libicu-dev zip python3
1134+
libreadline-dev libicu-dev jq zip python3
9661135
- *attach_hermes_workspace
1136+
- get_react_native_version
9671137
- restore_cache:
968-
key: v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
1138+
key: *hermes_linux_cache_key
9691139
- run:
9701140
name: Set up workspace
9711141
command: |
@@ -984,7 +1154,7 @@ jobs:
9841154
cp /tmp/hermes/build/bin/hermesc /tmp/hermes/linux64-bin/.
9851155
fi
9861156
- save_cache:
987-
key: v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
1157+
key: *hermes_linux_cache_key
9881158
paths:
9891159
- /tmp/hermes/linux64-bin/
9901160
- /tmp/hermes/hermes/destroot/
@@ -1065,7 +1235,9 @@ jobs:
10651235
- MSBUILD_DIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin'
10661236
- CMAKE_DIR: 'C:\Program Files\CMake\bin'
10671237
steps:
1238+
- checkout_code_with_cache
10681239
- *attach_hermes_workspace
1240+
- get_react_native_version_windows
10691241
- restore_cache:
10701242
key: v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tmp/hermes/hermesversion" }}
10711243
- run:

0 commit comments

Comments
 (0)
Please sign in to comment.