diff --git a/.github/scripts/verifyPodfile.sh b/.github/scripts/verifyPodfile.sh index 213da895d365..dc4c54fd229a 100755 --- a/.github/scripts/verifyPodfile.sh +++ b/.github/scripts/verifyPodfile.sh @@ -1,19 +1,64 @@ #!/bin/bash -declare -r GREEN='\033[0;32m' -declare -r RED='\033[0;31m' -declare -r NC='\033[0m' +START_DIR=$(pwd) +ROOT_DIR=$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")") +cd "$ROOT_DIR" || exit 1 -podfileSha=$(openssl sha1 ios/Podfile | awk '{print $2}') -podfileLockSha=$(awk '/PODFILE CHECKSUM: /{print $3}' ios/Podfile.lock) +source scripts/shellUtils.sh -echo "Podfile: $podfileSha" -echo "Podfile.lock: $podfileLockSha" +title "Verifying that Podfile.lock is synced with the project" -if [ "$podfileSha" == "$podfileLockSha" ]; then - echo -e "${GREEN}Podfile verified!${NC}" - exit 0 +declare EXIT_CODE=0 + +PODFILE_SHA=$(openssl sha1 ios/Podfile | awk '{print $2}') +PODFILE_LOCK_SHA=$(awk '/PODFILE CHECKSUM: /{print $3}' ios/Podfile.lock) + +echo "Podfile: $PODFILE_SHA" +echo "Podfile.lock: $PODFILE_LOCK_SHA" + +if [[ "$PODFILE_SHA" == "$PODFILE_LOCK_SHA" ]]; then + success "Podfile checksum verified!" else - echo -e "${RED}Error: Podfile.lock out of date with Podfile. Did you forget to run \`npx pod-install\`?${NC}" - exit 1 + error "Podfile.lock checksum mismatch. Did you forget to run \`npx pod-install\`?" + EXIT_CODE=1 +fi + +info "Comparing Podfile.lock with node packages..." + +# Retrieve a list of podspec directories as listed in the Podfile.lock +SPEC_DIRS=$(yq '.["EXTERNAL SOURCES"].[].":path" | select( . == "*node_modules*")' < ios/Podfile.lock) + +# Format a list of Pods based on the output of the config command +FORMATTED_PODS=$( \ + jq --raw-output --slurp 'map((.name + " (" + .version + ")")) | .[]' <<< "$( \ + npx react-native config | \ + jq '.dependencies[].platforms.ios.podspecPath | select( . != null )' | \ + xargs -L 1 pod ipc spec --silent + )" +) + +# Check for uncommitted package removals +# If they are listed in Podfile.lock but the directories don't exist they have been removed +while read -r DIR; do + if [[ ! -d "${DIR#../}" ]]; then + error "Directory \`${DIR#../node_modules/}\` not found in node_modules. Did you forget to run \`npx pod-install\` after removing the package?" + EXIT_CODE=1 + fi +done <<< "$SPEC_DIRS" + +# Check for uncommitted package additions/updates +while read -r POD; do + if ! grep -q "$POD" ./ios/Podfile.lock; then + error "$POD not found in Podfile.lock. Did you forget to run \`npx pod-install\`?" + EXIT_CODE=1 + fi +done <<< "$FORMATTED_PODS" + +if [[ "$EXIT_CODE" == 0 ]]; then + success "Podfile.lock is up to date." fi + +# Cleanup +cd "$START_DIR" || exit 1 + +exit $EXIT_CODE diff --git a/.github/workflows/verifyPodfile.yml b/.github/workflows/verifyPodfile.yml index 84f52d09997a..490d88463b45 100644 --- a/.github/workflows/verifyPodfile.yml +++ b/.github/workflows/verifyPodfile.yml @@ -8,7 +8,7 @@ on: jobs: verify: if: github.actor != 'OSBotify' - runs-on: ubuntu-latest + runs-on: macos-latest steps: # This action checks-out the repository, so the workflow can access it. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8