From 7e371b3bdfff6018686d040e6f3fb7213440d658 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Mon, 27 Apr 2020 15:05:11 -0700 Subject: [PATCH] Add --synchronous option to pod trunk push --- CHANGELOG.md | 5 ++++- lib/pod/command/trunk/push.rb | 22 ++++++++++----------- spec/command/trunk/push_spec.rb | 35 ++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b51deb..780a04d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/pod/command/trunk/push.rb b/lib/pod/command/trunk/push.rb index 9e337eb..209018b 100644 --- a/lib/pod/command/trunk/push.rb +++ b/lib/pod/command/trunk/push.rb @@ -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 @@ -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 @@ -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}", @@ -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=) @@ -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 diff --git a/spec/command/trunk/push_spec.rb b/spec/command/trunk/push_spec.rb index 2b81c94..6dde8cd 100644 --- a/spec/command/trunk/push_spec.rb +++ b/spec/command/trunk/push_spec.rb @@ -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 @@ -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)