From 40e8bb9a43109121673cba16310bacfcd73f1551 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 23 May 2023 03:34:20 -0700 Subject: [PATCH] Make CircleCI caches for hermesc be version dependent (#37452) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- .circleci/config.yml | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e94c7134da82e2..4410f338ff285e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,10 +51,14 @@ references: checkout_cache_key: &checkout_cache_key v2-checkout gems_cache_key: &gems_cache_key v1-gems-{{ checksum "Gemfile.lock" }} gradle_cache_key: &gradle_cache_key v1-gradle-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "ReactAndroid/gradle.properties" }} - hermes_cache_key: &hermes_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }} - hermes_sdk_cache_key: &hermes_sdk_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "sdks/.hermes-cache-key-file" }} - hermes_windows_cache_key: &hermes_windows_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tmp/hermes/hermesversion" }} - pods_cache_key: &pods_cache_key v6-pods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock.bak" }}-{{ checksum "packages/rn-tester/Podfile" }} + hermes_workspace_cache_key: &hermes_workspace_cache_key v4-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }} + 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" }} + 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" }} + hermes_linux_cache_key: &hermes_linux_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-linux-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }} + 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" }} + hermes_tarball_debug_cache_key: &hermes_tarball_debug_cache_key v4-hermes-tarball-debug-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }} + hermes_tarball_release_cache_key: &hermes_tarball_release_cache_key v3-hermes-tarball-release-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }} + pods_cache_key: &pods_cache_key v8-pods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock.bak" }}-{{ checksum "packages/rn-tester/Podfile" }} windows_yarn_cache_key: &windows_yarn_cache_key v1-win-yarn-cache-{{ arch }}-{{ checksum "yarn.lock" }} yarn_cache_key: &yarn_cache_key v5-yarn-cache-{{ .Environment.CIRCLE_JOB }} @@ -281,7 +285,31 @@ commands: name: Report size of RNTester.app (analysis-bot) command: GITHUB_TOKEN="$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A""$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B" scripts/circleci/report-bundle-size.sh << parameters.platform >> || true - with_hermes_sdk_cache_span: + get_react_native_version: + steps: + - run: + name: Get React Native version + command: | + VERSION=$(cat package.json | jq -r '.version') + # Save the react native version we are building in a file so we can use that file as part of the cache key. + echo "$VERSION" > /tmp/react-native-version + echo "React Native Version is $(cat /tmp/react-native-version)" + HERMES_VERSION="$(cat /tmp/hermes/hermesversion)" + echo "Hermes commit is $HERMES_VERSION" + + get_react_native_version_windows: + steps: + - run: + name: Get React Native version on Windows + command: | + $VERSION=cat packages/react-native/package.json | jq -r '.version' + # Save the react native version we are building in a file so we can use that file as part of the cache key. + echo "$VERSION" > /tmp/react-native-version + echo "React Native Version is $(cat /tmp/react-native-version)" + $HERMES_VERSION=cat C:\Users\circleci\project\tmp\hermes\hermesversion + echo "Hermes commit is $HERMES_VERSION" + + with_hermes_tarball_cache_span: parameters: steps: type: steps @@ -917,17 +945,18 @@ jobs: docker: - image: debian:bullseye resource_class: "xlarge" - working_directory: /root steps: + - checkout_code_with_cache - run: name: Install dependencies command: | apt update apt install -y git openssh-client cmake build-essential \ - libreadline-dev libicu-dev zip python3 + libreadline-dev libicu-dev jq zip python3 - *attach_hermes_workspace + - get_react_native_version - restore_cache: - key: *hermes_cache_key + key: *hermes_linux_cache_key - run: name: Set up workspace command: | @@ -946,7 +975,7 @@ jobs: cp /tmp/hermes/build/bin/hermesc /tmp/hermes/linux64-bin/. fi - save_cache: - key: *hermes_cache_key + key: *hermes_linux_cache_key paths: - /tmp/hermes/linux64-bin/ - /tmp/hermes/hermes/destroot/ @@ -1032,7 +1061,9 @@ jobs: - MSBUILD_DIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin' - CMAKE_DIR: 'C:\Program Files\CMake\bin' steps: + - checkout_code_with_cache - *attach_hermes_workspace + - get_react_native_version_windows - restore_cache: key: *hermes_windows_cache_key - run: