Skip to content

Commit

Permalink
Fix bundler env being copied to Ruby runner
Browse files Browse the repository at this point in the history
Fix issues with the wrong bundle of gems being used as context for the
runner. This failed to find the Ruby gem as it was using this project's
test suite Gemfile instead.

Wrap commands with `Bundler.with_unbundled_env` so it removes any
Bundler context from the environment. It also clears some other env
vars, so explicitly set them again in the base `run_env` method.
  • Loading branch information
tombruijn committed Jul 2, 2024
1 parent d27021c commit 0336aa1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PATH
remote: ../../../..
specs:
appsignal (3.0.15)
appsignal (3.9.2)
rack

GEM
remote: https://rubygems.org/
specs:
rack (2.2.3)
rack (3.1.5)

PLATFORMS
ruby
Expand Down
32 changes: 21 additions & 11 deletions spec/support/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,41 @@ def install_report?
end

def run_env
{ "APPSIGNAL_PUSH_API_KEY" => @push_api_key }
{
"APPSIGNAL_PUSH_API_KEY" => @push_api_key,
"APPSIGNAL_PUSH_API_ENDPOINT" => ENV["APPSIGNAL_PUSH_API_ENDPOINT"],
"APPSIGNAL_DIAGNOSE_ENDPOINT" => ENV["APPSIGNAL_DIAGNOSE_ENDPOINT"]
}
end

def run_command(_arguments)
raise NotImplementedError, "`Runner` subclasses must implement `run_command`"
end

def run # rubocop:disable Metrics/MethodLength
Dir.chdir directory do
before_setup
setup_commands.each do |command|
run_setup command
Bundler.with_unbundled_env do
Dir.chdir directory do
before_setup
setup_commands.each do |command|
run_setup command
end
after_setup
end
after_setup
end

# Run the command
prompt = @prompt ? %(echo "#{@prompt}" | ) : ""
command = run_command(@arguments.dup)
read, write = IO.pipe
pid = spawn(
run_env,
"#{prompt} #{command}",
{ [:out, :err] => write, :chdir => directory }
)
env = run_env
pid =
Bundler.with_unbundled_env do
spawn(
env,
"#{prompt} #{command}",
{ [:out, :err] => write, :chdir => directory }
)
end
_pid, status = Process.wait2 pid # Wait until command exits
write.close

Expand Down

0 comments on commit 0336aa1

Please sign in to comment.