diff --git a/Gemfile.lock b/Gemfile.lock index b68989a..1f83b5a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: perf_check (0.10.5) + bundler colorize diffy rake @@ -17,20 +18,20 @@ GEM pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) - rake (12.3.2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.4) + rake (13.0.1) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.1) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.2) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) PLATFORMS ruby @@ -41,4 +42,4 @@ DEPENDENCIES rspec BUNDLED WITH - 1.17.2 + 1.17.3 diff --git a/bin/perf_check b/bin/perf_check index 52a19be..4dee8f9 100755 --- a/bin/perf_check +++ b/bin/perf_check @@ -1,6 +1,11 @@ #!/usr/bin/env ruby -require 'perf_check' +begin + require 'perf_check' +rescue LoadError + $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) + retry +end app_root = begin diff --git a/lib/perf_check.rb b/lib/perf_check.rb index 0b995ef..2acdf60 100644 --- a/lib/perf_check.rb +++ b/lib/perf_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'benchmark' require 'bundler' require 'colorize' @@ -7,6 +9,7 @@ require 'net/http' require 'open3' require 'ostruct' +require 'securerandom' class PerfCheck autoload :VERSION, 'perf_check/version' @@ -89,9 +92,12 @@ def run def bundle Bundler.with_clean_env do execute( + { 'BUNDLE_APP_CONFIG' => bundle_app_config_path }, 'bundle', 'install', '--frozen', '--retry', '3', '--jobs', '3', fail_with: BundleError ) + ensure + FileUtils.rm_rf(File.join(app_root, bundle_app_config_path)) end end @@ -105,6 +111,12 @@ def execute(*args, fail_with: nil) private + # Returns a random bundle config path so we don't clobber any settings + # previously made in a working directory. + def bundle_app_config_path + @bundle_app_config_path ||= ".bundle-#{SecureRandom.uuid}" + end + def logger_level options.verbose ? Logger::DEBUG : Logger::INFO end @@ -200,8 +212,10 @@ def cleanup_and_report callbacks = {} if $! - callbacks[:error_message] = "#{$!.class}: #{$!.message}\n" - callbacks[:error_message] << $!.backtrace.map{|x| "\t#{x}"}.join("\n") + callbacks[:error_message] = +"#{$!.class}: #{$!.message}\n" + callbacks[:error_message] << $!.backtrace.map do |line| + "\t#{line}" + end.join("\n") end trigger_when_finished_callbacks(callbacks) diff --git a/lib/perf_check/version.rb b/lib/perf_check/version.rb index 0410efc..c7783d7 100644 --- a/lib/perf_check/version.rb +++ b/lib/perf_check/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class PerfCheck - VERSION = '0.10.5' + VERSION = '0.10.5' unless defined?(VERSION) end diff --git a/perf_check b/perf_check new file mode 120000 index 0000000..b4a6c3b --- /dev/null +++ b/perf_check @@ -0,0 +1 @@ +/Users/manfred/Code/perf_check \ No newline at end of file diff --git a/perf_check.gemspec b/perf_check.gemspec index de45303..e197baa 100644 --- a/perf_check.gemspec +++ b/perf_check.gemspec @@ -10,8 +10,9 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/rubytune/perf_check' s.license = 'MIT' - s.add_development_dependency 'rspec' s.add_development_dependency 'pry' + s.add_development_dependency 'rspec' + s.add_runtime_dependency 'bundler' s.add_runtime_dependency 'colorize' s.add_runtime_dependency 'diffy' s.add_runtime_dependency 'rake' diff --git a/spec/bundles/rails-4.tar.bz2 b/spec/bundles/rails-4.tar.bz2 index 6e1773a..3fbbf1b 100644 Binary files a/spec/bundles/rails-4.tar.bz2 and b/spec/bundles/rails-4.tar.bz2 differ diff --git a/spec/bundles/rails-5.tar.bz2 b/spec/bundles/rails-5.tar.bz2 index dea97a3..b512751 100644 Binary files a/spec/bundles/rails-5.tar.bz2 and b/spec/bundles/rails-5.tar.bz2 differ diff --git a/spec/support/apps.rb b/spec/support/apps.rb index 40c08cc..fddc721 100644 --- a/spec/support/apps.rb +++ b/spec/support/apps.rb @@ -55,9 +55,7 @@ def link_perf_check end def run_bundle_install - # Use the --frozen option to prevent the test suite from writing a new - # Gemfile.lock. - bundle 'install', '--frozen', '--retry', '3', '--jobs', '3' + PerfCheck.new(Dir.pwd).bundle end def run_db_setup