CircleCI-Public / ruby-orb

The `circleci/ruby` orb source code.
https://circleci.com/developer/orbs/orb/circleci/ruby
MIT License
25 stars 53 forks source link

Setting BUNDLE_GEMFILE causes issues with `bundle exec` #122

Open matiaskorhonen opened 1 year ago

matiaskorhonen commented 1 year ago

Orb version: 2.0.0

What happened:

The current default configuration for the install-deps command results in broken behavior when running bundle exec commands in project subdirectories:

$ bundle exec fastlane detox_build
bundler: command not found: fastlane
Install missing gem executables with `bundle install`

That error occurs after a successful bundle install only because it was run in ~/project/android instead of ~/project/

By default, bundler will search up from the current working directory until it finds a Gemfile. However, setting the gemfile/BUNDLE_GEMFILE configuration option results in this getting short-circuited, even when set to Gemfile.

You can see this behavior here:

# …

def find_gemfile
  given = ENV["BUNDLE_GEMFILE"]
  return given if given && !given.empty?
  find_file(*gemfile_names)
end

def gemfile_names
  ["gems.rb", "Gemfile"]
end

def find_file(*names)
  search_up(*names) do |filename|
    return filename if File.file?(filename)
  end
end

#...

Expected behavior:

If the Gemfile name hasn't been customized, the gemfile configuration option should not be set.

Additional Information:

It might also be worth it it to not set the path/BUNDLE_PATH configuration option either the current value (vendor/bundle) is already the default when using Bundler in deployment mode. It doesn't seem to be causing the same problems as the gemfile setting though, so it's a judgement call…

marboledacci commented 1 week ago

@matiaskorhonen If I understood well, the problem is coming when line bundle config set gemfile "$PARAM_GEMFILE" is executed. Why is it a problem that the value is set to Gemfile?

matiaskorhonen commented 1 week ago

Because you might need to run commands in a project subdirectory and explicitly setting gemfile to a relative path causes Bundler not to locate the Gemfile in the parent directory (the default Bundler behaviour).

marboledacci commented 4 days ago

Version 2.2.1 now uses absolute path for the Gemfile, so this shouldn't be an issue anymore.