Skip to content

Commit

Permalink
Create pod-install script that verifies local podspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham committed Jul 27, 2024
1 parent 7b919de commit cf3221d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/verifyPodfile.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

START_DIR=$(pwd)
ROOT_DIR=$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")
cd "$ROOT_DIR" || exit 1
Expand Down Expand Up @@ -61,6 +63,7 @@ if ! SPEC_DIRS=$(yq '.["EXTERNAL SOURCES"].[].":path" | select( . == "*node_modu
cleanupAndExit 1
fi

# Retrieve a list of podspec paths from react-native config
if ! read_lines_into_array PODSPEC_PATHS < <(npx react-native config | jq --raw-output '.dependencies[].platforms.ios.podspecPath | select ( . != null)'); then
error "Error: could not parse podspec paths from react-native config command"
cleanupAndExit 1
Expand Down
71 changes: 71 additions & 0 deletions scripts/pod-install.sh
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
6 changes: 6 additions & 0 deletions scripts/shellUtils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ function title {
printf "\n%s%s%s\n" "$TITLE" "$1" "$RESET"
}

# Function to clear the last printed line
clear_last_line() {
# echo -ne "\r\033[K"
echo -ne "\033[1A\033[K"
}

function assert_equal {
if [[ "$1" != "$2" ]]; then
error "Assertion failed: $1 is not equal to $2"
Expand Down

0 comments on commit cf3221d

Please sign in to comment.