From 4c9181f8ddfc49496c1ca6c2880f580e57aa4136 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Wed, 6 Jan 2021 15:48:03 -0800 Subject: [PATCH] chore: Attempt to fix the releaser (#2218) --- Rakefile | 9 ++++++++- rakelib/releaser.rb | 29 ++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Rakefile b/Rakefile index b9559d5ff..070e6c845 100644 --- a/Rakefile +++ b/Rakefile @@ -74,7 +74,14 @@ def load_env_vars filename = "#{ENV['KOKORO_GFILE_DIR']}/ruby_env_vars.json" raise "#{filename} is not a file" unless File.file? filename env_vars = JSON.parse File.read(filename) - env_vars.each { |k, v| ENV[k] ||= v } + env_vars.each do |k, v| + if ENV[k] + puts "Ignoring #{k} because it is already set" + else + puts "Setting #{k}" + end + ENV[k] ||= v + end end def header str, token = "#" diff --git a/rakelib/releaser.rb b/rakelib/releaser.rb index ec6fe232e..a0c40a2cc 100644 --- a/rakelib/releaser.rb +++ b/rakelib/releaser.rb @@ -37,9 +37,11 @@ class Releaser def publish_gem configure_rubygems_api_token - bundle_dir do + Dir.chdir(gem_dir) do FileUtils.rm_rf("pkg") - execute "bundle exec rake build" + isolate_bundle do + execute "bundle exec rake build" + end built_gem_path = "pkg/#{gem_name}-#{gem_version}.gem" raise "Failed to build #{built_gem_path}" unless File.file?(built_gem_path) if dry_run? @@ -53,10 +55,12 @@ class Releaser end def publish_docs - bundle_dir do + Dir.chdir(gem_dir) do FileUtils.rm_rf("doc") FileUtils.rm_rf(".yardoc") - execute "bundle exec rake yard" + isolate_bundle do + execute "bundle exec rake yard" + end Dir.chdir("doc") do execute "python3 -m docuploader create-metadata" \ " --name #{gem_name}" \ @@ -117,25 +121,24 @@ class Releaser Gems.configure do |config| config.key = rubygems_api_token end + puts "Configured rubygems api token" end end - def bundle_dir + def isolate_bundle block = proc do execute "bundle update" unless @bundle_updated @bundle_updated = true yield end - Dir.chdir(gem_dir) do - if defined?(Bundler) - if Bundler.respond_to?(:with_unbundled_env) - Bundler.with_unbundled_env(&block) - else - Bundler.with_clean_env(&block) - end + if defined?(Bundler) + if Bundler.respond_to?(:with_unbundled_env) + Bundler.with_unbundled_env(&block) else - block.call + Bundler.with_clean_env(&block) end + else + block.call end end