-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix flaky pod installs #46316
Merged
Merged
Fix flaky pod installs #46316
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0ee3bb0
Add --verbose in platformDeploy as well
roryabraham e1a1db1
Add debug info
roryabraham 7ac3e09
Add conditional for local podspecs
roryabraham 7b919de
log local podspec
roryabraham cf3221d
Create pod-install script that verifies local podspecs
roryabraham 1bc94f2
Add pod install at end of file
roryabraham f07ec0e
Remove mismatched local podspec
roryabraham f22409b
Add comment for script
roryabraham 60944f9
Remove commented out line
roryabraham a4b4f80
Remove verbose
roryabraham a206ce3
Use pod-install script in CI
roryabraham e090f86
Remove debug info step
roryabraham ff654b5
Remove unnecessary blue
roryabraham a9de250
Skip the whole thing if no Local Podspecs dir
roryabraham 5f4c971
Simplify implementation and make it a touch faster
roryabraham 48e686c
Improve comments
roryabraham 80f4a37
Merge branch 'main' into Rory-FixFlakyPodInstalls
roryabraham d85276c
Merge branch 'main' into Rory-FixFlakyPodInstalls
roryabraham 819c5ea
Update scripts/pod-install.sh
roryabraham 49ddefa
Merge branch 'main' into Rory-FixFlakyPodInstalls
roryabraham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/bash | ||
|
||
# This script ensures pod installs respect Podfile.lock as the source of truth. | ||
# Specifically, the podspecs for pods listed under the 'EXTERNAL SOURCES' key in the Podfile.lock are cached in the `ios/Pods/Local Podspecs` directory. | ||
# While caching results in significantly faster installs, if a cached podspec doesn't match the version in Podfile.lock, pod install will fail. | ||
# To prevent this, this script will find and delete any mismatched cached podspecs before running pod install | ||
|
||
# Exit immediately if any command exits with a non-zero status | ||
set -e | ||
|
||
# Go to project root | ||
START_DIR="$(pwd)" | ||
ROOT_DIR="$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)")" | ||
cd "$ROOT_DIR" || exit 1 | ||
|
||
# Cleanup and exit | ||
# param - status code | ||
function cleanupAndExit { | ||
cd "$START_DIR" || exit 1 | ||
exit "$1" | ||
} | ||
|
||
source scripts/shellUtils.sh | ||
|
||
# Check if bundle is installed | ||
if ! bundle --version > /dev/null 2>&1; then | ||
error 'bundle is not installed. Please install bundle and try again' | ||
cleanupAndExit 1 | ||
fi | ||
|
||
# Check if jq is installed | ||
if ! jq --version > /dev/null 2>&1; then | ||
error 'jq is not installed. Please install jq and try again' | ||
cleanupAndExit 1 | ||
fi | ||
|
||
# Check if yq is installed | ||
if ! yq --version > /dev/null 2>&1; then | ||
error 'yq is not installed. Please install yq and try again' | ||
cleanupAndExit 1 | ||
fi | ||
|
||
CACHED_PODSPEC_DIR='ios/Pods/Local Podspecs' | ||
if [ -d "$CACHED_PODSPEC_DIR" ]; then | ||
info "Verifying pods from Podfile.lock match local podspecs..." | ||
|
||
# Convert podfile.lock to json since yq is missing some features of jq (namely, if/else) | ||
PODFILE_LOCK_AS_JSON="$(yq -o=json ios/Podfile.lock)" | ||
|
||
# Retrieve a list of pods and their versions from Podfile.lock | ||
declare PODS_FROM_LOCKFILE | ||
if ! read_lines_into_array PODS_FROM_LOCKFILE < <(jq -r '.PODS | map (if (.|type) == "object" then keys[0] else . end) | .[]' < <(echo "$PODFILE_LOCK_AS_JSON")); then | ||
error "Error: Could not parse pod versions from Podfile.lock" | ||
cleanupAndExit 1 | ||
fi | ||
|
||
for CACHED_PODSPEC_PATH in "$CACHED_PODSPEC_DIR"/*; do | ||
if [ -f "$CACHED_PODSPEC_PATH" ]; then | ||
# The next two lines use bash parameter expansion to get just the pod name from the path | ||
# i.e: `ios/Pods/Local Podspecs/hermes-engine.podspec.json` to just `hermes-engine` | ||
# It extracts the part of the string between the last `/` and the first `.` | ||
CACHED_POD_NAME="${CACHED_PODSPEC_PATH##*/}" | ||
CACHED_POD_NAME="${CACHED_POD_NAME%%.*}" | ||
|
||
info "🫛 Verifying local pod $CACHED_POD_NAME" | ||
CACHED_POD_VERSION="$(jq -r '.version' < <(cat "$CACHED_PODSPEC_PATH"))" | ||
for POD_FROM_LOCKFILE in "${PODS_FROM_LOCKFILE[@]}"; do | ||
# Extract the pod name and version that was parsed from the lockfile. POD_FROM_LOCKFILE looks like `PodName (version)` | ||
IFS=' ' read -r POD_NAME_FROM_LOCKFILE POD_VERSION_FROM_LOCKFILE <<< "$POD_FROM_LOCKFILE" | ||
if [[ "$CACHED_POD_NAME" == "$POD_NAME_FROM_LOCKFILE" ]]; then | ||
if [[ "$POD_VERSION_FROM_LOCKFILE" != "($CACHED_POD_VERSION)" ]]; then | ||
clear_last_line | ||
info "⚠️ found mismatched pod: $CACHED_POD_NAME, removing local podspec $CACHED_PODSPEC_PATH" | ||
rm "$CACHED_PODSPEC_PATH" | ||
echo -e "\n" | ||
fi | ||
break | ||
fi | ||
done | ||
clear_last_line | ||
fi | ||
done | ||
fi | ||
|
||
cd ios || cleanupAndExit 1 | ||
bundle exec pod install | ||
|
||
# Go back to where we started | ||
cleanupAndExit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So after this script runs, will it execute like:
npm install
where it does not verify any changes against the lock file? And it will install any local changes?OR
npm ci
where it will fail if there are any changes from what the lock file says?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully understand the question.
npm ci
will automatically treatpackage-lock.json
as the source of truth, overwriting any cachednode_modules
if their version does not match.pod install
doesn't work the same way. It will throw an error if there's a cached pod with a different version fromPodfile.lock
. The goal of this PR is to write a script that works more likenpm ci
, where if there's a cached Pod that doesn't match, it's deleted and replaced by the version stored inPodfile.lock
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I did to test this was:
ios/Pods/Local Podspecs/hermes-engine.podspec.json
to not match thehermes-engine
version fromPodfile.lock
.cd ios && bundle exec pod install
and verify that it failsrm ios/Pods/Local Podspecs/hermes-engine.podspec.json
cd ios && bundle exec pod install
and verify that it passes.