diff --git a/lib/big_tuna/runner.rb b/lib/big_tuna/runner.rb index 513541d..3627e97 100644 --- a/lib/big_tuna/runner.rb +++ b/lib/big_tuna/runner.rb @@ -3,7 +3,7 @@ class Runner def self.execute(dir, command) end_command = "cd #{dir} && #{command}" BigTuna.logger.debug("Executing: #{end_command}") - with_clean_env do + with_clean_env(dir) do output = Output.new(dir, command) buffer = [] status = Open4.popen4(end_command) do |_, _, stdout, stderr| @@ -18,13 +18,20 @@ def self.execute(dir, command) end end - def self.with_clean_env + def self.with_clean_env(dir) Bundler.with_clean_env do begin rails_env = ENV.delete("RAILS_ENV") + old_bundle_gemfile = nil + bundle_gemfile = File.join(dir, "Gemfile") + if File.file?(bundle_gemfile) + old_bundle_gemfile = ENV.delete("BUNDLE_GEMFILE") + ENV["BUNDLE_GEMFILE"] = bundle_gemfile + end yield ensure ENV["RAILS_ENV"] = rails_env if rails_env # if nil, then don't set any key + ENV["BUNDLE_GEMFILE"] = old_bundle_gemfile if old_bundle_gemfile end end end diff --git a/test/unit/bundler_project_test.rb b/test/unit/bundler_project_test.rb new file mode 100644 index 0000000..301fae7 --- /dev/null +++ b/test/unit/bundler_project_test.rb @@ -0,0 +1,43 @@ +require 'test_helper' + +class BundlerProjectTest < ActiveSupport::TestCase + def setup + super + create_bundler_test_repo + end + + def teardown + destroy_test_repo + super + end + + test "bundler projects are auto-discovered" do + project = project_with_steps({:name => "bundlerproject", :vcs_source => "test/files/bundler_repo", :vcs_type => "git"}, "env") + project.build! + run_delayed_jobs() + build = project.recent_build + envs = build.parts[0].output[0].stdout + bundle_gemfile_env = envs.map! { |e| e.split("=") }.assoc("BUNDLE_GEMFILE") + assert_equal File.join(build.build_dir, "Gemfile"), bundle_gemfile_env[1] + end + + private + def create_bundler_test_repo + command = <<-CMD.gsub("\n", "; ") + mkdir -p test/files/bundler_repo + cd test/files/bundler_repo + git init + git config user.name git + git config user.email git@example.com + echo "my file" > file + touch Gemfile + git add file Gemfile + git commit -m "bundler project added" + CMD + `#{command}` + end + + def destroy_test_repo + FileUtils.rm_rf 'test/files/bundler_repo' + end +end