From 0ee3bb0999d23dc99d4f3f7afe4b86517acb9d69 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 09:34:26 -0700 Subject: [PATCH 01/17] Add --verbose in platformDeploy as well --- .github/workflows/platformDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index f2fda2bc56ff..a58cc48ec24e 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -221,7 +221,7 @@ jobs: with: timeout_minutes: 10 max_attempts: 5 - command: cd ios && bundle exec pod install + command: cd ios && bundle exec pod install --verbose - name: Decrypt AppStore profile run: cd ios && gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output NewApp_AppStore.mobileprovision NewApp_AppStore.mobileprovision.gpg From e1a1db1d6c52f88864cee77ef5a7c74e386cf7b0 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 09:49:36 -0700 Subject: [PATCH 02/17] Add debug info --- .github/workflows/testBuild.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index 1abe22dc395d..c0914a64ef75 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -179,6 +179,20 @@ jobs: id: compare-podfile-and-manifest run: echo "IS_PODFILE_SAME_AS_MANIFEST=${{ hashFiles('ios/Podfile.lock') == hashFiles('ios/Pods/Manifest.lock') }}" >> "$GITHUB_OUTPUT" + - name: Add debug info + run: | + echo "RORY_DEBUG Podfile" + cat ios/Podfile + echo "" + echo "RORY_DEBUG Podfile.lock" + cat ios/Podfile.lock + echo "" + echo "RORY_DEBUG Hermes podspec from node_modules" + cat node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec + echo "" + echo "RORY_DEBUG local podspecs" + ls 'ios/Pods/Local Podspecs' + - name: Install cocoapods uses: nick-invision/retry@0711ba3d7808574133d713a0d92d2941be03a350 if: steps.pods-cache.outputs.cache-hit != 'true' || steps.compare-podfile-and-manifest.outputs.IS_PODFILE_SAME_AS_MANIFEST != 'true' || steps.setup-node.outputs.cache-hit != 'true' From 7ac3e09fdc2a65e2b310e6a4a6c5604f741dad2d Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 10:04:45 -0700 Subject: [PATCH 03/17] Add conditional for local podspecs --- .github/workflows/testBuild.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index c0914a64ef75..0e4680c128c4 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -184,14 +184,19 @@ jobs: echo "RORY_DEBUG Podfile" cat ios/Podfile echo "" + echo "" echo "RORY_DEBUG Podfile.lock" cat ios/Podfile.lock echo "" echo "RORY_DEBUG Hermes podspec from node_modules" cat node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec echo "" - echo "RORY_DEBUG local podspecs" - ls 'ios/Pods/Local Podspecs' + if [ -d 'ios/Pods/Local Podspecs' ]; then + echo "RORY_DEBUG local podspecs" + ls 'ios/Pods/Local Podspecs' + echo "" + echo "" + fi - name: Install cocoapods uses: nick-invision/retry@0711ba3d7808574133d713a0d92d2941be03a350 From 7b919def009de0df4414932de7dd088c8adac0da Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 11:00:11 -0700 Subject: [PATCH 04/17] log local podspec --- .github/workflows/testBuild.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index 0e4680c128c4..3f7c9ce78c96 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -191,9 +191,9 @@ jobs: echo "RORY_DEBUG Hermes podspec from node_modules" cat node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec echo "" - if [ -d 'ios/Pods/Local Podspecs' ]; then - echo "RORY_DEBUG local podspecs" - ls 'ios/Pods/Local Podspecs' + if [ -f 'ios/Pods/Local Podspecs/hermes-engine.podspec.json' ]; then + echo "RORY_DEBUG local podspec" + cat 'ios/Pods/Local Podspecs/hermes-engine.podspec.json' echo "" echo "" fi From cf3221dd4b617c002f4e720026a7ab913343cd2e Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 18:21:49 -0700 Subject: [PATCH 05/17] Create pod-install script that verifies local podspecs --- .github/scripts/verifyPodfile.sh | 3 ++ scripts/pod-install.sh | 71 ++++++++++++++++++++++++++++++++ scripts/shellUtils.sh | 6 +++ 3 files changed, 80 insertions(+) create mode 100755 scripts/pod-install.sh diff --git a/.github/scripts/verifyPodfile.sh b/.github/scripts/verifyPodfile.sh index f4b1c5521733..ff67b11c8657 100755 --- a/.github/scripts/verifyPodfile.sh +++ b/.github/scripts/verifyPodfile.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + START_DIR=$(pwd) ROOT_DIR=$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")") cd "$ROOT_DIR" || exit 1 @@ -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 diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh new file mode 100755 index 000000000000..3dd2f5f0c903 --- /dev/null +++ b/scripts/pod-install.sh @@ -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 diff --git a/scripts/shellUtils.sh b/scripts/shellUtils.sh index fa44f2ee7d3a..0b28fccae5fb 100644 --- a/scripts/shellUtils.sh +++ b/scripts/shellUtils.sh @@ -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" From 1bc94f2d52ce4d1c097b60e1669aab6207fffbfa Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 21:14:46 -0700 Subject: [PATCH 06/17] Add pod install at end of file --- scripts/pod-install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index 3dd2f5f0c903..9084d4b72df3 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -67,5 +67,7 @@ for EXTERNAL_SOURCE_POD in $(jq -cr '."EXTERNAL SOURCES" | keys | .[]' < <(echo fi done +bundle exec pod install --verbose + # Go back to where we started cleanupAndExit 0 From f07ec0ed0a87f96c1710f6eda6657b17aa8e0fcf Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 21:18:27 -0700 Subject: [PATCH 07/17] Remove mismatched local podspec --- scripts/pod-install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index 9084d4b72df3..f4b37fe24739 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -50,7 +50,7 @@ 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" + info "$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" @@ -58,6 +58,7 @@ for EXTERNAL_SOURCE_POD in $(jq -cr '."EXTERNAL SOURCES" | keys | .[]' < <(echo 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" + rm "$LOCAL_PODSPEC_PATH" echo -e "\n" fi break @@ -67,6 +68,7 @@ for EXTERNAL_SOURCE_POD in $(jq -cr '."EXTERNAL SOURCES" | keys | .[]' < <(echo fi done +cd ios || cleanupAndExit 1 bundle exec pod install --verbose # Go back to where we started From f22409b03c760a85758a540c7766855a74830e47 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 22:01:57 -0700 Subject: [PATCH 08/17] Add comment for script --- scripts/pod-install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index f4b37fe24739..2dfa411d7066 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -1,5 +1,10 @@ #!/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 deleted any mismatched cached podspecs before running pod install + # Exit immediately if any command exits with a non-zero status set -e From 60944f9a063776818339b0efda4423be97d9dd66 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 22:46:50 -0700 Subject: [PATCH 09/17] Remove commented out line --- scripts/shellUtils.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/shellUtils.sh b/scripts/shellUtils.sh index 0b28fccae5fb..c1ceace09d0a 100644 --- a/scripts/shellUtils.sh +++ b/scripts/shellUtils.sh @@ -43,7 +43,6 @@ function title { # Function to clear the last printed line clear_last_line() { -# echo -ne "\r\033[K" echo -ne "\033[1A\033[K" } From a4b4f800b70b3e50faf6a6a906d1a1fbce5054ec Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 23:07:21 -0700 Subject: [PATCH 10/17] Remove verbose --- scripts/pod-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index 2dfa411d7066..c3f7916927a8 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -74,7 +74,7 @@ for EXTERNAL_SOURCE_POD in $(jq -cr '."EXTERNAL SOURCES" | keys | .[]' < <(echo done cd ios || cleanupAndExit 1 -bundle exec pod install --verbose +bundle exec pod install # Go back to where we started cleanupAndExit 0 From a206ce3186e1929ffb2e4a21f94cc8a640ff8fc1 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 23:09:41 -0700 Subject: [PATCH 11/17] Use pod-install script in CI --- .github/workflows/platformDeploy.yml | 2 +- .github/workflows/testBuild.yml | 2 +- package.json | 2 +- workflow_tests/assertions/platformDeployAssertions.ts | 2 +- workflow_tests/assertions/testBuildAssertions.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index a58cc48ec24e..261a0d914d47 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -221,7 +221,7 @@ jobs: with: timeout_minutes: 10 max_attempts: 5 - command: cd ios && bundle exec pod install --verbose + command: scripts/pod-install.sh - name: Decrypt AppStore profile run: cd ios && gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output NewApp_AppStore.mobileprovision NewApp_AppStore.mobileprovision.gpg diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index 3f7c9ce78c96..3580236d5128 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -204,7 +204,7 @@ jobs: with: timeout_minutes: 10 max_attempts: 5 - command: cd ios && bundle exec pod install --verbose + command: scripts/pod-install.sh - name: Decrypt AdHoc profile run: cd ios && gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output NewApp_AdHoc.mobileprovision NewApp_AdHoc.mobileprovision.gpg diff --git a/package.json b/package.json index c320c88f4ef4..4066b03624a5 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "clean": "npx react-native clean-project-auto", "android": "scripts/set-pusher-suffix.sh && npx react-native run-android --mode=developmentDebug --appId=com.expensify.chat.dev --active-arch-only", "ios": "scripts/set-pusher-suffix.sh && npx react-native run-ios --list-devices --mode=\"DebugDevelopment\" --scheme=\"New Expensify Dev\"", - "pod-install": "cd ios && bundle exec pod install", + "pod-install": "scripts/pod-install.sh", "ipad": "concurrently \"npx react-native run-ios --simulator=\\\"iPad Pro (12.9-inch) (6th generation)\\\" --mode=\\\"DebugDevelopment\\\" --scheme=\\\"New Expensify Dev\\\"\"", "ipad-sm": "concurrently \"npx react-native run-ios --simulator=\\\"iPad Pro (11-inch) (4th generation)\\\" --mode=\\\"DebugDevelopment\\\" --scheme=\\\"New Expensify Dev\\\"\"", "start": "npx react-native start", diff --git a/workflow_tests/assertions/platformDeployAssertions.ts b/workflow_tests/assertions/platformDeployAssertions.ts index af80e9f2beb3..e9d8e9bd899b 100644 --- a/workflow_tests/assertions/platformDeployAssertions.ts +++ b/workflow_tests/assertions/platformDeployAssertions.ts @@ -160,7 +160,7 @@ function assertIOSJobExecuted(workflowResult: Step[], didExecute = true, isProdu createStepAssertion('Install cocoapods', true, null, 'IOS', 'Installing cocoapods', [ {key: 'timeout_minutes', value: '10'}, {key: 'max_attempts', value: '5'}, - {key: 'command', value: 'cd ios && bundle exec pod install'}, + {key: 'command', value: 'scripts/pod-install.sh'}, ]), createStepAssertion('Decrypt AppStore profile', true, null, 'IOS', 'Decrypting profile', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), createStepAssertion('Decrypt AppStore Notification Service profile', true, null, 'IOS', 'Decrypting profile', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), diff --git a/workflow_tests/assertions/testBuildAssertions.ts b/workflow_tests/assertions/testBuildAssertions.ts index 72b36e47639a..37da3181c5b7 100644 --- a/workflow_tests/assertions/testBuildAssertions.ts +++ b/workflow_tests/assertions/testBuildAssertions.ts @@ -170,7 +170,7 @@ function assertIOSJobExecuted(workflowResult: Step[], ref = '', didExecute = tru [ {key: 'timeout_minutes', value: '10'}, {key: 'max_attempts', value: '5'}, - {key: 'command', value: 'cd ios && bundle exec pod install --verbose'}, + {key: 'command', value: 'scripts/pod-install.sh'}, ], [], ), From e090f86173fd96540fea8bff8a16517dd56a4750 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 23:25:23 -0700 Subject: [PATCH 12/17] Remove debug info step --- .github/workflows/testBuild.yml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index 3580236d5128..444f40ee7129 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -179,25 +179,6 @@ jobs: id: compare-podfile-and-manifest run: echo "IS_PODFILE_SAME_AS_MANIFEST=${{ hashFiles('ios/Podfile.lock') == hashFiles('ios/Pods/Manifest.lock') }}" >> "$GITHUB_OUTPUT" - - name: Add debug info - run: | - echo "RORY_DEBUG Podfile" - cat ios/Podfile - echo "" - echo "" - echo "RORY_DEBUG Podfile.lock" - cat ios/Podfile.lock - echo "" - echo "RORY_DEBUG Hermes podspec from node_modules" - cat node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec - echo "" - if [ -f 'ios/Pods/Local Podspecs/hermes-engine.podspec.json' ]; then - echo "RORY_DEBUG local podspec" - cat 'ios/Pods/Local Podspecs/hermes-engine.podspec.json' - echo "" - echo "" - fi - - name: Install cocoapods uses: nick-invision/retry@0711ba3d7808574133d713a0d92d2941be03a350 if: steps.pods-cache.outputs.cache-hit != 'true' || steps.compare-podfile-and-manifest.outputs.IS_PODFILE_SAME_AS_MANIFEST != 'true' || steps.setup-node.outputs.cache-hit != 'true' From ff654b555a9a828ab964557ffc19695c31b87342 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 26 Jul 2024 23:44:34 -0700 Subject: [PATCH 13/17] Remove unnecessary blue --- scripts/pod-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index c3f7916927a8..406e74d72873 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -55,7 +55,7 @@ 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 - info "$BLUE 🫛 Verifying local pod $EXTERNAL_SOURCE_POD" + info "🫛 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" From a9de25038fd615bfa07ed948ab29b5005c225b8d Mon Sep 17 00:00:00 2001 From: rory Date: Sat, 27 Jul 2024 09:41:44 -0700 Subject: [PATCH 14/17] Skip the whole thing if no Local Podspecs dir --- scripts/pod-install.sh | 58 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index 406e74d72873..04185f035596 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -40,38 +40,40 @@ if ! yq --version > /dev/null 2>&1; then cleanupAndExit 1 fi -info "Verifying pods from Podfile.lock match local podspecs..." +if [ -d 'ios/Pods/Local Podspecs' ]; 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)" + # 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 + # 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 - info "🫛 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" - rm "$LOCAL_PODSPEC_PATH" - echo -e "\n" + 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 + info "🫛 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" + rm "$LOCAL_PODSPEC_PATH" + echo -e "\n" + fi + break fi - break - fi - done - clear_last_line - fi -done + done + clear_last_line + fi + done +fi cd ios || cleanupAndExit 1 bundle exec pod install From 5f4c971c9125b571042fb2f5bd1b2b6d16719ef2 Mon Sep 17 00:00:00 2001 From: rory Date: Sat, 27 Jul 2024 10:51:27 -0700 Subject: [PATCH 15/17] Simplify implementation and make it a touch faster --- scripts/pod-install.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index 04185f035596..95fa72e61f07 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -40,7 +40,8 @@ if ! yq --version > /dev/null 2>&1; then cleanupAndExit 1 fi -if [ -d 'ios/Pods/Local Podspecs' ]; then +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) @@ -53,18 +54,19 @@ if [ -d 'ios/Pods/Local Podspecs' ]; then 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 - info "🫛 Verifying local pod $EXTERNAL_SOURCE_POD" - POD_VERSION_FROM_LOCAL_PODSPECS="$(jq -r '.version' < <(cat "$LOCAL_PODSPEC_PATH"))" + for CACHED_PODSPEC_PATH in "$CACHED_PODSPEC_DIR"/*; do + if [ -f "$CACHED_PODSPEC_PATH" ]; then + 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 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 + 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: $EXTERNAL_SOURCE_POD, removing local podspec $LOCAL_PODSPEC_PATH" - rm "$LOCAL_PODSPEC_PATH" + info "⚠️ found mismatched pod: $CACHED_POD_NAME, removing local podspec $CACHED_PODSPEC_PATH" + rm "$CACHED_PODSPEC_PATH" echo -e "\n" fi break From 48e686c76de99538f9441efd2fbaf0240c63b20f Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 29 Jul 2024 11:08:20 -0700 Subject: [PATCH 16/17] Improve comments --- scripts/pod-install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index 95fa72e61f07..4f552aa60a54 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -56,11 +56,16 @@ if [ -d "$CACHED_PODSPEC_DIR" ]; then 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 From 819c5ea4908da51582f53d7f836df1485f410550 Mon Sep 17 00:00:00 2001 From: Rory Abraham <47436092+roryabraham@users.noreply.github.com> Date: Sun, 4 Aug 2024 11:01:49 -0700 Subject: [PATCH 17/17] Update scripts/pod-install.sh Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- scripts/pod-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index 4f552aa60a54..cb2976d64587 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -3,7 +3,7 @@ # 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 deleted any mismatched cached podspecs before running pod install +# 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