From 96bbb676e245a5f9a7bd95f59c02dac27fc8f5b7 Mon Sep 17 00:00:00 2001 From: Aleksandr Darovskikh Date: Wed, 14 Jun 2023 20:07:57 +0500 Subject: [PATCH 1/3] Sort podspecs by dependency and update local dependencies when bumping version --- fastlane/Fastfile | 6 +- fastlane/actions/bump_podspec_dependency.rb | 51 +++++++++++ fastlane/actions/sorted_podspecs.rb | 93 +++++++++++++++++++++ 3 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 fastlane/actions/bump_podspec_dependency.rb create mode 100644 fastlane/actions/sorted_podspecs.rb diff --git a/fastlane/Fastfile b/fastlane/Fastfile index acddfb4..c91cd08 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -4,10 +4,12 @@ lane :release do |options| # Checking that everything is alright check - podspec_names = Dir.glob('*.podspec', base: '..') + podspec_names = sorted_podspecs(podspecs:Dir.glob('*.podspec', base: '..')) # Bumping podspec version for podspec_name in podspec_names version = version_bump_podspec(path: podspec_name, bump_type: bump_type) + + bump_podspec_dependency(podspecs: podspec_names, name: podspec_name.delete_suffix('.podspec'), version: version) end add_files = extend_bump_version(version: version) @@ -108,7 +110,7 @@ end def push_podspec(podspec_name) tries = 6 - for i in 1..tries + (1..tries).each do |i| begin sh("bundle exec pod repo update") pod_push( diff --git a/fastlane/actions/bump_podspec_dependency.rb b/fastlane/actions/bump_podspec_dependency.rb new file mode 100644 index 0000000..d2c4e64 --- /dev/null +++ b/fastlane/actions/bump_podspec_dependency.rb @@ -0,0 +1,51 @@ +module Fastlane + module Actions + class BumpPodspecDependencyAction < Action + def self.run(params) + podspecs = params[:podspecs] + name = params[:name] + version = params[:version] + regexp = %r{(\.dependency\s+['"]#{Regexp.escape(name)}(?:/[^/'"]+)*['"]\s*,\s*['"])(?:[^'"]+)(['"])}m + affected_podspecs = [] + podspecs.each do |podspec| + UI.message("replacing #{regexp}") + content = File.read(podspec) + new_content = content.gsub(regexp, "\\1#{version}\\2") + if new_content != content + File.write(podspec, new_content) + affected_podspecs.append(podspec) + end + end + if affected_podspecs.empty? + UI.important("No affected podspecs for dependency '#{name}'") + else + UI.success("Update dependency '#{name}' to version #{version} in #{affected_podspecs.join(', ')}") + end + affected_podspecs + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new( + key: :podspecs, + description: 'Podspec path list', + type: Array, + optional: false + ), + FastlaneCore::ConfigItem.new( + key: :name, + description: 'Dependency name (example: Alamofire)', + type: String, + optional: false + ), + FastlaneCore::ConfigItem.new( + key: :version, + description: 'Dependency version (example: \'~> 1.2.3\')', + type: String, + optional: false + ) + ] + end + end + end +end diff --git a/fastlane/actions/sorted_podspecs.rb b/fastlane/actions/sorted_podspecs.rb new file mode 100644 index 0000000..da0f4db --- /dev/null +++ b/fastlane/actions/sorted_podspecs.rb @@ -0,0 +1,93 @@ +require 'cocoapods' +require 'tsort' + +module Fastlane + module Actions + class SortedPodspecsAction < Action + def self.run(params) + @podspecs = params[:podspecs].map { |filename| Fastlane::Helper::Podspec.new(filename) } + + tsort.map(&:path) + end + + ##################################################### + # @!group Documentation + ##################################################### + + def self.description + 'Returns a list of podspecs sorted by dependency' + end + + def self.details + # Optional: + # this is your chance to provide a more detailed description of this action + 'Parses podspec from a given list and topologically sorts them by dependency' + end + + def self.available_options + # Define all options your action supports. + + # Below a few examples + [ + FastlaneCore::ConfigItem.new( + key: :podspecs, + description: 'Podspec path list', + type: Array, + optional: false + ) + ] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.authors + # So no one will ever forget your contribution to fastlane :) You are awesome btw! + ['adarovsky'] + end + + ##################################################### + # @!group Sorting + ##################################################### + + def self.tsort_each_node(&block) + @podspecs.each(&block) + end + + def self.tsort_each_child(node, &block) + node + .dependencies + .filter_map { |d| @podspecs.find { |e| e.name == d.name } } + .each(&block) + end + + extend TSort + end + end + + module Helper + class Podspec + + attr_reader :path + + # @param [String] path + def initialize(path) + @path = path + @spec = Pod::Spec.from_file(path) + end + + def dependencies + @spec.dependencies + end + + def name + @spec.name + end + + def to_s + "#{@spec}: #{path}/#{@spec.name}.podspec" + end + end + end +end From 7bd08203b129448f3f14eed1d3bddd57ced850d0 Mon Sep 17 00:00:00 2001 From: Aleksandr Darovskikh Date: Wed, 14 Jun 2023 20:10:09 +0500 Subject: [PATCH 2/3] Revert auto-change --- fastlane/Fastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index c91cd08..7ab5873 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -110,7 +110,7 @@ end def push_podspec(podspec_name) tries = 6 - (1..tries).each do |i| + for i in 1..tries begin sh("bundle exec pod repo update") pod_push( From b66ac419d8ab6cd5089012767b3c5f5f1327771f Mon Sep 17 00:00:00 2001 From: Aleksandr Darovskikh Date: Wed, 14 Jun 2023 20:23:54 +0500 Subject: [PATCH 3/3] Update sorted_podspecs.rb Remove unneeded comments and methods --- fastlane/actions/sorted_podspecs.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/fastlane/actions/sorted_podspecs.rb b/fastlane/actions/sorted_podspecs.rb index da0f4db..d12a5b2 100644 --- a/fastlane/actions/sorted_podspecs.rb +++ b/fastlane/actions/sorted_podspecs.rb @@ -19,8 +19,6 @@ def self.description end def self.details - # Optional: - # this is your chance to provide a more detailed description of this action 'Parses podspec from a given list and topologically sorts them by dependency' end @@ -39,11 +37,10 @@ def self.available_options end def self.return_value - # If your method provides a return value, you can describe here what it does + 'An original list of podspec filenames sorted by dependency' end def self.authors - # So no one will ever forget your contribution to fastlane :) You are awesome btw! ['adarovsky'] end @@ -84,10 +81,6 @@ def dependencies def name @spec.name end - - def to_s - "#{@spec}: #{path}/#{@spec.name}.podspec" - end end end end