Skip to content

Commit 21e1901

Browse files
authored
Merge pull request #43154 from Expensify/Rory-VerifyPodfile
[No QA] Fix verifyPodfile script
2 parents 54210a8 + 1d97b58 commit 21e1901

File tree

3 files changed

+78
-23
lines changed

3 files changed

+78
-23
lines changed

.github/scripts/printPodspec.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env ruby
2+
3+
# This file is a lightweight port of the `pod ipc spec` command.
4+
# It was built from scratch to imports some 3rd party functions before reading podspecs
5+
6+
require 'cocoapods'
7+
require 'json'
8+
9+
# Require 3rd party functions needed to parse podspecs. This code is copied from ios/Podfile
10+
def node_require(script)
11+
# Resolve script with node to allow for hoisting
12+
require Pod::Executable.execute_command('node', ['-p',
13+
"require.resolve(
14+
'#{script}',
15+
{paths: [process.argv[1]]},
16+
)", __dir__]).strip
17+
end
18+
node_require('react-native/scripts/react_native_pods.rb')
19+
node_require('react-native-permissions/scripts/setup.rb')
20+
21+
# Configure pod in silent mode
22+
Pod::Config.instance.silent = true
23+
24+
# Process command-line arguments
25+
podspec_files = ARGV
26+
27+
# Validate each podspec file
28+
podspec_files.each do |podspec_file|
29+
begin
30+
spec = Pod::Specification.from_file(podspec_file)
31+
puts(spec.to_pretty_json)
32+
rescue => e
33+
STDERR.puts "Failed to validate #{podspec_file}: #{e.message}"
34+
end
35+
end

.github/scripts/verifyPodfile.sh

+28-22
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ source scripts/shellUtils.sh
88

99
title "Verifying that Podfile.lock is synced with the project"
1010

11-
declare EXIT_CODE=0
11+
# Cleanup and exit
12+
# param - status code
13+
function cleanupAndExit {
14+
cd "$START_DIR" || exit 1
15+
exit "$1"
16+
}
1217

1318
# Check Provisioning Style. If automatic signing is enabled, iOS builds will fail, so ensure we always have the proper profile specified
1419
info "Verifying that automatic signing is not enabled"
1520
if grep -q 'PROVISIONING_PROFILE_SPECIFIER = "(NewApp) AppStore"' ios/NewExpensify.xcodeproj/project.pbxproj; then
1621
success "Automatic signing not enabled"
1722
else
1823
error "Error: Automatic provisioning style is not allowed!"
19-
EXIT_CODE=1
24+
cleanupAndExit 1
2025
fi
2126

2227
PODFILE_SHA=$(openssl sha1 ios/Podfile | awk '{print $2}')
@@ -29,7 +34,7 @@ if [[ "$PODFILE_SHA" == "$PODFILE_LOCK_SHA" ]]; then
2934
success "Podfile checksum verified!"
3035
else
3136
error "Podfile.lock checksum mismatch. Did you forget to run \`npx pod-install\`?"
32-
EXIT_CODE=1
37+
cleanupAndExit 1
3338
fi
3439

3540
info "Ensuring correct version of cocoapods is used..."
@@ -45,45 +50,46 @@ if [[ "$POD_VERSION_FROM_GEMFILE" == "$POD_VERSION_FROM_PODFILE_LOCK" ]]; then
4550
success "Cocoapods version from Podfile.lock matches cocoapods version from Gemfile"
4651
else
4752
error "Cocoapods version from Podfile.lock does not match cocoapods version from Gemfile. Please use \`npm run pod-install\` or \`bundle exec pod install\` instead of \`pod install\` to install pods."
48-
EXIT_CODE=1
53+
cleanupAndExit 1
4954
fi
5055

5156
info "Comparing Podfile.lock with node packages..."
5257

5358
# Retrieve a list of podspec directories as listed in the Podfile.lock
54-
SPEC_DIRS=$(yq '.["EXTERNAL SOURCES"].[].":path" | select( . == "*node_modules*")' < ios/Podfile.lock)
59+
if ! SPEC_DIRS=$(yq '.["EXTERNAL SOURCES"].[].":path" | select( . == "*node_modules*")' < ios/Podfile.lock); then
60+
error "Error: Could not parse podspec directories from Podfile.lock"
61+
cleanupAndExit 1
62+
fi
63+
64+
if ! read_lines_into_array PODSPEC_PATHS < <(npx react-native config | jq --raw-output '.dependencies[].platforms.ios.podspecPath | select ( . != null)'); then
65+
error "Error: could not parse podspec paths from react-native config command"
66+
cleanupAndExit 1
67+
fi
5568

5669
# Format a list of Pods based on the output of the config command
57-
FORMATTED_PODS=$( \
58-
jq --raw-output --slurp 'map((.name + " (" + .version + ")")) | .[]' <<< "$( \
59-
npx react-native config | \
60-
jq '.dependencies[].platforms.ios.podspecPath | select( . != null )' | \
61-
xargs -L 1 pod ipc spec --silent
62-
)"
63-
)
70+
if ! FORMATTED_PODS=$( \
71+
jq --raw-output --slurp 'map((.name + " (" + .version + ")")) | .[]' <<< "$(./.github/scripts/printPodspec.rb "${PODSPEC_PATHS[@]}")" \
72+
); then
73+
error "Error: could not parse podspecs at paths parsed from react-native config"
74+
cleanupAndExit 1
75+
fi
6476

6577
# Check for uncommitted package removals
6678
# If they are listed in Podfile.lock but the directories don't exist they have been removed
6779
while read -r DIR; do
6880
if [[ ! -d "${DIR#../}" ]]; then
6981
error "Directory \`${DIR#../node_modules/}\` not found in node_modules. Did you forget to run \`npx pod-install\` after removing the package?"
70-
EXIT_CODE=1
82+
cleanupAndExit 1
7183
fi
7284
done <<< "$SPEC_DIRS"
7385

7486
# Check for uncommitted package additions/updates
7587
while read -r POD; do
7688
if ! grep -q "$POD" ./ios/Podfile.lock; then
7789
error "$POD not found in Podfile.lock. Did you forget to run \`npx pod-install\`?"
78-
EXIT_CODE=1
90+
cleanupAndExit 1
7991
fi
8092
done <<< "$FORMATTED_PODS"
8193

82-
if [[ "$EXIT_CODE" == 0 ]]; then
83-
success "Podfile.lock is up to date."
84-
fi
85-
86-
# Cleanup
87-
cd "$START_DIR" || exit 1
88-
89-
exit $EXIT_CODE
94+
success "Podfile.lock is up to date."
95+
cleanupAndExit 0

scripts/shellUtils.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,18 @@ get_abs_path() {
102102
abs_path=${abs_path/#\/\//\/}
103103

104104
echo "$abs_path"
105-
}
105+
}
106+
107+
# Function to read lines from standard input into an array using a temporary file.
108+
# This is a bash 3 polyfill for readarray.
109+
# Arguments:
110+
# $1: Name of the array variable to store the lines
111+
# Usage:
112+
# read_lines_into_array array_name
113+
read_lines_into_array() {
114+
local array_name="$1"
115+
local line
116+
while IFS= read -r line || [ -n "$line" ]; do
117+
eval "$array_name+=(\"$line\")"
118+
done
119+
}

0 commit comments

Comments
 (0)