Skip to content

gem install bundler - add '--conservative', small README.md change - #48

Closed
MSP-Greg wants to merge 2 commits into
ruby:masterfrom
MSP-Greg:bundler-conservative
Closed

MSP-Greg wants to merge 2 commits into
ruby:masterfrom
MSP-Greg:bundler-conservative

Conversation

@MSP-Greg

@MSP-Greg MSP-Greg commented Apr 2, 2020

Copy link
Copy Markdown
Collaborator

Two commits:

  1. 'gem install bundler - add --conservative' - to avoid unnecessary bundler installs, especially on master

  2. README.md - remove reference to MSP-Greg/actions-ruby - Preferred repo is now MSP-Greg/setup-ruby-pkgs

@MSP-Greg

MSP-Greg commented Apr 2, 2020

Copy link
Copy Markdown
Collaborator Author

Working with master, I often get frustrated with RG/Bundler. This is not working as expected. In my fork, I looked at the head builds, and they're not installing Bundler (as desired).

But, if you compare the 2.5 & 2.6.5 jobs, in the ' Run /./' and 'Run bundle --version' steps, it certainly looks like something isn't working right. 2.5 seems right, but 2.6.5 is a 'WTF is this?'...

Maybe use a regex like rubyVersion.match(/(head|mingw|mswin)$/) and skip gem install bundler for them?

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

Working with master, I often get frustrated with RG/Bundler. This is not working as expected. In my fork, I looked at the head builds, and they're not installing Bundler (as desired).

I'm not sure what you mean, could you point to a log and explain your expectation?
My expectation is it should install latest bundler on ruby-head, and basically every Ruby >= 2.3 if there is no Gemfile.lock by default.

but 2.6.5 is a 'WTF is this?'...

Log please :)

@MSP-Greg

MSP-Greg commented Apr 3, 2020 •

Copy link
Copy Markdown
Collaborator Author

My expectation is it should install latest bundler on ruby-head

Right now, head is running with RubyGems 3.2.0.pre1, which isn't released. The same may be true for Bundler. Hence, ruby-head should not have anything done to its RubyGems or Bundler. If a Gemfile, etc requires Bundler 1.x, then it should be installed.

Log please :)

The log for the CI on this PR.

Ruby 2.5

Step:  Run /./
  Successfully installed bundler-2.1.4

Step:  Run bundle --version
  Bundler version 2.1.4

Ruby 2.6.5

Step:  Run /./
  No gem (Bundler) installed

Step:  Run bundle --version
  Bundler version 1.17.2

Why does 2.6.5 have Bundler 1.17.2, but 2.5 has 2.1.4?

EDIT: When I said 'WTF is this?', I wasn't referring to any of the code here, I was referring to why 2.6.5 was not behaving correctly...

MSP-Greg added 2 commits April 2, 2020 21:17
use --conservative to avoid unnecessary bundler installs, especially on master
Preferred repo is now MSP-Greg/setup-ruby-pkgs
@MSP-Greg
MSP-Greg force-pushed the bundler-conservative branch from fff3219 to 36269a7 Compare April 3, 2020 02:23
@MSP-Greg

MSP-Greg commented Apr 3, 2020

Copy link
Copy Markdown
Collaborator Author

Fixed issue with Ruby 2.6, apparently RubyGems 3.0.3 needs a version requirement for --conservative to function as in other versions. Ruby 2.6 is now correctly updating Bundler to the current version.

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

Same results on the original PR: https://github.com/ruby/setup-ruby/runs/550219139?check_suite_focus=true (Bundler 2 on Ruby 2.6.5 on all 3 platforms)

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

Right now, head is running with RubyGems 3.2.0.pre1, which isn't released. The same may be true for Bundler. Hence, ruby-head should not have anything done to its RubyGems or Bundler. If a Gemfile, etc requires Bundler 1.x, then it should be installed.

That's something to consider. I think there might be cases where ruby-head has a older Bundler than the latest release. Bundler is updated infrequently in ruby-head IIRC.
I agree for ruby-head (and mingw/msiwn) it seems safer to not touch Bundler if the logic would otherwise decide to install the latest Bundler. In other words, for ruby-head, only install Bundler if we decide we need Bundler 1.

Regarding --conservative, would that use the Bundler 2.1.4 shipped with Ruby 2.7.1, instead of a more recent Bundler release, say 2.2.0?
I think that would be suboptimal if we have Ruby 2.6.5 gets the latest Bundler 2.2.0 (because it doesn't ship with Bundler 2) but Ruby 2.7.1 ends up with Bundler 2.1.4 (which might have bugs fixed in 2.2.0).

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

Found https://github.com/ruby/setup-ruby/runs/556397578?check_suite_focus=true which indeeds reports Bundler 1 since --conservative added in this PR has no version requirement and so is happy with the default Bundler gem (which is Bundler 1).

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

But, if you compare the 2.5 & 2.6.5 jobs, in the ' Run /./' and 'Run bundle --version' steps, it certainly looks like something isn't working right. 2.5 seems right, but 2.6.5 is a 'WTF is this?'...

It was really not clear to me you were talking about the CI of this PR, I thought you were mentioning a bug of current master.

@MSP-Greg

MSP-Greg commented Apr 3, 2020

Copy link
Copy Markdown
Collaborator Author

Sorry. I was irritated about RubyGems, as most versions seem to take --conservative as equivalent to 'don't re-install if on latest', but with RG 3.0.3, it's equivalent to 'don't install if it is installed'.

Either way, probably best to include the >= 2.1.

I thought you were mentioning a bug of current master.

I would have made that clear. We got messed up with 'logs', and I did say "but 2.6.5 is a 'WTF is this?". Or, your code is fine, it's the RG/Bundler quirks. I wrestled with them with AppVeyor & Travis, I just want to be done messing with them. JFYI, I have come across CI where RG needed an update when using Ruby 2.2...

@MSP-Greg

MSP-Greg commented Apr 3, 2020

Copy link
Copy Markdown
Collaborator Author

Regarding --conservative, would that use the Bundler 2.1.4 shipped with Ruby 2.7.1, instead of a more recent Bundler release, say 2.2.0?
I think that would be suboptimal if we have Ruby 2.6.5 gets the latest Bundler 2.2.0 (because it doesn't ship with Bundler 2) but Ruby 2.7.1 ends up with Bundler 2.1.4 (which might have bugs fixed in 2.2.0).

I think we may need to wait and see how the RG in those versions handles --conservative?

Maybe just add conditional logic to leave head's Bundler alone, and remove --conservative?

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

Any reason to use >= 2.1 over just ~> 2?
I guess that wouldn't allow Bundler 3, but I think we can revisit the situation then.

Maybe just add conditional logic to leave head's Bundler alone, and remove --conservative?

Yes, I think we should do that, it seems safer to me and more predictable than using a flag which apparently changes meaning in different RubyGems versions.
I'll take care of that change, and merge your small README fix.

eregon added a commit that referenced this pull request Apr 3, 2020
* Avoid issues when using --conservative as seen in
  #48, clarifies what's getting
  installed and simplifies the following logic.
* We'll probably need changes when Bundler 3 comes out anyway.
@eregon

eregon commented Apr 3, 2020 •

Copy link
Copy Markdown
Member

--conservative would have the advantage to not reinstall Bundler 2.1.4 on Ruby 2.7.1 currently, without needing explicit logic.
OTOH then we could have the situation where there is a future Bundler 2.2.0 and it would be used for all Rubies (2.3/2.4/2.5/2.6) except head (kind of OK) and 2.7.1 (kind of surprising I'd say).

So I think for 2.7.1 it's not good to skip installing Bundler right now, since it would only be without side-effects until the next Bundler version comes out.
I might reconsider later, I'm not sure what's better here:

  • use the stdlib Bundler if same major version as Gemfile.lock or (--conservative might be an easy way to implement that if it works reliably with -v '~> 1|2)
  • try to use latest Bundler of the same major version so all or almost all Rubies use that same latest Bundler of the same major version (current approach)

@eregon

eregon commented Apr 3, 2020

Copy link
Copy Markdown
Member

See c40ce85 and the parent commit, that will avoid installing Bundler on ruby-head/mingw/mswin.

I think the main issue is addressed here, thanks for reporting it and the PR.
Let's close this PR since it will conflict.

I'll keep thinking about the two approaches mentioned above.

@eregon eregon closed this Apr 3, 2020
@MSP-Greg
MSP-Greg deleted the bundler-conservative branch April 3, 2020 22:19
excid3 added a commit to excid3/setup-ruby that referenced this pull request Oct 21, 2026
Reinstalling an exact version that is already installed changes nothing, but
`gem install` removes the gem directory before extracting it again. On
self-hosted runners that share a tool cache, a concurrent job then fails at
`bundle config` with "cannot load such file -- .../bundler-X.Y.Z/lib/bundler/dsl"
(ruby#191). With `--conservative`, RubyGems returns before touching anything when
the requirement is already met, including by a default gem. Only exact
versions pass the flag, so a `~>` constraint still gets the latest matching
release rather than the Bundler the Ruby shipped with (see ruby#48).

`--conservative` has worked this way for `gem install` since RubyGems 1.8.23.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants