react-native/.circleci/configurations/commands.yml
Riccardo Cipolleschi 479b4bb1ba Install bundler versions depending on Ruby version (#41962)
Summary:
Since yesterday evening (why it is always friday evening???) CircleCI or Gem decided to update the default bundler version that is installed with `gem bundle install`.
Therefore, CI for iOS stopped working.

This change installs bundler's versions so that they are compatible with the Ruby version.

## Changelog:

[Internal] - Fix CI for iOS installing versions of bundler that are compatible with Ruby

Pull Request resolved: https://github.com/facebook/react-native/pull/41962

Test Plan: CircleCI is green

Reviewed By: GijsWeterings

Differential Revision: D52230544

Pulled By: cipolleschi

fbshipit-source-id: 2f96e16ecb94159953056e8de757ea4d249f80f0
2023-12-16 08:50:20 -08:00

577 lines
20 KiB
YAML

# -------------------------
# COMMANDS
# -------------------------
commands:
# Checkout with cache, on machines that are using Docker the cache is ignored
checkout_code_with_cache:
parameters:
checkout_base_cache_key:
default: *checkout_cache_key
type: string
steps:
- restore_cache:
key: << parameters.checkout_base_cache_key >>-{{ arch }}-{{ .Branch }}-{{ .Revision }}
- checkout
- save_cache:
key: << parameters.checkout_base_cache_key >>-{{ arch }}-{{ .Branch }}-{{ .Revision }}
paths:
- ".git"
setup_ruby:
parameters:
ruby_version:
default: "2.6.10"
type: string
steps:
- restore_cache:
key: *gems_cache_key
- run:
name: Set Required Ruby
command: echo << parameters.ruby_version >> > /tmp/required_ruby
- restore_cache:
key: *rbenv_cache_key
- run:
name: Bundle Install
command: |
# Check if rbenv is installed. CircleCI is migrating to rbenv so we may not need to always install it.
if [[ -z "$(command -v rbenv)" ]]; then
brew install rbenv ruby-build
# Load and init rbenv
(rbenv init 2> /dev/null) || true
echo '' >> ~/.bash_profile
echo 'eval "$(rbenv init - bash)"' >> ~/.bash_profile
source ~/.bash_profile
else
echo "rbenv found; Skipping installation"
fi
# Install the right version of ruby
if [[ -z "$(rbenv versions | grep << parameters.ruby_version >>)" ]]; then
# ensure that `ruby-build` can see all the available versions of Ruby
# some PRs received machines in a weird state, this should make the pipelines
# more robust.
brew update && brew upgrade ruby-build
rbenv install << parameters.ruby_version >>
fi
# Set ruby dependencies
rbenv global << parameters.ruby_version >>
if [[ << parameters.ruby_version >> == "2.6.10" ]]; then
gem install bundler -v 2.4.22
else
gem install bundler
fi
bundle check || bundle install --path vendor/bundle --clean
- save_cache:
key: *rbenv_cache_key
paths:
- ~/.rbenv
- save_cache:
key: *gems_cache_key
paths:
- vendor/bundle
run_yarn:
parameters:
yarn_base_cache_key:
default: *yarn_cache_key
type: string
steps:
- restore_cache:
keys:
- << parameters.yarn_base_cache_key >>-{{ arch }}-{{ checksum "yarn.lock" }}
- << parameters.yarn_base_cache_key >>-{{ arch }}
- << parameters.yarn_base_cache_key >>
- run:
name: "Yarn: Install Dependencies"
command: |
# Skip yarn install on metro bump commits as the package is not yet
# available on npm
if [[ $(echo "$GIT_COMMIT_DESC" | grep -c "Bump metro@") -eq 0 ]]; then
yarn install --non-interactive --cache-folder ~/.cache/yarn
fi
- save_cache:
paths:
- ~/.cache/yarn
key: << parameters.yarn_base_cache_key >>-{{ arch }}-{{ checksum "yarn.lock" }}
build_packages:
steps:
- run:
name: Build packages
command: yarn build
brew_install:
parameters:
package:
description: Homebrew package to install
type: string
steps:
- run:
name: "Brew: Install << parameters.package >>"
command: brew install << parameters.package >>
with_rntester_pods_cache_span:
parameters:
steps:
type: steps
steps:
- run:
name: Setup CocoaPods cache
# Copy packages/rn-tester/Podfile.lock since it can be changed by pod install
command: cp packages/rn-tester/Podfile.lock packages/rn-tester/Podfile.lock.bak
- restore_cache:
keys:
# The committed lockfile is generated using static libraries and USE_HERMES=1 so it could load an outdated cache if a change
# only affects the frameworks or hermes config. To help prevent this also cache based on the content of Podfile.
- *pods_cache_key
- steps: << parameters.steps >>
- save_cache:
paths:
- packages/rn-tester/Pods
key: *pods_cache_key
with_gradle_cache:
parameters:
steps:
type: steps
steps:
- restore_cache:
keys:
- *gradle_cache_key
- v3-gradle-{{ .Environment.CIRCLE_JOB }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-
- v3-gradle-{{ .Environment.CIRCLE_JOB }}-
- v3-gradle-
- steps: << parameters.steps >>
- save_cache:
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper
- packages/react-native/ReactAndroid/build/downloads
- packages/react-native/ReactAndroid/build/third-party-ndk
key: *gradle_cache_key
run_e2e:
parameters:
platform:
description: Target platform
type: enum
enum: ["android", "ios", "js"]
default: "js"
retries:
description: How many times the job should try to run these tests
type: integer
default: 3
steps:
- run:
name: "Run Tests: << parameters.platform >> End-to-End Tests"
command: node ./scripts/run-ci-e2e-tests.js --<< parameters.platform >> --retries << parameters.retries >>
report_bundle_size:
parameters:
platform:
description: Target platform
type: enum
enum: ["android", "ios"]
steps:
- run:
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
setup_hermes_version:
steps:
- run:
name: Set up Hermes workspace and caching
command: |
mkdir -p "/tmp/hermes" "/tmp/hermes/download" "/tmp/hermes/hermes"
if [ -f "$HERMES_VERSION_FILE" ]; then
echo "Hermes Version file found! Using this version for the build:"
cat $HERMES_VERSION_FILE > /tmp/hermes/hermesversion
else
echo "Hermes Version file not found!!!"
echo "Using the last commit from main for the build:"
HERMES_TAG_SHA=$(git ls-remote https://github.com/facebook/hermes main | cut -f 1 | tr -d '[:space:]')
echo $HERMES_TAG_SHA > /tmp/hermes/hermesversion
fi
cat /tmp/hermes/hermesversion
get_react_native_version:
steps:
- run:
name: Get React Native version
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 /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
set_tarball_path:
type: boolean
default: False
flavor:
default: "Debug"
description: The Hermes build type. Must be one of "Debug", "Release".
type: enum
enum: ["Debug", "Release"]
hermes_tarball_artifacts_dir:
type: string
default: *hermes_tarball_artifacts_dir
steps:
- get_react_native_version
- when:
condition:
equal: [ << parameters.flavor >>, "Debug"]
steps:
- restore_cache:
keys:
- *hermes_tarball_debug_cache_key
- when:
condition:
equal: [ << parameters.flavor >>, "Release"]
steps:
- restore_cache:
keys:
- *hermes_tarball_release_cache_key
- when:
condition: << parameters.set_tarball_path >>
steps:
- run:
name: Set HERMES_ENGINE_TARBALL_PATH envvar if Hermes tarball is present
command: |
HERMES_TARBALL_ARTIFACTS_DIR=<< parameters.hermes_tarball_artifacts_dir >>
if [ ! -d $HERMES_TARBALL_ARTIFACTS_DIR ]; then
echo "Hermes tarball artifacts dir not present ($HERMES_TARBALL_ARTIFACTS_DIR). Build Hermes from source."
exit 0
fi
if [ ! -d ~/react-native ]; then
echo "No React Native checkout found. Run `checkout` first."
exit 0
fi
TARBALL_FILENAME=$(node ~/react-native/packages/react-native/scripts/hermes/get-tarball-name.js --buildType "<< parameters.flavor >>")
TARBALL_PATH=$HERMES_TARBALL_ARTIFACTS_DIR/$TARBALL_FILENAME
echo "Looking for $TARBALL_FILENAME in $HERMES_TARBALL_ARTIFACTS_DIR"
echo "$TARBALL_PATH"
if [ ! -f $TARBALL_PATH ]; then
echo "Hermes tarball not present ($TARBALL_PATH). Build Hermes from source."
exit 0
fi
echo "Found Hermes tarball at $TARBALL_PATH"
echo "export HERMES_ENGINE_TARBALL_PATH=$TARBALL_PATH" >> $BASH_ENV
- run:
name: Print Hermes version
command: |
HERMES_TARBALL_ARTIFACTS_DIR=<< parameters.hermes_tarball_artifacts_dir >>
TARBALL_FILENAME=$(node ~/react-native/packages/react-native/scripts/hermes/get-tarball-name.js --buildType "<< parameters.flavor >>")
TARBALL_PATH=$HERMES_TARBALL_ARTIFACTS_DIR/$TARBALL_FILENAME
if [[ -e $TARBALL_PATH ]]; then
tar -xf $TARBALL_PATH
echo 'print(HermesInternal?.getRuntimeProperties?.()["OSS Release Version"])' > test.js
./destroot/bin/hermes test.js
rm test.js
rm -rf destroot
else
echo 'No Hermes tarball found.'
fi
- steps: << parameters.steps >>
- when:
condition:
equal: [ << parameters.flavor >>, "Debug"]
steps:
- save_cache:
key: *hermes_tarball_debug_cache_key
paths: *hermes_tarball_cache_paths
- when:
condition:
equal: [ << parameters.flavor >>, "Release"]
steps:
- save_cache:
key: *hermes_tarball_release_cache_key
paths: *hermes_tarball_cache_paths
store_hermes_apple_artifacts:
description: Stores the tarball and the osx binaries
parameters:
flavor:
default: "Debug"
description: The Hermes build type. Must be one of "Debug", "Release".
type: enum
enum: ["Debug", "Release"]
steps:
- when:
condition:
equal: [ << parameters.flavor >>, "Debug"]
steps:
- store_artifacts:
path: /tmp/hermes/hermes-runtime-darwin/hermes-ios-debug.tar.gz
- when:
condition:
equal: [ << parameters.flavor >>, "Release"]
steps:
- store_artifacts:
path: /tmp/hermes/hermes-runtime-darwin/hermes-ios-release.tar.gz
- store_artifacts:
path: /tmp/hermes/osx-bin/<< parameters.flavor >>/hermesc
- store_artifacts:
path: /tmp/hermes/dSYM/<< parameters.flavor >>/hermes.framework.dSYM
stop_job_if_apple_artifacts_are_there:
description: Stops the current job if there are already the required artifacts
parameters:
flavor:
default: "All"
description: The flavor of artifacts to check. Must be one of "Debug", "Release" or "All"
type: enum
enum: ["Debug", "Release", "All"]
steps:
- when:
condition:
equal: [ << parameters.flavor >>, "All"]
steps:
- run:
name: "Export files to be checked"
command: |
echo "/tmp/hermes/Release_tarball_present" > /tmp/hermes_files
echo "/tmp/hermes/Debug_tarball_present" >> /tmp/hermes_files
echo "/tmp/hermes/Release_osx_bin" >> /tmp/hermes_files
echo "/tmp/hermes/Debug_osx_bin" >> /tmp/hermes_files
echo "/tmp/hermes/Release_dSYM" >> /tmp/hermes_files
echo "/tmp/hermes/Debug_dSYM" >> /tmp/hermes_files
- when:
condition:
not:
equal: [ << parameters.flavor >>, "All"]
steps:
- run:
name: "Export files to be checked"
command: |
echo "/tmp/hermes/<< parameters.flavor >>_tarball_present" > /tmp/hermes_files
echo "/tmp/hermes/<< parameters.flavor >>_osx_bin" >> /tmp/hermes_files
echo "/tmp/hermes/<< parameters.flavor >>_dSYM" >> /tmp/hermes_files
- run:
name: Stop if files are present
command: |
files=($(cat /tmp/hermes_files))
# Initialize a flag indicating all files exist
all_files_exist=true
for file in "${files[@]}"; do
if [[ ! -f "$file" ]]; then
all_files_exist=false
echo "$file does not exist."
else
echo "$file exist."
fi
done
if [[ "$all_files_exist" == true ]]; then
echo "Tarball, osx-bin and dSYM are present. Halting this job"
circleci-agent step halt
fi
check_if_tarball_is_present:
description: "Checks if the tarball of a specific Flavor is present and adds a marker file"
parameters:
flavor:
default: "Debug"
description: The flavor of artifacts to check. Must be one of "Debug" or "Release"
type: enum
enum: ["Debug", "Release"]
steps:
- run:
name: Check if << parameters.flavor >> tarball is there
command: |
FLAVOR=debug
if [[ << parameters.flavor >> == "Release" ]]; then
FLAVOR=release
fi
if [[ -f "/tmp/hermes/hermes-runtime-darwin/hermes-ios-$FLAVOR.tar.gz" ]]; then
echo "[HERMES TARBALL] Found the << parameters.flavor >> tarball"
touch /tmp/hermes/<< parameters.flavor >>_tarball_present
fi
check_if_osx_bin_is_present:
description: "Checks if the osx bin of a specific Flavor is present and adds a marker file"
parameters:
flavor:
default: "Debug"
description: The flavor of artifacts to check. Must be one of "Debug" or "Release"
type: enum
enum: ["Debug", "Release"]
steps:
- run:
name: Check if macosx binary is there
command: |
if [[ -d /tmp/hermes/osx-bin/<< parameters.flavor >> ]]; then
echo "[HERMES MACOSX BIN] Found the osx bin << parameters.flavor >>"
touch /tmp/hermes/<< parameters.flavor >>_osx_bin
fi
check_if_dsym_are_present:
description: "Checks if the dSYM a specific Flavor are present and adds a marker file"
parameters:
flavor:
default: "Debug"
description: The flavor of artifacts to check. Must be one of "Debug" or "Release"
type: enum
enum: ["Debug", "Release"]
steps:
- run:
name: Check if dSYM are there
command: |
if [[ -d /tmp/hermes/dSYM/<< parameters.flavor >> ]]; then
echo "[HERMES dSYM] Found the dSYM << parameters.flavor >>"
touch /tmp/hermes/<< parameters.flavor >>_dSYM
fi
setup_hermes_workspace:
description: "Setup Hermes Workspace"
steps:
- run:
name: Set up workspace
command: |
mkdir -p $HERMES_OSXBIN_ARTIFACTS_DIR ./packages/react-native/sdks/hermes
cp -r $HERMES_WS_DIR/hermes/* ./packages/react-native/sdks/hermes/.
cp -r ./packages/react-native/sdks/hermes-engine/utils ./packages/react-native/sdks/hermes/.
with_xcodebuild_cache:
description: "Add caching to iOS jobs to speed up builds"
parameters:
steps:
type: steps
podfile_lock_path:
type: string
default: packages/rn-tester/Podfile.lock
pods_build_folder:
type: string
default: packages/rn-tester/Pods
podfile_lock_cache_key:
type: string
default: *rntester_podfile_lock_cache_key
cocoapods_cache_key:
type: string
default: *cocoapods_cache_key
steps:
- run:
name: Prepare Xcodebuild cache
command: |
WEEK=$(date +"%U")
YEAR=$(date +"%Y")
echo "$WEEK-$YEAR" > /tmp/week_year
- restore_cache:
key: << parameters.podfile_lock_cache_key >>
- restore_cache:
key: << parameters.cocoapods_cache_key >>
- steps: << parameters.steps >>
- save_cache:
key: << parameters.podfile_lock_cache_key >>
paths:
- << parameters.podfile_lock_path >>
- save_cache:
key: << parameters.cocoapods_cache_key >>
paths:
- << parameters.pods_build_folder >>
store_artifacts_if_needed:
description: "This step stores the artifacts only if we are on main or on a stable branch"
parameters:
path:
type: string
destination:
type: string
default: << parameters.path >>
when:
type: enum
enum: ['always', 'on_fail', 'on_success']
default: 'always'
steps:
- when:
condition:
or:
- equal: [ main, << pipeline.git.branch >> ]
- matches:
pattern: /0\.[0-9]+[\.[0-9]+]?-stable/
value: << pipeline.git.branch >>
steps:
- store_artifacts:
when: << parameters.when >>
path: << parameters.path >>
destination: << parameters.destination >>
prepare_ios_tests:
description: This command runs a set of commands to prepare iOS for running unit tests
steps:
- brew_install:
package: xcbeautify
- run:
name: Run Ruby Tests
command: |
cd packages/react-native/scripts
sh run_ruby_tests.sh
- run:
name: Boot iPhone Simulator
command: source scripts/.tests.env && xcrun simctl boot "$IOS_DEVICE" || true
- run:
name: Configure Environment Variables
command: |
echo 'export PATH=/usr/local/opt/node@18/bin:$PATH' >> $BASH_ENV
source $BASH_ENV
- run:
name: "Brew: Tap wix/brew"
command: brew tap wix/brew
- brew_install:
package: applesimutils watchman
- run:
name: Configure Watchman
command: echo "{}" > .watchmanconfig
run_ios_tests:
description: This command run iOS tests and collects results
steps:
- run:
name: "Run Tests: iOS Unit and Integration Tests"
command: node ./scripts/circleci/run_with_retry.js 3 yarn test-ios
- run:
name: Zip Derived data folder
when: always
command: |
echo "zipping tests results"
cd /Users/distiller/Library/Developer/Xcode
XCRESULT_PATH=$(find . -name '*.xcresult')
tar -zcvf xcresults.tar.gz $XCRESULT_PATH
- store_artifacts_if_needed:
path: /Users/distiller/Library/Developer/Xcode/xcresults.tar.gz
- report_bundle_size:
platform: ios
- store_test_results:
path: ./reports/junit