-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from adarovsky/publish-improvements
Publish improvements
- Loading branch information
Showing
3 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
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 | ||
'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 | ||
'An original list of podspec filenames sorted by dependency' | ||
end | ||
|
||
def self.authors | ||
['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 | ||
end | ||
end | ||
end |