Skip to content

Instantly share code, notes, and snippets.

@AliSoftware
Last active March 12, 2021 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AliSoftware/dd2864cdf3b6814c67a3a1748031ef21 to your computer and use it in GitHub Desktop.
Save AliSoftware/dd2864cdf3b6814c67a3a1748031ef21 to your computer and use it in GitHub Desktop.
Tools to investigate the state of our internal pods at a8c
#!/usr/bin/env ruby
require 'json'
require 'yaml'
require 'open-uri'
# [Array<String>] List of iOS/macOS apps
app_dirs = ['WordPress-iOS', 'woocommerce-ios', 'simplenote-ios', 'simplenote-macos', 'autoproxxy']
specs_cache = File.join(__dir__, 'pod_stats.cache')
# [Hash{pod name => spec}] Pods owned by Automattic
podspecs = if File.exists?(specs_cache)
puts "Loading specs from cache file..."
YAML.load_file(specs_cache)
else
puts "No cache found. Loading all my specs from scratch to create cache..."
all_my_pods = `pod trunk me | sed -n /Pods:/,/Sessions:/p`.split("\n")[1..-2].map { |l| l.gsub(/^ *- /,'') }
all_specs = all_my_pods.map do |pod_name|
puts "Reading spec for #{pod_name}..."
[pod_name, JSON.load(`pod spec cat --regex '^#{Regexp.escape(pod_name)}$'`) ]
end.to_h
File.write(specs_cache, all_specs.to_yaml)
end
# [Array<String>] List of pod names belonging to a8c
a8c_pod_names = podspecs.select { |_, spec| ((spec['source'] || {})['git'])&.match(%{https://github.com/(Automattic|wordpress-mobile)/}) }.keys
# [Array<String>] Name of the a8c pods that are not deprecated
a8c_live_pod_names = a8c_pod_names.reject { |pod_name| podspecs[pod_name]['deprecated'] == true }
# Hash{pod name => name of a8c pods it depends on}
$deps_map = a8c_pod_names.map do |pod|
[pod, (podspecs[pod]['dependencies'] || {}).keys & a8c_pod_names]
end.to_h
# [Array<String>] List of that pod + all its transitive dependencies, recursively
def all_transitive_pods(pod)
([pod] + $deps_map[pod].flat_map { |dep_pod| all_transitive_pods(dep_pod) }).uniq
end
# [Hash{app_dir => Hash{pod=>version}}] List of pods and versions used by each app
versions_used_per_app = app_dirs.map do |dir_name|
lockfile_content = `cd "#{File.join(ENV['HOME'], 'Documents', 'Dev', dir_name)}" && (git checkout develop || git checkout trunk) &>/dev/null && cat Podfile.lock`
app_pods_refs = YAML.load(lockfile_content)['PODS']
app_pod_versions = app_pods_refs
.map { |entry| entry.is_a?(Hash) ? entry.keys.first : entry }
.map { |line| line.match(/^([^ ]+) +\((.+)\)$/).captures }
.to_h
.select { |(pod, _)| a8c_pod_names.include?(pod) }
[dir_name, app_pod_versions]
end.to_h
# [Array<String>] List of a8c pods that are _directly_ used by at least one app
used_pod_names = versions_used_per_app.values.flat_map(&:keys).uniq
# [Array<String>] List of a8c pods that are, directly OR indirectly, used by at least one app
all_used_pod_names = used_pod_names.flat_map { |p| all_transitive_pods(p) }.uniq
# [Array<String>] List of a8c pods that are not used by ANY app
unused_pods = a8c_pod_names - all_used_pod_names
puts "=== Unused pods"
puts unused_pods.map { |p| '- ' + p + (podspecs[p]['deprecated'] == true ? ' (deprecated)' : '') }
versions_per_pod = all_used_pod_names.map do |pod|
[pod, versions_used_per_app.values.map { |versions_map| versions_map[pod] }.compact.uniq]
end.to_h
puts "=== Various versions used by the apps for each active a8c pod"
versions_per_pod.each do |pod, versions|
prefix = $deps_map[pod].empty? ? ' 🌱 ' : ' '
puts "#{prefix}#{pod.ljust(30)}: #{versions.inspect}"
end
puts "=== Pods using our CircleCI orb command to auto-publish to trunk so far..."
all_used_pod_names.each do |pod|
repo_raw_url = podspecs[pod]['source']['git']
.gsub('git@github.com:', 'https://raw.githubusercontent.com/')
.gsub('https://github.com/', 'https://raw.githubusercontent.com/')
.gsub(/\.git$/, '')
content = URI.open("#{repo_raw_url}/develop/.circleci/config.yml").read rescue ""
ok = content.include?('ios/publish-podspec:')
puts " #{(ok ? "✅" : "❌")} #{pod}"
end
#!/bin/bash
START_TAG=$1
TAGS_LIST=`git tag --list | sort -V | sed -n /$START_TAG/,/_/p`
PODSPEC=`ls *.podspec`
echo "About to push $PODSPEC for following tags:"
echo $TAGS_LIST | tr ' ' '\n'
read -p "Continue? [y/n] " -s -n1 confirm
echo
if [[ $confirm != 'y' ]]; then
exit
fi
echo "Pushing $PODSPEC to internal spec repo..."
OLD_BRANCH=`git branch --show-current`
for t in $TAGS_LIST; do
git checkout $t
echo "=== Pushing $t..."
bundle check || bundle install
bundle exec pod repo push "git@github.com:wordpress-mobile/cocoapods-specs.git" "$PODSPEC"
done
git checkout "$OLD_BRANCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment