forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create pod-install script that verifies local podspecs
- Loading branch information
1 parent
7b919de
commit cf3221d
Showing
3 changed files
with
80 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/bin/bash | ||
|
||
# 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 | ||
|
||
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 EXTERNAL_SOURCE_POD in $(jq -cr '."EXTERNAL SOURCES" | keys | .[]' < <(echo "$PODFILE_LOCK_AS_JSON")); do | ||
LOCAL_PODSPEC_PATH="ios/Pods/Local Podspecs/$EXTERNAL_SOURCE_POD.podspec.json" | ||
if [ -f "$LOCAL_PODSPEC_PATH" ]; then | ||
echo -e "\r$BLUE 🫛 Verifying local pod $EXTERNAL_SOURCE_POD" | ||
POD_VERSION_FROM_LOCAL_PODSPECS="$(jq -r '.version' < <(cat "$LOCAL_PODSPEC_PATH"))" | ||
for POD_FROM_LOCKFILE in "${PODS_FROM_LOCKFILE[@]}"; do | ||
IFS=' ' read -r POD_NAME_FROM_LOCKFILE POD_VERSION_FROM_LOCKFILE <<< "$POD_FROM_LOCKFILE" | ||
if [[ "$EXTERNAL_SOURCE_POD" == "$POD_NAME_FROM_LOCKFILE" ]]; then | ||
if [[ "$POD_VERSION_FROM_LOCKFILE" != "($POD_VERSION_FROM_LOCAL_PODSPECS)" ]]; then | ||
clear_last_line | ||
info "⚠️ found mismatched pod: $EXTERNAL_SOURCE_POD, removing local podspec $LOCAL_PODSPEC_PATH" | ||
echo -e "\n" | ||
fi | ||
break | ||
fi | ||
done | ||
clear_last_line | ||
fi | ||
done | ||
|
||
# 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