diff --git a/Gemfile b/Gemfile index f795e05..39672db 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,3 @@ gemspec group :test do gem 'rake' end - -if RUBY_VERSION =~ /1.9/ - Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::UTF_8 -end diff --git a/Gemfile.lock b/Gemfile.lock index 2ed79d4..57824d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - bigkeeper (0.9.9) + bigkeeper (0.9.17) big_resources big_stash (~> 0.1) cocoapods @@ -18,7 +18,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - ast (2.3.0) + ast (2.4.0) atomos (0.1.3) big_resources (0.1.2) chunky_png @@ -30,26 +30,26 @@ GEM gli (~> 2.16) chunky_png (1.3.11) claide (1.0.2) - cocoapods (1.6.1) + cocoapods (1.5.0) activesupport (>= 4.0.2, < 5) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.6.1) + cocoapods-core (= 1.5.0) cocoapods-deintegrate (>= 1.0.2, < 2.0) - cocoapods-downloader (>= 1.2.2, < 2.0) + cocoapods-downloader (>= 1.2.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.3.1, < 2.0) + cocoapods-trunk (>= 1.3.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (>= 2.2.0, < 3.0) + fourflusher (~> 2.0.1) gh_inspector (~> 1.0) - molinillo (~> 0.6.6) + molinillo (~> 0.6.5) nap (~> 1.0) - ruby-macho (~> 1.4) - xcodeproj (>= 1.8.1, < 2.0) - cocoapods-core (1.6.1) + ruby-macho (~> 1.1) + xcodeproj (>= 1.5.7, < 2.0) + cocoapods-core (1.5.0) activesupport (>= 4.0.2, < 6) fuzzy_match (~> 2.0.4) nap (~> 1.0) @@ -67,7 +67,7 @@ GEM colorize (0.8.1) concurrent-ruby (1.1.5) escape (0.0.4) - fourflusher (2.2.0) + fourflusher (2.0.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) gli (2.18.0) @@ -78,11 +78,11 @@ GEM nanaimo (0.2.6) nap (1.1.0) netrc (0.11.0) - parallel (1.12.0) - parser (2.4.0.0) - ast (~> 2.2) + parallel (1.12.1) + parser (2.5.1.2) + ast (~> 2.4.0) plist (3.5.0) - powerpack (0.1.1) + powerpack (0.1.2) rainbow (2.2.2) rake rake (10.5.0) @@ -98,7 +98,7 @@ GEM thread_safe (0.3.6) tzinfo (1.2.5) thread_safe (~> 0.1) - unicode-display_width (1.3.0) + unicode-display_width (1.4.0) xcodeproj (1.8.2) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) diff --git a/lib/big_keeper.rb b/lib/big_keeper.rb index 9182947..f54b941 100644 --- a/lib/big_keeper.rb +++ b/lib/big_keeper.rb @@ -14,6 +14,7 @@ require 'big_keeper/command/spec' require 'big_keeper/command/image' require 'big_keeper/command/init' +require 'big_keeper/command/client' require 'big_keeper/service/git_service' require 'big_keeper/util/leancloud_logger' @@ -46,7 +47,7 @@ module BigKeeper post do |global_options, command, options, args| is_show_log = true - if global_options[:log] == 'false' + if global_options[:log] == 'true' is_show_log = false end LeanCloudLogger.instance.end_log(true, is_show_log) @@ -66,6 +67,8 @@ module BigKeeper init_command + client_command + desc 'Show version of bigkeeper' command :version do |version| version.action do |global_options, options, args| diff --git a/lib/big_keeper/command/client.rb b/lib/big_keeper/command/client.rb new file mode 100644 index 0000000..f0141da --- /dev/null +++ b/lib/big_keeper/command/client.rb @@ -0,0 +1,50 @@ +require 'big_keeper/util/leancloud_logger' +require 'big_keeper/command/pod/podfile' +require 'big_keeper/command/spec/list' +require 'big_keeper/util/list_generator' + +module BigKeeper + + def self.client_command + desc 'API for bigkeeper-client.' + command :client do | c | + c.desc 'Commands about operate modules.' + c.command :modules do |modules| + modules.desc 'Get modules list from Bigkeeper file.' + modules.command :list do |list| + list.action do |global_options, options, args| + LeanCloudLogger.instance.set_command("spec/list") + path = File.expand_path(global_options[:path]) + version = global_options[:ver] + user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + spec_list(path, user, options) + end + end + modules.desc 'Update modules.' + modules.command :update do |update| + update.action do |global_options, options, args| + LeanCloudLogger.instance.set_command("spec/list") + path = File.expand_path(global_options[:path]) + version = global_options[:ver] + user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + spec_list(path, user, options) + end + end + end + c.desc 'Commands about features.' + c.command :feature do |feature| + feature.desc "List all the features including origin." + feature.command :list do | list | + list.flag %i[v version] , default_value: 'all versions' + list.action do |global_options, options, args| + LeanCloudLogger.instance.set_command("feature/list/json") + options[:json] = true + path = File.expand_path(global_options[:path]) + user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + list(path, user, GitflowType::FEATURE, options) + end + end + end + end + end +end diff --git a/lib/big_keeper/command/feature&hotfix.rb b/lib/big_keeper/command/feature&hotfix.rb index fc08b5e..9337b7c 100644 --- a/lib/big_keeper/command/feature&hotfix.rb +++ b/lib/big_keeper/command/feature&hotfix.rb @@ -8,6 +8,7 @@ require 'big_keeper/command/feature&hotfix/publish' require 'big_keeper/command/feature&hotfix/delete' require 'big_keeper/command/feature&hotfix/list' +require 'big_keeper/command/feature&hotfix/module' require 'big_keeper/util/leancloud_logger' module BigKeeper @@ -43,6 +44,33 @@ def self.feature_and_hotfix_command(type) end end + c.desc "Modules operate for the #{GitflowType.name(type)}" + c.command :module do |m| + m.desc "Add modules for the #{GitflowType.name(type)}" + m.command :add do |add| + add.action do |global_options, options, args| + path = File.expand_path(global_options[:path]) + version = global_options[:ver] + user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + LeanCloudLogger.instance.set_command("feature/module/add") + modules = args[(0...args.length)] if args.length > 0 + module_add(path, user, modules, type) + end + end + + m.desc "delete modules for the #{GitflowType.name(type)}" + m.command :delete do |delete| + delete.action do |global_options, options, args| + path = File.expand_path(global_options[:path]) + version = global_options[:ver] + user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + LeanCloudLogger.instance.set_command("feature/module/delete") + modules = args[(0...args.length)] if args.length > 0 + module_del(path, user, modules, type) + end + end + end + c.desc "Switch to the #{GitflowType.name(type)} with name" c.command :switch do |switch| switch.action do |global_options, options, args| diff --git a/lib/big_keeper/command/feature&hotfix/delete.rb b/lib/big_keeper/command/feature&hotfix/delete.rb index 010a212..212c60c 100644 --- a/lib/big_keeper/command/feature&hotfix/delete.rb +++ b/lib/big_keeper/command/feature&hotfix/delete.rb @@ -20,9 +20,9 @@ def self.delete(path, user, name, type) # Parse Bigkeeper file BigkeeperParser.parse("#{path}/Bigkeeper") branch_name = "#{GitflowType.name(type)}/#{name}" + version = 'all version' modules = BigkeeperParser.module_names - modules.each do |module_name| module_full_path = BigkeeperParser.module_full_path(path, user, module_name) diff --git a/lib/big_keeper/command/feature&hotfix/list.rb b/lib/big_keeper/command/feature&hotfix/list.rb index 9c114b2..4113daa 100644 --- a/lib/big_keeper/command/feature&hotfix/list.rb +++ b/lib/big_keeper/command/feature&hotfix/list.rb @@ -19,7 +19,7 @@ def self.list(path, user, type, options) begin #get cache file path FileUtils.mkdir_p(cache_path) unless File.exist?(cache_path) - file = File.new(json_path, 'w') + file = File.new(json_path, 'w', :encoding => 'UTF-8') begin #get all modules info module_list_dic = get_module_info(path, user, type, version, branches, is_print_log) diff --git a/lib/big_keeper/command/feature&hotfix/module.rb b/lib/big_keeper/command/feature&hotfix/module.rb new file mode 100644 index 0000000..5a7def5 --- /dev/null +++ b/lib/big_keeper/command/feature&hotfix/module.rb @@ -0,0 +1,89 @@ +#!/usr/bin/ruby + +require 'big_keeper/util/podfile_operator' +require 'big_keeper/util/gitflow_operator' +require 'big_keeper/util/bigkeeper_parser' +require 'big_keeper/util/logger' +require 'big_keeper/util/pod_operator' +require 'big_keeper/util/xcode_operator' +require 'big_keeper/util/cache_operator' +require 'big_keeper/model/operate_type' +require 'big_keeper/dependency/dep_service' + +require 'big_keeper/dependency/dep_type' + +require 'big_keeper/service/stash_service' +require 'big_keeper/service/module_service' + + +module BigKeeper + def self.module_add(path, user, modules, type) + BigkeeperParser.parse("#{path}/Bigkeeper") + branch_name = GitOperator.new.current_branch(path) + + Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type) + + full_name = branch_name.gsub(/#{GitflowType.name(type)}\//, '') + + # Verify input modules + modules = BigkeeperParser.verify_modules(modules) + + current_modules = ModuleCacheOperator.new(path).current_path_modules + + ModuleCacheOperator.new(path).clean_modules + ModuleCacheOperator.new(path).cache_path_modules(current_modules + modules, modules, []) + + Logger.highlight("Start to add modules for branch '#{branch_name}'...") + + if modules.empty? + Logger.default("There is nothing changed with modules #{modules}.") + else + # Modify podfile as path and Start modules feature + modules.each do |module_name| + ModuleCacheOperator.new(path).add_path_module(module_name) + ModuleService.new.add(path, user, module_name, full_name, type) + end + end + + # Install + DepService.dep_operator(path, user).install(modules, OperateType::UPDATE, false) + + # Open home workspace + DepService.dep_operator(path, user).open + end + + def self.module_del(path, user, modules, type) + BigkeeperParser.parse("#{path}/Bigkeeper") + branch_name = GitOperator.new.current_branch(path) + + Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type) + + full_name = branch_name.gsub(/#{GitflowType.name(type)}\//, '') + + current_modules = ModuleCacheOperator.new(path).current_path_modules + + # Verify input modules + modules = BigkeeperParser.verify_modules(modules) + + ModuleCacheOperator.new(path).clean_modules + ModuleCacheOperator.new(path).cache_path_modules(current_module + modules, [], modules) + + Logger.highlight("Start to delete modules for branch '#{branch_name}'...") + + if modules.empty? + Logger.default("There is nothing changed with modules #{modules}.") + else + # Modify podfile as path and Start modules feature + modules.each do |module_name| + ModuleCacheOperator.new(path).del_path_module(module_name) + ModuleService.new.del(path, user, module_name, full_name, type) + end + end + + # Install + DepService.dep_operator(path, user).install(modules, OperateType::UPDATE, false) + + # Open home workspace + DepService.dep_operator(path, user).open + end +end diff --git a/lib/big_keeper/command/feature&hotfix/publish.rb b/lib/big_keeper/command/feature&hotfix/publish.rb index 622e601..4d4289b 100644 --- a/lib/big_keeper/command/feature&hotfix/publish.rb +++ b/lib/big_keeper/command/feature&hotfix/publish.rb @@ -41,15 +41,28 @@ def self.publish(path, user, type) Logger.highlight("Publish branch '#{branch_name}' for 'Home'") + # [CHG] try to fix publish bug # Recover home - DepService.dep_operator(path, user).recover + # DepService.dep_operator(path, user).recover # Push home changes to remote GitService.new.verify_push(path, "publish branch #{branch_name}", branch_name, 'Home') # Rebase Home GitService.new.verify_rebase(path, GitflowType.base_branch(type), 'Home') - `open #{BigkeeperParser.home_pulls()}` + current_cmd = LeanCloudLogger.instance.command + cmds = BigkeeperParser.post_install_command + + if cmds && (cmds.keys.include? current_cmd) + cmd = BigkeeperParser.post_install_command[current_cmd] + if path + Dir.chdir(path) do + system cmd + end + end + else + `open #{BigkeeperParser.home_pulls()}` + end ensure end end diff --git a/lib/big_keeper/command/release.rb b/lib/big_keeper/command/release.rb index f3493b4..e9bcae2 100644 --- a/lib/big_keeper/command/release.rb +++ b/lib/big_keeper/command/release.rb @@ -1,38 +1,46 @@ require 'big_keeper/command/release/home' require 'big_keeper/command/release/module' require 'big_keeper/util/leancloud_logger' -require 'big_keeper/command/release/start' -require 'big_keeper/command/release/finish' require 'big_keeper/util/command_line_util' module BigKeeper def self.release_command - desc 'Gitflow release operations' - command :release do |c| - - c.desc 'release project start' + desc 'Prerelease home project command' + command :prerelease do |c| + c.desc 'Prerelease home project start. (for Andriod)' c.command :start do |start| start.action do |global_options, options, args| path = File.expand_path(global_options[:path]) version = global_options[:ver] user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + LeanCloudLogger.instance.set_command("prerelease/start") + + help_now!('user name is required') if user and user.empty? + raise Logger.error("release version is required") if version == nil modules = args[(0...args.length)] if args.length > 0 - release_start(path, version, user, modules) + prerelease_start(path, version, user, modules) end end - c.desc 'release project finish' + c.desc 'Prerelease home project finish.' c.command :finish do |finish| finish.action do |global_options, options, args| path = File.expand_path(global_options[:path]) version = global_options[:ver] user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + LeanCloudLogger.instance.set_command("prerelease/start") + + help_now!('user name is required') if user and user.empty? + raise Logger.error("release version is required") if version == nil modules = args[(0...args.length)] if args.length > 0 - release_finish(path, version, user, modules) + prerelease_finish(path, version, user, modules) end end + end - c.desc 'Release home project operations' + desc 'Release home project & module.' + command :release do |c| + c.desc 'Release home project & module.' c.command :home do |home| home.desc 'Start release home project' home.command :start do |start| @@ -44,7 +52,8 @@ def self.release_command help_now!('user name is required') if user and user.empty? raise Logger.error("release version is required") if version == nil - release_home_start(path, version, user) + modules = args[(0...args.length)] if args.length > 0 + release_home_start(path, version, user, modules) end end @@ -53,46 +62,29 @@ def self.release_command finish.action do |global_options, options, args| path = File.expand_path(global_options[:path]) version = global_options[:ver] + user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase LeanCloudLogger.instance.set_command("release/home/finish") + help_now!('user name is required') if user and user.empty? raise Logger.error("release version is required") if version == nil - release_home_finish(path, version) + release_home_finish(path, version, user, modules) end end end - c.desc 'release module' + c.desc 'if ignore warning' c.switch [:i,:ignore] + c.desc 'Release single module operations (for iOS)' c.command :module do |m| - m.desc 'Start release module project' - m.command :start do |start| - start.action do |global_options, options, args| - path = File.expand_path(global_options[:path]) - version = global_options[:ver] - user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase - LeanCloudLogger.instance.set_command("release/module/start") - - help_now!('module name is required') if args.length != 1 - raise Logger.error("release version is required") if version == nil - module_name = args[0] - release_module_start(path, version, user, module_name, options[:ignore]) - end - end - - m.desc 'finish release module project' - m.switch [:s,:spec] - m.command :finish do |finish| - finish.action do |global_options, options, args| - path = File.expand_path(global_options[:path]) - version = global_options[:ver] - user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase - LeanCloudLogger.instance.set_command("release/module/finish") - - help_now!('module name is required') if args.length != 1 - raise Logger.error("release version is required") if version == nil - module_name = args[0] - release_module_finish(path, version, user, module_name, options[:spec]) - end + m.action do |global_options, options, args| + LeanCloudLogger.instance.set_command("release/module") + path = File.expand_path(global_options[:path]) + version = global_options[:ver] + user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase + help_now!('module name is required') if args.length == 0 + raise Logger.error("release version is required") if version == nil + modules = args[(0...args.length)] if args.length > 0 + release_module(path, version, user, modules, options[:spec]) end end end diff --git a/lib/big_keeper/command/release/finish.rb b/lib/big_keeper/command/release/finish.rb deleted file mode 100644 index a4190fb..0000000 --- a/lib/big_keeper/command/release/finish.rb +++ /dev/null @@ -1,36 +0,0 @@ -module BigKeeper - def self.release_finish(path, version, user, modules) - BigkeeperParser.parse("#{path}/Bigkeeper") - version = BigkeeperParser.version if version == 'Version in Bigkeeper file' - modules = release_check_changed_modules(path, user) if (modules.nil? || modules.empty?) - - if modules.nil? || modules.empty? - Logger.error('no module need to release') - end - if !CommandLineUtil.double_check("module #{modules} will changed version to #{version}, are you sure?") - Logger.error('release finish interrupt') - end - #stash home - StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') - # delete cache - CacheOperator.new(path).clean() - # checkout develop - GitService.new.verify_checkout_pull(path, 'develop') - - modules.each do |module_name| - Logger.highlight("release start module #{module_name}") - ModuleService.new.release_finish(path, user, modules, module_name, version) - end - - #release home - DepService.dep_operator(path, user).release_home_finish(modules, version) - - # Push home changes to remote - Logger.highlight("Push branch 'develop' for 'Home'...") - GitService.new.verify_push( - path, - "release finish for #{version}", - 'develop', - 'Home') - end -end diff --git a/lib/big_keeper/command/release/home.rb b/lib/big_keeper/command/release/home.rb index 689d97f..01e19fb 100644 --- a/lib/big_keeper/command/release/home.rb +++ b/lib/big_keeper/command/release/home.rb @@ -8,85 +8,37 @@ require 'big_keeper/model/operate_type' module BigKeeper - def self.release_home_start(path, version, user) + def self.prerelease_start(path, version, user, modules) BigkeeperParser.parse("#{path}/Bigkeeper") + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + DepService.dep_operator(path, user).prerelease_start(path, version, user, modules) + end + def self.prerelease_finish(path, version, user, modules) + BigkeeperParser.parse("#{path}/Bigkeeper") version = BigkeeperParser.version if version == 'Version in Bigkeeper file' modules = BigkeeperParser.module_names + DepService.dep_operator(path, user).prerelease_finish(path, version, user, modules) + end - #stash - StashService.new.stash_all(path, GitOperator.new.current_branch(path), user, modules) - - # delete cache - CacheOperator.new(path).clean() - # cache Podfile - CacheOperator.new(path).save('Podfile') - - # check - GitOperator.new.check_diff(path, "develop", "master") - - #checkout release branch - Logger.highlight(%Q(Start to checkout Branch release/#{version})) - if GitOperator.new.current_branch(path) != "release/#{version}" - if GitOperator.new.has_branch(path, "release/#{version}") - GitOperator.new.checkout(path, "release/#{version}") - else - GitflowOperator.new.start(path, version, GitflowType::RELEASE) - GitOperator.new.push_to_remote(path, "release/#{version}") - end - end - - Logger.highlight(%Q(Start to release/#{version})) - # step 2 replace_modules - PodfileOperator.new.replace_all_module_release(path, - user, - modules, - ModuleOperateType::RELEASE) - - # step 3 change Info.plist value - InfoPlistOperator.new.change_version_build(path, version) - - GitService.new.verify_push(path, "Change version to #{version}", "release/#{version}", 'Home') - DepService.dep_operator(path, user).install(modules, OperateType::RELEASE, true) - XcodeOperator.open_workspace(path) + def self.release_home_start(path, version, user, modules) + DepService.dep_operator(path, user).release_home_start(path, version, user, modules) end - def self.release_home_finish(path, version) + def self.release_home_finish(path, version, user, modules) BigkeeperParser.parse("#{path}/Bigkeeper") - version = BigkeeperParser.version if version == 'Version in Bigkeeper file' - Logger.highlight("Start finish release home for #{version}") - if GitOperator.new.has_branch(path, "release/#{version}") - if GitOperator.new.current_branch(path) != "release/#{version}" - GitOperator.new.checkout(path, "release/#{version}") + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + modules = [] + BigkeeperParser.module_names.each do |module_name| + module_full_path = BigkeeperParser.module_full_path(path, user, module_name) + if GitOperator.new.has_branch(module_full_path, "release/#{version}") + Logger.highlight("#{module_name} has release/#{version}") + modules << module_name end - - GitService.new.verify_push(path, "finish release branch", "release/#{version}", 'Home') - - # master - GitOperator.new.checkout(path, "master") - GitOperator.new.merge(path, "release/#{version}") - GitService.new.verify_push(path, "release V#{version}", "master", 'Home') - - GitOperator.new.tag(path, version) - - # release branch - GitOperator.new.checkout(path, "release/#{version}") - CacheOperator.new(path).load('Podfile') - CacheOperator.new(path).clean() - GitOperator.new.commit(path, "reset #{version} Podfile") - GitService.new.verify_push(path, "reset #{version} Podfile", "release/#{version}", 'Home') - - # develop - GitOperator.new.checkout(path, "develop") - GitOperator.new.merge(path, "release/#{version}") - GitService.new.verify_push(path, "merge release/#{version} to develop", "develop", 'Home') - GitOperator.new.check_diff(path, "develop", "master") - - Logger.highlight("Finish release home for #{version}") - else - raise Logger.error("There is no release/#{version} branch, please use release home start first.") end +54322 + DepService.dep_operator(path, user).release_home_finish(path, version, user, modules) end end diff --git a/lib/big_keeper/command/release/module.rb b/lib/big_keeper/command/release/module.rb index 8dc411f..89a2776 100644 --- a/lib/big_keeper/command/release/module.rb +++ b/lib/big_keeper/command/release/module.rb @@ -8,58 +8,67 @@ require 'big_keeper/util/pod_operator' module BigKeeper - def self.release_module_start(path, version, user, module_name, ignore) + def self.release_module(path, version, user, modules, spec) BigkeeperParser.parse("#{path}/Bigkeeper") + if !CommandLineUtil.double_check("modules #{modules} will publish version #{version}, are you sure?") + Logger.error('module prerelease interrupt') + end + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' - module_path = BigkeeperParser.module_full_path(path, user, module_name) - # stash - StashService.new.stash(module_path, GitOperator.new.current_branch(module_path), module_name) + for module_name in modules + module_path = BigkeeperParser.module_full_path(path, user, module_name) - #check - if ignore != true - GitOperator.new.check_merge(module_path, "feature/#{version}") - GitOperator.new.check_diff(module_path, "develop", "master") - Logger.highlight(%Q(#{module_name} release check finish)) - end + StashService.new.stash(module_path, GitOperator.new.current_branch(module_path), module_name) + GitService.new.verify_checkout_pull(module_path, "release/#{version}") + GitService.new.verify_checkout_pull(module_path, "develop") - # checkout to develop branch - Logger.highlight(%Q(Start checkout #{module_name} to Branch develop)) - GitService.new.verify_checkout_pull(module_path, "develop") + has_diff = release_module_pre_check(module_path, module_name, version) - Logger.highlight(%Q(#{module_name} release start finish)) - end + if has_diff + # merge release to develop + branch_name = GitOperator.new.current_branch(module_path) + if branch_name == "develop" + GitOperator.new.merge_no_ff(module_path, "release/#{version}") + GitOperator.new.push_to_remote(module_path, "develop") + else + Logger.error("current branch is not develop branch") + end + end -## release finish - def self.release_module_finish(path, version, user, module_name, spec) - BigkeeperParser.parse("#{path}/Bigkeeper") + # check commit + Logger.error("current branch has unpush files") if GitOperator.new.has_changes(module_path) - version = BigkeeperParser.version if version == 'Version in Bigkeeper file' - module_path = BigkeeperParser.module_full_path(path, user, module_name) + # check out master + Logger.highlight("'#{module_name}' checkout branch to master...") + GitService.new.verify_checkout_pull(module_path, "master") - # check commit - Logger.error("current branch has unpush files") if GitOperator.new.has_changes(module_path) + # merge release to master + GitOperator.new.merge_no_ff(module_path, "release/#{version}") - #修改 podspec 文件 - # TO DO: - advanced to use Regular Expression - has_change = PodfileOperator.new.podspec_change(%Q(#{module_path}/#{module_name}.podspec), version, module_name) - GitService.new.verify_push(module_path, "Change version number", "develop", "#{module_name}") if has_change == true + Logger.highlight(%Q(Merge "release/#{version}" to master)) - # check out master - Logger.highlight("'#{module_name}' checkout branch to master...") - GitService.new.verify_checkout_pull(module_path, "master") + GitOperator.new.push_to_remote(module_path, "master") - Logger.highlight(%Q(Merge develop to master)) - # merge develop to master - GitOperator.new.merge(module_path, "develop") - GitOperator.new.push_to_remote(module_path, "master") + #修改 podspec 文件 + # TO DO: - advanced to use Regular Expression + # has_change = PodfileOperator.new.podspec_change(%Q(#{module_path}/#{module_name}.podspec), version, module_name) + # GitService.new.verify_push(module_path, "Change version number", "master", "#{module_name}") if has_change == true - GitOperator.new.tag(module_path, version) - # pod repo push - if spec == true - PodOperator.pod_repo_push(module_path, module_name, BigkeeperParser.source_spec_path(module_name), version) + GitOperator.new.tag(module_path, version) + # pod repo push + if spec == true + PodOperator.pod_repo_push(module_path, module_name, BigkeeperParser.source_spec_path(module_name), version) + end end end + def self.release_module_pre_check(module_path, module_name, version) + #check + #GitOperator.new.check_merge(module_path, "feature/#{version}") + Logger.highlight(%Q(#{module_name} release pre-check finish)) + return GitOperator.new.check_diff(module_path, "develop", "release/#{version}") + end + end diff --git a/lib/big_keeper/command/release/start.rb b/lib/big_keeper/command/release/start.rb deleted file mode 100644 index f73d10e..0000000 --- a/lib/big_keeper/command/release/start.rb +++ /dev/null @@ -1,78 +0,0 @@ -module BigKeeper - def self.release_start(path, version, user, modules) - BigkeeperParser.parse("#{path}/Bigkeeper") - version = BigkeeperParser.version if version == 'Version in Bigkeeper file' - modules = release_check_changed_modules(path, user) if (modules.nil? || modules.empty?) - - if modules.nil? || modules.empty? - Logger.error('no module need to release') - end - - if !CommandLineUtil.double_check("module #{modules} will changed version to #{version}-SNAPSHOT, are you sure?") - Logger.error('release start interrupt') - end - - #stash home - StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') - # delete cache - CacheOperator.new(path).clean() - # checkout develop - GitService.new.verify_checkout_pull(path, 'develop') - - modules.each do |module_name| - Logger.highlight("release start module #{module_name}") - ModuleService.new.release_start(path, user, modules, module_name, version) - end - - #release home - DepService.dep_operator(path, user).release_home_start(modules, version) - - # Push home changes to remote - Logger.highlight("Push branch 'develop' for 'Home'...") - GitService.new.verify_push( - path, - "release start for #{version}", - 'develop', - 'Home') - end - - def self.release_finish(path, version, user, modules) - BigkeeperParser.parse("#{path}/Bigkeeper") - version = BigkeeperParser.version if version == 'Version in Bigkeeper file' - - #stash home - StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') - # delete cache - CacheOperator.new(path).clean() - # checkout develop - GitService.new.verify_checkout_pull(path, 'develop') - - modules.each do |module_name| - Logger.highlight("release start module #{module_name}") - ModuleService.new.release_finish(path, user, modules, module_name, version) - end - - #release home - DepService.dep_operator(path, user).release_home_finish(modules, version) - - # Push home changes to remote - Logger.highlight("Push branch 'develop' for 'Home'...") - GitService.new.verify_push( - path, - "release finish for #{version}", - 'develop', - 'Home') - end - - def self.release_check_changed_modules(path, user) - changed_modules = [] - BigkeeperParser.parse("#{path}/Bigkeeper") - allModules = BigkeeperParser.module_names - allModules.each do |module_name| - if ModuleService.new.release_check_changed(path, user, module_name) - changed_modules << module_name - end - end - changed_modules - end -end diff --git a/lib/big_keeper/command/spec.rb b/lib/big_keeper/command/spec.rb index 705eeae..df8b42a 100644 --- a/lib/big_keeper/command/spec.rb +++ b/lib/big_keeper/command/spec.rb @@ -42,13 +42,11 @@ def self.spec_command spec.command :sync do | sync| sync.action do |global_options, options, args| LeanCloudLogger.instance.set_command("spec/sync") - path = File.expand_path(global_options[:path]) - version = global_options[:ver] user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase - module_name = args - - spec_sync(path, version, user, module_name) + help_now!('module name is required') if args.length != 1 + module_name = args[0] + spec_sync(path, user, module_name) end end diff --git a/lib/big_keeper/command/spec/sync.rb b/lib/big_keeper/command/spec/sync.rb index 4f536fc..5804123 100644 --- a/lib/big_keeper/command/spec/sync.rb +++ b/lib/big_keeper/command/spec/sync.rb @@ -1,12 +1,39 @@ require 'big_keeper/util/bigkeeper_parser' require 'big_keeper/dependency/dep_type' require 'big_keeper/util/logger' +require 'big_keeper/util/podspec_operator' +require 'big_keeper/util/lockfile_parser' module BigKeeper - def self.spec_sync(path, version, user, module_name) + def self.spec_sync(path, user, module_name) # Parse Bigkeeper file BigkeeperParser.parse("#{path}/Bigkeeper") - Logger.default('Coming soon.') + module_full_path = BigkeeperParser.module_full_path(path, user, module_name) + + detector = PodspecOperator.instance + detector.parse(module_full_path, module_name) + + lock_parser = LockfileParser.instance + lock_parser.parse(path) + + pod_versions = Hash.new + for pod in detector.pod_list + pod_ver = get_pod_version(lock_parser.pods, pod) + if pod_ver != nil + pod_versions = pod_versions.merge(pod_ver) + end + end + + PodfileOperator.new.find_and_lock("#{module_full_path}/Example/Podfile", pod_versions) + Logger.highlight("The Podfile has been changed.") end + + def self.get_pod_version(locks, pod_name) + pod_version = Hash.new + if locks[pod_name] + pod_version = {"#{pod_name}" => locks[pod_name]} + end + end + end diff --git a/lib/big_keeper/dependency/dep_gradle_operator.rb b/lib/big_keeper/dependency/dep_gradle_operator.rb index 28301a7..055d11d 100644 --- a/lib/big_keeper/dependency/dep_gradle_operator.rb +++ b/lib/big_keeper/dependency/dep_gradle_operator.rb @@ -57,18 +57,224 @@ def release_module_finish(modules, module_name, version) VersionConfigOperator.change_version(version_config_file, modules, version) end - def release_home_start(modules, version) - version_config_file = "#{@path}/doc/config/version-config.gradle" + def open + end + + def release_check_changed_modules(path, user) + changed_modules = [] + BigkeeperParser.parse("#{path}/Bigkeeper") + allModules = BigkeeperParser.module_names + allModules.each do |module_name| + if ModuleService.new.release_check_changed(path, user, module_name) + changed_modules << module_name + end + end + changed_modules + end + +## release cmd + def release_home_start(path, version, user, modules) + BigkeeperParser.parse("#{path}/Bigkeeper") + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + modules = BigkeeperParser.module_names + + if modules.nil? || modules.empty? + Logger.default('no module need to release') + end + + #stash home + StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') + # delete cache + CacheOperator.new(path).clean() + # check + GitOperator.new.check_diff(path, "develop", "master") + + #checkout release branch + Logger.highlight(%Q(Start to checkout Home Branch release/#{version})) + + GitService.new.verify_checkout(path, "release/#{version}") + + raise Logger.error("Chechout release/#{version} failed.") unless GitOperator.new.current_branch(path) == "release/#{version}" + + Logger.highlight(%Q(Finish to release/#{version} for home project)) + + if !modules.nil? && !modules.empty? + modules.each do |module_name| + Logger.highlight("release checkout release/#{version} for #{module_name}") + module_full_path = BigkeeperParser.module_full_path(path, user, module_name) + + if GitOperator.new.has_branch(module_full_path, "release/#{version}") + Logger.highlight("#{module_name} has release/#{version}") + GitService.new.verify_checkout_pull(module_full_path, "release/#{version}") + else + Logger.highlight("#{module_name} dont have release/#{version}") + GitService.new.verify_checkout(module_full_path, "release/#{version}") + Logger.highlight("Push branch release/'#{version}' for #{module_name}...") + GitOperator.new.push_to_remote(module_full_path, "release/#{version}") + end + end + end + + Logger.highlight("Home project release home start finished") + end + + def release_home_finish(path, version, user, modules) + BigkeeperParser.parse("#{path}/Bigkeeper") + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + + if modules.nil? || modules.empty? + Logger.default('no module need to release') + end + + #stash home + StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') + # delete cache + CacheOperator.new(path).clean() + # check + GitOperator.new.check_diff(path, "develop", "master") + + for module_name in modules + module_path = BigkeeperParser.module_full_path(path, user, module_name) + + StashService.new.stash(module_path, GitOperator.new.current_branch(module_path), module_name) + GitService.new.verify_checkout_pull(module_path, "release/#{version}") + GitService.new.verify_checkout_pull(module_path, "develop") + + has_diff = GitOperator.new.check_diff(module_path, "develop", "release/#{version}") + if has_diff + branch_name = GitOperator.new.current_branch(module_path) + if branch_name == "develop" + GitOperator.new.merge_no_ff(module_path, "release/#{version}") + GitOperator.new.push_to_remote(module_path, "develop") + else + Logger.error("current branch is not develop branch") + end + end + + # check out master + Logger.highlight("'#{module_name}' checkout branch to master...") + GitService.new.verify_checkout_pull(module_path, "master") + + # merge release to master + GitOperator.new.merge_no_ff(module_path, "release/#{version}") + Logger.highlight(%Q(Merge "release/#{version}" to master)) + GitOperator.new.push_to_remote(module_path, "master") + end + + if GitOperator.new.has_branch(path, "release/#{version}") + + GitService.new.verify_checkout_pull(path, "release/#{version}") + + PodfileOperator.new.replace_all_module_release(path, user, modules, ModuleOperateType::RELEASE) + + GitService.new.verify_push(path, "finish release branch", "release/#{version}", 'Home') + + # master + GitService.new.verify_checkout(path, "master") + GitOperator.new.merge(path, "release/#{version}") + GitService.new.verify_push(path, "release V#{version}", "master", 'Home') + + GitOperator.new.tag(path, version) + + # release branch + GitOperator.new.checkout(path, "release/#{version}") + CacheOperator.new(path).load('Podfile') + CacheOperator.new(path).clean() + GitOperator.new.commit(path, "reset #{version} Podfile") + GitService.new.verify_push(path, "reset #{version} Podfile", "release/#{version}", 'Home') + + # develop + GitOperator.new.checkout(path, "develop") + GitOperator.new.merge(path, "release/#{version}") + GitService.new.verify_push(path, "merge release/#{version} to develop", "develop", 'Home') + GitOperator.new.check_diff(path, "develop", "master") + + Logger.highlight("Finish release home for #{version}") + else + raise Logger.error("There is no release/#{version} branch, please use release home start first.") + end + + end + +## prerelease cmd + def prerelease_start(path, version, user, modules) + BigkeeperParser.parse("#{path}/Bigkeeper") + + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + modules = BigkeeperParser.module_names if (modules.nil? || modules.empty?) + modules = release_check_changed_modules(path, user) if (modules.nil? || modules.empty?) + if modules.nil? || modules.empty? + Logger.error('no module need to release') + end + + if !CommandLineUtil.double_check("module #{modules} will changed version to #{version}-SNAPSHOT, are you sure?") + Logger.error('release start interrupt') + end + + #stash home + StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') + # delete cache + CacheOperator.new(path).clean() + # checkout develop + GitService.new.verify_checkout_pull(path, 'develop') + + modules.each do |module_name| + Logger.highlight("release start module #{module_name}") + module_full_path = BigkeeperParser.module_full_path(path, user, module_name) + ModuleService.new.release_start(path, user, modules, module_name, version) + GitService.new.verify_push(module_full_path, "Change version to #{version}-SNAPSHOT", "develop", module_name) + end + + #release home + DepService.dep_operator(path, user).prerelease_home_start(path, version, user, modules) + + # Push home changes to remote + Logger.highlight("Push branch 'develop' for 'Home'...") + GitService.new.verify_push( + path, + "release start for #{version}", + 'develop', + 'Home') + end + + def prerelease_finish(path, version, user, modules) + BigkeeperParser.parse("#{path}/Bigkeeper") + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + + #stash home + StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') + # delete cache + CacheOperator.new(path).clean() + # checkout develop + GitService.new.verify_checkout_pull(path, 'develop') + + modules.each do |module_name| + Logger.highlight("release start module #{module_name}") + ModuleService.new.release_finish(path, user, modules, module_name, version) + end + + # release home + DepService.dep_operator(path, user).prerelease_home_finish(path, version, user, modules) + + # Push home changes to remote + Logger.highlight("Push branch 'develop' for 'Home'...") + GitService.new.verify_push( + path, + "release finish for #{version}", + 'develop', + 'Home') + end + + def prerelease_home_start(path, version, user, modules) + version_config_file = "#{path}/doc/config/version-config.gradle" version = "#{version}-SNAPSHOT" unless version.include?'SNAPSHOT' VersionConfigOperator.change_version(version_config_file, modules, version) end - def release_home_finish(modules, version) + def prerelease_home_finish(path, version, user, modules) version_config_file = "#{@path}/doc/config/version-config.gradle" VersionConfigOperator.change_version(version_config_file, modules, version) end - def open - end end end diff --git a/lib/big_keeper/dependency/dep_operator.rb b/lib/big_keeper/dependency/dep_operator.rb index cbe723c..ac3cfa6 100644 --- a/lib/big_keeper/dependency/dep_operator.rb +++ b/lib/big_keeper/dependency/dep_operator.rb @@ -21,6 +21,22 @@ def update_module_config(module_name, module_operate_type) raise "You should override this method in subclass." end + def prerelease_start(path, version, user, modules) + raise "You should override this method in subclass." + end + + def prerelease_finish(path, version, user, modules) + raise "You should override this method in subclass." + end + + def prerelease_home_start(path, version, user, modules) + raise "You should override this method in subclass." + end + + def prerelease_home_finish(path, version, user, modules) + raise "You should override this method in subclass." + end + def release_module_start(modules, module_name, version) raise "You should override this method in subclass." end @@ -29,11 +45,11 @@ def release_module_finish(modules, module_name, version) raise "You should override this method in subclass." end - def release_home_start(modules, version) + def release_home_start(path, version, user, modules) raise "You should override this method in subclass." end - def release_home_finish(modules, version) + def release_home_finish(path, version, user, modules) raise "You should override this method in subclass." end diff --git a/lib/big_keeper/dependency/dep_pod_operator.rb b/lib/big_keeper/dependency/dep_pod_operator.rb index be4b963..f1f6971 100644 --- a/lib/big_keeper/dependency/dep_pod_operator.rb +++ b/lib/big_keeper/dependency/dep_pod_operator.rb @@ -20,10 +20,10 @@ def recover def update_module_config(module_name, module_operate_type) file = "#{@path}/Podfile" - temp_file = Tempfile.new('.Podfile.tmp') + temp_file = Tempfile.new('.Podfile.tmp', :encoding => 'UTF-8') begin - File.open(file, 'r') do |file| + File.open(file, 'r', :encoding => 'UTF-8') do |file| file.each_line do |line| temp_file.puts generate_module_config(line, module_name, module_operate_type) end @@ -84,9 +84,9 @@ def generate_module_config(line, module_name, module_operate_type) def origin_config_of_module(module_name) origin_config = '' - File.open("#{@path}/.bigkeeper/Podfile", 'r') do |file| + File.open("#{@path}/.bigkeeper/Podfile", 'r', :encoding => 'UTF-8') do |file| file.each_line do |line| - if line =~ /(\s*)pod(\s*)('|")#{module_name}('|")([\s\S]*)/ + if line =~ /(\s*)pod(\s*)('|")#{module_name}((\/[_a-zA-Z0-9]+)?)('|")([\s\S]*)/ origin_config = line break end @@ -102,7 +102,7 @@ def find_lastest_tag(module_name) tags_spec_list = Array.new tags_module_list = Array.new - IO.popen("find /Users/#{username}/.cocoapods/repos -type d -name #{module_name}") do |io| + IO.popen("find /Users/#{username}/.cocoapods/repos/#{BigkeeperParser.source_spec_name(module_name)} -type d -name #{module_name}") do |io| io.each do |line| tags_repos_pwd.push(line) if line.include? "#{module_name}" end @@ -125,6 +125,106 @@ def find_lastest_tag(module_name) end end + def release_home_start(path, version, user, modules) + BigkeeperParser.parse("#{path}/Bigkeeper") + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + + if modules.nil? || modules.empty? + Logger.default('no module need to release') + end + + #stash home + StashService.new.stash(path, GitOperator.new.current_branch(path), 'home') + # delete cache + CacheOperator.new(path).clean() + # cache Podfile + CacheOperator.new(path).save('Podfile') + # checkout develop + GitService.new.verify_checkout_pull(path, 'develop') + # check + GitOperator.new.check_diff(path, "develop", "master") + + #checkout release branch + Logger.highlight(%Q(Start to checkout Home Branch release/#{version})) + + GitService.new.verify_checkout(path, "release/#{version}") + + raise Logger.error("Chechout release/#{version} failed.") unless GitOperator.new.current_branch(path) == "release/#{version}" + + Logger.highlight(%Q(Finish to release/#{version} for home project)) + + if !modules.nil? && !modules.empty? + modules.each do |module_name| + Logger.highlight("release checkout release/#{version} for #{module_name}") + module_full_path = BigkeeperParser.module_full_path(path, user, module_name) + + if GitOperator.new.has_branch(module_full_path, "release/#{version}") + Logger.highlight("#{module_name} has release/#{version}") + GitService.new.verify_checkout_pull(module_full_path, "release/#{version}") + else + Logger.highlight("#{module_name} dont have release/#{version}") + ModuleService.new.release_start(path, user, modules, module_name, version) + Logger.highlight("Push branch release/'#{version}' for #{module_name}...") + GitOperator.new.push_to_remote(module_full_path, "release/#{version}") + end + + DepService.dep_operator(path, user).update_module_config( + module_name, + ModuleOperateType::FINISH) + end + end + + # step 3 change Info.plist value + InfoPlistOperator.new.change_version_build(path, version) + + GitService.new.verify_push(path, "Change version to #{version}", "release/#{version}", 'Home') + DepService.dep_operator(path, user).install(modules, OperateType::RELEASE, true) + XcodeOperator.open_workspace(path) + end + + def release_module_start(modules, module_name, version) + module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name) + GitService.new.verify_checkout(module_full_path, "release/#{version}") + end + + def release_home_finish(path, version, user, modules) + BigkeeperParser.parse("#{path}/Bigkeeper") + version = BigkeeperParser.version if version == 'Version in Bigkeeper file' + + if GitOperator.new.has_branch(path, "release/#{version}") + + GitService.new.verify_checkout_pull(path, "release/#{version}") + + PodfileOperator.new.replace_all_module_release(path, user, modules, ModuleOperateType::RELEASE) + + GitService.new.verify_push(path, "finish release branch", "release/#{version}", 'Home') + + # master + GitService.new.verify_checkout(path, "master") + GitOperator.new.merge(path, "release/#{version}") + GitService.new.verify_push(path, "release V#{version}", "master", 'Home') + + GitOperator.new.tag(path, version) + + # release branch + GitOperator.new.checkout(path, "release/#{version}") + CacheOperator.new(path).load('Podfile') + CacheOperator.new(path).clean() + GitOperator.new.commit(path, "reset #{version} Podfile") + GitService.new.verify_push(path, "reset #{version} Podfile", "release/#{version}", 'Home') + + # develop + GitOperator.new.checkout(path, "develop") + GitOperator.new.merge(path, "release/#{version}") + GitService.new.verify_push(path, "merge release/#{version} to develop", "develop", 'Home') + GitOperator.new.check_diff(path, "develop", "master") + + Logger.highlight("Finish release home for #{version}") + else + raise Logger.error("There is no release/#{version} branch, please use release home start first.") + end + end + private :generate_module_config, :origin_config_of_module, :find_lastest_tag end end diff --git a/lib/big_keeper/model/operate_type.rb b/lib/big_keeper/model/operate_type.rb index 40114b2..f3536c5 100644 --- a/lib/big_keeper/model/operate_type.rb +++ b/lib/big_keeper/model/operate_type.rb @@ -26,5 +26,6 @@ module ModuleOperateType FINISH = 3 PUBLISH = 4 RELEASE = 5 + RELEASE_START = 6 end end diff --git a/lib/big_keeper/service/git_service.rb b/lib/big_keeper/service/git_service.rb index 9535b05..6f8a85f 100644 --- a/lib/big_keeper/service/git_service.rb +++ b/lib/big_keeper/service/git_service.rb @@ -114,8 +114,9 @@ def current_branch_type(path) def branchs_with_type(path, type) branchs = [] Dir.chdir(path) do - IO.popen('git branch -r') do | io | + IO.popen('git branch -a') do | io | io.each do | line | + branchs << line.gsub('\n', '') if line.include?('develop') branchs << line.gsub(/\s/, '') if line =~ /[\s\S]*#{GitflowType.name(type)}*/ end end @@ -168,7 +169,7 @@ def verify_push(path, comment, branch_name, name) git.push_to_remote(path, branch_name) end - GitOperator.new.check_push_success(path, branch_name, "origin/#{branch_name}") + GitOperator.new.check_push_success(path, branch_name, "#{GitOperator.remote_local_name(path)}/#{branch_name}") else Logger.default("Nothing to push for '#{name}'.") end diff --git a/lib/big_keeper/service/module_service.rb b/lib/big_keeper/service/module_service.rb index e40199b..d91faec 100644 --- a/lib/big_keeper/service/module_service.rb +++ b/lib/big_keeper/service/module_service.rb @@ -87,7 +87,19 @@ def publish(path, user, module_name, home_branch_name, type) module_full_path = BigkeeperParser.module_full_path(path, user, module_name) GitService.new.verify_push(module_full_path, "publish branch #{home_branch_name}", home_branch_name, module_name) - `open #{BigkeeperParser.module_pulls(module_name)}` + current_cmd = LeanCloudLogger.instance.command + cmds = BigkeeperParser.post_install_command + + if cmds && (cmds.keys.include? current_cmd) + cmd = BigkeeperParser.post_install_command[current_cmd] + if module_full_path + Dir.chdir(module_full_path) do + system cmd + end + end + else + `open #{BigkeeperParser.module_pulls(module_name)}` + end ModuleCacheOperator.new(path).del_git_module(module_name) end @@ -183,14 +195,6 @@ def release_start(path, user, modules, module_name, version) # checkout develop GitService.new.verify_checkout_pull(module_full_path, 'develop') DepService.dep_operator(path, user).release_module_start(modules, module_name, version) - - # Push home changes to remote - Logger.highlight("Push branch 'develop' for #{module_name}...") - GitService.new.verify_push( - module_full_path, - "release start for #{version}", - 'develop', - "#{module_name}") end def release_finish(path, user, modules, module_name, version) diff --git a/lib/big_keeper/util/bigkeeper_parser.rb b/lib/big_keeper/util/bigkeeper_parser.rb index 4f11d99..747cb1e 100644 --- a/lib/big_keeper/util/bigkeeper_parser.rb +++ b/lib/big_keeper/util/bigkeeper_parser.rb @@ -40,14 +40,24 @@ def self.param(key, value) yield if block_given? end + def self.post_install + BigkeeperParser.parse_post_install + yield if block_given? + end + + def self.cmd(key, value) + BigkeeperParser.parse_command(key, value) + yield if block_given? + end + # Bigkeeper file parser class BigkeeperParser @@config = {} @@current_user = '' def self.parse(bigkeeper) + @@config = {} if @@config.empty? - Logger.error("Can't find a Bigkeeper file in current directory.") if !FileOperator.definitely_exists?(bigkeeper) content = File.read(bigkeeper, :encoding => 'UTF-8') @@ -59,6 +69,8 @@ def self.parse(bigkeeper) content.gsub!(/modules\s/, 'BigKeeper::modules ') content.gsub!(/configs\s/, 'BigKeeper::configs ') content.gsub!(/param\s/, 'BigKeeper::param ') + content.gsub!(/post_install\s/, 'BigKeeper::post_install ') + content.gsub!(/cmd\s/, 'BigKeeper::cmd ') eval content end end @@ -133,6 +145,14 @@ def self.parse_param(key, value) @@config[:configs] = @@config[:configs].merge(key => value) end + def self.parse_post_install + @@config[:post_install] = {} + end + + def self.parse_command(key, value) + @@config[:post_install] = @@config[:post_install].merge(key => value) + end + def self.version @@config[:version] end @@ -175,6 +195,10 @@ def self.sources @@config[:source].keys end + def self.post_install_command + @@config[:post_install] + end + def self.global_configs(key) if @@config[:configs] == nil return @@ -183,6 +207,8 @@ def self.global_configs(key) end def self.module_full_path(home_path, user_name, module_name) + Logger.error("Can't find a Pod named #{module_name} in current directory.") unless @@config[:modules].invert.has_value?(module_name) + if @@config[:users] \ && @@config[:users][user_name] \ && @@config[:users][user_name][:mods] \ @@ -206,7 +232,6 @@ def self.module_path(user_name, module_name) && @@config[:users][user_name][:mods][module_name][:path] File.expand_path(@@config[:users][user_name][:mods][module_name][:path]) else - p @@config[:modules][module_name] if @@config[:modules][module_name][:alias] "#{home_modules_workspace}#{@@config[:modules][module_name][:alias]}" else diff --git a/lib/big_keeper/util/cache_operator.rb b/lib/big_keeper/util/cache_operator.rb index 9e9189d..d7682fa 100644 --- a/lib/big_keeper/util/cache_operator.rb +++ b/lib/big_keeper/util/cache_operator.rb @@ -15,7 +15,9 @@ def save(file) end def load(file) - FileUtils.cp("#{@cache_path}/#{file}", "#{@path}/#{file}"); + if File.exist?(@cache_path) + FileUtils.cp("#{@cache_path}/#{file}", "#{@path}/#{file}"); + end end def clean @@ -32,7 +34,7 @@ def initialize(path) FileUtils.mkdir_p(@cache_path) unless File.exist?(@cache_path) if File.exist?("#{@cache_path}/module.cache") - file = File.open("#{@cache_path}/module.cache", 'r') + file = File.open("#{@cache_path}/module.cache", 'r', :encoding => 'UTF-8') @modules = JSON.load(file.read(), :encoding => 'UTF-8') file.close else @@ -110,7 +112,7 @@ def clean_modules end def cache_modules - file = File.new("#{@cache_path}/module.cache", 'w') + file = File.new("#{@cache_path}/module.cache", 'w', :encoding => 'UTF-8') file << @modules.to_json file.close end diff --git a/lib/big_keeper/util/file_operator.rb b/lib/big_keeper/util/file_operator.rb index a8fc8ba..20c8112 100644 --- a/lib/big_keeper/util/file_operator.rb +++ b/lib/big_keeper/util/file_operator.rb @@ -29,5 +29,5 @@ def find_all_code_file(path) return header_file_list+m_file_list end end - + end diff --git a/lib/big_keeper/util/git_operator.rb b/lib/big_keeper/util/git_operator.rb index a762927..f75ed44 100644 --- a/lib/big_keeper/util/git_operator.rb +++ b/lib/big_keeper/util/git_operator.rb @@ -51,13 +51,13 @@ def checkout(path, branch_name) def fetch(path) Dir.chdir(path) do - `git fetch origin` + `git fetch #{GitOperator.remote_local_name(path)}` end end def rebase(path, branch_name) Dir.chdir(path) do - `git rebase origin/#{branch_name}` + `git rebase #{GitOperator.remote_local_name(path)}/#{branch_name}` end end @@ -76,14 +76,15 @@ def commit(path, message) def push_to_remote(path, branch_name) Dir.chdir(path) do - `git push -u origin #{branch_name}` + `git push -u #{GitOperator.remote_local_name(path)} #{branch_name}` end - GitOperator.new.check_push_success(path, branch_name, "origin/#{branch_name}") + GitOperator.new.check_push_success(path, branch_name, "#{GitOperator.remote_local_name(path)}/#{branch_name}") end def pull(path) Dir.chdir(path) do - `git pull` + # git pull + `git pull #{GitOperator.remote_local_name(path)} #{GitOperator.new.current_branch(path)}` end end @@ -122,7 +123,7 @@ def del_local(path, branch_name) def del_remote(path, branch_name) Dir.chdir(path) do - `git push origin --delete #{branch_name}` + `git push #{GitOperator.remote_local_name(path)} --delete #{branch_name}` end end @@ -184,7 +185,7 @@ def check_merge(path, condition) def check_remote_branch_diff(path, branch, compare_branch) fetch(path) compare_branch_commits = Array.new - IO.popen("cd '#{path}';git log --left-right #{branch}...origin/#{compare_branch} --pretty=oneline") do |io| + IO.popen("cd '#{path}';git log --left-right #{branch}...#{GitOperator.remote_local_name(path)}/#{compare_branch} --pretty=oneline") do |io| io.each do |line| compare_branch_commits.push(line) unless (line.include? '>') && (line.include? "Merge branch \'#{branch}\'") end @@ -196,6 +197,17 @@ def check_remote_branch_diff(path, branch, compare_branch) end end + def self.remote_local_name(path) + Dir.chdir(path) do + IO.popen("git remote") do |io| + io.each do |line| + Logger.error("Check git remote setting.") if line.length == 0 + return line.chomp + end + end + end + end + # TODO: 需要改造,util方法不应该有业务逻辑 def check_diff(path, branch, compare_branch) compare_branch_commits = Array.new @@ -208,15 +220,27 @@ def check_diff(path, branch, compare_branch) compare_branch_commits.map { |item| Logger.default(item) } - Logger.error("#{compare_branch} branch has commit doesn't committed in #{branch}, please check") + Logger.highlight("#{compare_branch} branch has commit doesn't committed in #{branch}, please check") + return false else Logger.highlight("#{compare_branch} branch doesn't have commit before #{branch}") + return true end end def merge(path, branch_name) - IO.popen("cd '#{path}'; git merge #{branch_name}") do |line| - Logger.error("Merge conflict in #{branch_name}") if line.include? 'Merge conflict' + IO.popen("cd '#{path}'; git merge #{branch_name}") do |io| + io.each do |line| + Logger.error("Merge conflict in #{line}") if line.include? 'Merge conflict' + end + end + end + + def merge_no_ff(path, branch_name) + IO.popen("cd '#{path}'; git merge #{branch_name} --no-ff") do |io| + io.each do |line| + Logger.error("Merge conflict in #{line}") if line.include? 'Merge conflict' + end end end diff --git a/lib/big_keeper/util/gradle_file_operator.rb b/lib/big_keeper/util/gradle_file_operator.rb index b829c78..62c8a6c 100644 --- a/lib/big_keeper/util/gradle_file_operator.rb +++ b/lib/big_keeper/util/gradle_file_operator.rb @@ -46,7 +46,7 @@ def update_module_settings(module_name, settings_file, depend_modules) dest_path = File.dirname(big_settings_file) FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path) - file = File.new(big_settings_file, 'w') + file = File.new(big_settings_file, 'w', :encoding => 'UTF-8') begin file << result file.close @@ -58,9 +58,9 @@ def update_module_settings(module_name, settings_file, depend_modules) return end - temp_file = Tempfile.new('.settings.gradle.tmp') + temp_file = Tempfile.new('.settings.gradle.tmp', :encoding => 'UTF-8') begin - File.open(settings_file, 'r') do |file| + File.open(settings_file, 'r', :encoding => 'UTF-8') do |file| file.each_line do |line| temp_file.puts(line) end @@ -92,7 +92,7 @@ def update_module_build(build_file, module_name, depend_modules, version_name) dest_path = File.dirname(big_build_file) FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path) - file = File.new(big_build_file, 'w') + file = File.new(big_build_file, 'w', :encoding => 'UTF-8') begin file << result file.close @@ -295,7 +295,7 @@ def recover_bigkeeper_config_file(bigkeeper_config_file) if !File.exist?(bigkeeper_config_file) return end - temp_file = Tempfile.new('.bigkeeper_config.tmp') + temp_file = Tempfile.new('.bigkeeper_config.tmp', :encoding => 'UTF-8') isBigkeeperScript = false isBigkeeperBackupScript = false begin @@ -310,7 +310,7 @@ def recover_bigkeeper_config_file(bigkeeper_config_file) elsif line.include?('bigkeeper config backup end') isBigkeeperBackupScript = false elsif isBigkeeperBackupScript - temp_file.puts(line.gsub('//','')) + temp_file.puts(line.sub('//','')) elsif !isBigkeeperScript temp_file.puts(line) end diff --git a/lib/big_keeper/util/list_generator.rb b/lib/big_keeper/util/list_generator.rb index e837cc8..901d819 100644 --- a/lib/big_keeper/util/list_generator.rb +++ b/lib/big_keeper/util/list_generator.rb @@ -51,7 +51,7 @@ def self.to_json(home_branches, module_info_list, version) branch_dic["is_remote"] = true end - if home_branch_name =~ /^origin\// + if home_branch_name =~ /^#{GitOperator.remote_local_name(path)}\// home_branch_name = $~.post_match end diff --git a/lib/big_keeper/util/lockfile_parser.rb b/lib/big_keeper/util/lockfile_parser.rb index 89d2022..2955322 100644 --- a/lib/big_keeper/util/lockfile_parser.rb +++ b/lib/big_keeper/util/lockfile_parser.rb @@ -36,10 +36,10 @@ def parse(main_path) $mode = 'PODFILE CHECKSUM' else if $mode == 'PODS' - deal_pod(sentence.strip.delete('\n')) + deal_pod(sentence.strip.chomp) end if $mode == 'SPEC CHECKSUMS' - deal_spec(sentence.strip.delete('\n')) + deal_spec(sentence.strip.chomp) end end end @@ -105,10 +105,10 @@ def deal_pod(s) #处理SPEC CHECKSUMS def deal_spec(s) - if /: +/ =~ s + if /: +/ =~ s dependency = $~.pre_match.strip self.dependencies << dependency unless self.dependencies.include?(dependency) - end + end end def get_lock_podname(sentence) #获得lock pod名称 diff --git a/lib/big_keeper/util/podfile_operator.rb b/lib/big_keeper/util/podfile_operator.rb index 0bef2b8..fd1f78a 100644 --- a/lib/big_keeper/util/podfile_operator.rb +++ b/lib/big_keeper/util/podfile_operator.rb @@ -20,9 +20,9 @@ def has(podfile, module_name) def generate_pod_config(pod_name, version, comment) module_config = '' if comment != nil - module_config = " pod '#{pod_name}' , '#{version}' # #{comment}" + module_config = " pod '#{pod_name}', '#{version}' # #{comment}" else - module_config = " pod '#{pod_name}' , '#{version}'" + module_config = " pod '#{pod_name}', '#{version}'" end end @@ -36,7 +36,7 @@ def replace_all_module_release(path, user, module_names, version) end def find_and_lock(podfile, dictionary) - temp_file = Tempfile.new('.Podfile.tmp') + temp_file = Tempfile.new('.Podfile.tmp', :encoding => 'UTF-8') begin File.open(podfile, 'r') do |file| file.each_line do |line| @@ -50,6 +50,7 @@ def find_and_lock(podfile, dictionary) end end if !dictionary.empty? + temp_file.puts '' temp_file.puts 'def sub_dependency' dictionary.keys.each do |sub_pod| temp_file.puts generate_pod_config(sub_pod, dictionary[sub_pod], 'bigkeeper') @@ -65,9 +66,9 @@ def find_and_lock(podfile, dictionary) end def find_and_upgrade(podfile, dictionary) - temp_file = Tempfile.new('.Podfile.tmp') + temp_file = Tempfile.new('.Podfile.tmp', :encoding => 'UTF-8') begin - File.open(podfile, 'r') do |file| + File.open(podfile, 'r', :encoding => 'UTF-8') do |file| file.each_line do |line| pod_model = PodfileParser.get_pod_model(line) if pod_model != nil && pod_model.name != nil && dictionary[pod_model.name] != nil @@ -87,10 +88,10 @@ def find_and_upgrade(podfile, dictionary) end def podspec_change(podspec_file, version, module_name) - temp_file = Tempfile.new(".#{module_name}.podspec") + temp_file = Tempfile.new(".#{module_name}.podspec", :encoding => 'UTF-8') has_change = false begin - File.open(podspec_file, 'r') do |file| + File.open(podspec_file, 'r', :encoding => 'UTF-8') do |file| file.each_line do |line| if line.include?("s.version") temp_line = line diff --git a/lib/big_keeper/util/podspec_operator.rb b/lib/big_keeper/util/podspec_operator.rb new file mode 100644 index 0000000..d0d4079 --- /dev/null +++ b/lib/big_keeper/util/podspec_operator.rb @@ -0,0 +1,55 @@ +require 'tempfile' +require 'fileutils' +require 'big_keeper/dependency/dep_type' +require 'big_keeper/util/podfile_detector' + +module BigKeeper + # Operator for podspec file + class PodspecOperator + include Singleton + attr_accessor :module_list, :main_path, :pod_list + $unlock_pod_list = [] + $modify_pod_list = {} + + def initialize + @module_list = BigkeeperParser.module_names + @pod_list = [] + end + + def parse(path, module_name) + @main_path = path + podspec_lines = File.readlines("#{@main_path}/#{module_name}.podspec", :encoding => 'UTF-8') + Logger.highlight("Analyzing Podspec...") unless podspec_lines.size.zero? + podspec_lines.collect do |sentence| + if /dependency / =~ sentence + pod_name = get_pod_name(sentence) + @pod_list << pod_name + end + end + end + + def get_pod_name(sentence) + pod_model = deal_podfile_line(sentence) + if pod_model != nil + return pod_model.chomp.gsub("'", "") + end + end + + def deal_podfile_line(sentence) + pod_name = '' + if sentence.strip.include?('dependency ') + pod_dep = sentence.split('dependency ') + if pod_dep.size > 1 + pod_names = pod_dep[1].split(',') + if pod_names.size > 1 + pod_name = pod_names[0] + else + pod_name = pod_dep[1] + end + end + pod_name + end + end + + end +end diff --git a/lib/big_keeper/version.rb b/lib/big_keeper/version.rb index 53f132a..9a14612 100644 --- a/lib/big_keeper/version.rb +++ b/lib/big_keeper/version.rb @@ -1,3 +1,3 @@ module BigKeeper - VERSION = "0.9.11" + VERSION = "0.9.18" end