Skip to content

Commit

Permalink
Merge pull request #147 from CocoaPods/paulb777-synchonous
Browse files Browse the repository at this point in the history
Add --synchronous option to pod trunk push
  • Loading branch information
paulb777 authored Apr 27, 2020
2 parents 6795930 + 7e371b3 commit 41f52c8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

##### Enhancements

* None.
* Add --synchronous option to `pod trunk push`.
[Paul Beusterien](https://github.com/paulb777)
[#147](https://github.com/CocoaPods/cocoapods-trunk/pull/147)
[CocoaPods#9497](https://github.com/CocoaPods/CocoaPods/issues/9497)

##### Bug Fixes

Expand Down
22 changes: 11 additions & 11 deletions lib/pod/command/trunk/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def self.options
'This takes precedence over a .swift-version file.'],
['--skip-import-validation', 'Lint skips validating that the pod can be imported'],
['--skip-tests', 'Lint skips building and running tests during validation'],
['--synchronous', 'If validation depends on other recently pushed pods, synchronize'],
].concat(super)
end

Expand All @@ -47,6 +48,7 @@ def initialize(argv)
@skip_import_validation = argv.flag?('skip-import-validation', false)
@skip_tests = argv.flag?('skip-tests', false)
@path = argv.shift_argument || '.'
@synchronous = argv.flag?('synchronous', false)
find_podspec_file if File.directory?(@path)
super
end
Expand Down Expand Up @@ -80,6 +82,8 @@ def run

private

MASTER_GIT_REPO_URL = 'https://github.com/CocoaPods/Specs.git'.freeze

def push_to_trunk
spec.attributes_hash[:pushed_with_swift_version] = @swift_version if @swift_version
response = request_path(:post, "pods?allow_warnings=#{@allow_warnings}",
Expand Down Expand Up @@ -118,7 +122,7 @@ def spec
def validate_podspec
UI.puts 'Validating podspec'.yellow

validator = Validator.new(spec, [master_repo_url])
validator = Validator.new(spec, [repo_url])
validator.allow_warnings = @allow_warnings
validator.use_frameworks = @use_frameworks
if validator.respond_to?(:use_modular_headers=)
Expand All @@ -139,21 +143,17 @@ def validate_podspec
@swift_version = validator.respond_to?(:used_swift_version) && validator.used_swift_version
end

def repo_url
@synchronous ? MASTER_GIT_REPO_URL : Pod::TrunkSource::TRUNK_REPO_URL
end

def update_master_repo
# more robust Trunk setup logic:
# - if Trunk exists, updates it
# - if Trunk doesn't exist, add it and update it
#
trunk = sources_manager.find_or_create_source_with_url(Pod::TrunkSource::TRUNK_REPO_URL)
sources_manager.update(trunk.name)
end

def master_repo_name
sources_manager.master.first.name
end

def master_repo_url
sources_manager.master.first.url
repo = sources_manager.find_or_create_source_with_url(repo_url)
sources_manager.update(repo.name)
end

def sources_manager
Expand Down
35 changes: 34 additions & 1 deletion spec/command/trunk/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def found_podspec_among_files(files)
it 'updates the master repo when it exists' do
Config.instance.sources_manager.stubs(:source_with_url).
at_most(2).
returns(Pod::TrunkSource.new(Pod::TrunkSource::TRUNK_REPO_NAME)).
returns(Pod::TrunkSource.new(Pod::TrunkSource::TRUNK_REPO_NAME))

Config.instance.sources_manager.expects(:update).with(Pod::TrunkSource::TRUNK_REPO_NAME).twice
Expand All @@ -262,6 +261,40 @@ def found_podspec_among_files(files)
end
end

describe 'synchronous updating the git repo' do
before do
@cmd = Command.parse(%w(trunk push spec/fixtures/BananaLib.podspec --synchronous))
@cmd.stubs(:validate_podspec)
@cmd.stubs(:push_to_trunk).returns([200, success_json])
Command::Trunk::Push.any_instance.unstub(:update_master_repo)
Command::Trunk::Push.any_instance.stubs(:master_repo_name).returns('master')
end

it 'updates the git repo when it exists' do
Config.instance.sources_manager.stubs(:source_with_url).
at_most(2).
returns(Pod::TrunkSource.new('master'))

Config.instance.sources_manager.expects(:update).with('master').twice
Command::Repo::AddCDN.any_instance.expects(:run).never

@cmd.run
end

it 'sets up the git repo when it does not exist' do
Config.instance.sources_manager.stubs(:source_with_url).
at_most(3).
returns(nil).
returns(Pod::TrunkSource.new('master'))
Config.instance.sources_manager.stubs(:cdn_url?).returns(false)
Config.instance.sources_manager.stubs(:create_source_with_url).once.
returns(Pod::TrunkSource.new('master'))
Config.instance.sources_manager.expects(:update).with('master').twice

@cmd.run
end
end

describe 'Presenting Responses to the user' do
before do
Command::Trunk::Push.any_instance.stubs(:update_master_repo)
Expand Down

0 comments on commit 41f52c8

Please sign in to comment.