Skip to content

Commit

Permalink
Create custom ruby script to print podspecs in a react native environ…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
roryabraham committed Jun 6, 2024
1 parent 7458515 commit 1d97b58
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
35 changes: 35 additions & 0 deletions .github/scripts/printPodspec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env ruby

# This file is a lightweight port of the `pod ipc spec` command.
# It was built from scratch to imports some 3rd party functions before reading podspecs

require 'cocoapods'
require 'json'

# Require 3rd party functions needed to parse podspecs. This code is copied from ios/Podfile
def node_require(script)
# Resolve script with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
"require.resolve(
'#{script}',
{paths: [process.argv[1]]},
)", __dir__]).strip
end
node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')

# Configure pod in silent mode
Pod::Config.instance.silent = true

# Process command-line arguments
podspec_files = ARGV

# Validate each podspec file
podspec_files.each do |podspec_file|
begin
spec = Pod::Specification.from_file(podspec_file)
puts(spec.to_pretty_json)
rescue => e
STDERR.puts "Failed to validate #{podspec_file}: #{e.message}"
end
end
13 changes: 7 additions & 6 deletions .github/scripts/verifyPodfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ if ! SPEC_DIRS=$(yq '.["EXTERNAL SOURCES"].[].":path" | select( . == "*node_modu
cleanupAndExit 1
fi

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
fi

# Format a list of Pods based on the output of the config command
if ! 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
)"
jq --raw-output --slurp 'map((.name + " (" + .version + ")")) | .[]' <<< "$(./.github/scripts/printPodspec.rb "${PODSPEC_PATHS[@]}")" \
); then
error "Error: could not parse pods from react-native config command"
error "Error: could not parse podspecs at paths parsed from react-native config"
cleanupAndExit 1
fi

Expand Down
16 changes: 15 additions & 1 deletion scripts/shellUtils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,18 @@ get_abs_path() {
abs_path=${abs_path/#\/\//\/}

echo "$abs_path"
}
}

# Function to read lines from standard input into an array using a temporary file.
# This is a bash 3 polyfill for readarray.
# Arguments:
# $1: Name of the array variable to store the lines
# Usage:
# read_lines_into_array array_name
read_lines_into_array() {
local array_name="$1"
local line
while IFS= read -r line || [ -n "$line" ]; do
eval "$array_name+=(\"$line\")"
done
}

0 comments on commit 1d97b58

Please sign in to comment.