Skip to content

Commit

Permalink
Ensure Bundler 2.2+ is used for all Rubies which support Bundler 2 (R…
Browse files Browse the repository at this point in the history
…uby >= 2.3)
  • Loading branch information
eregon committed Jul 29, 2022
1 parent 8731780 commit d5ee236
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ By default, Bundler is installed as follows:

* If there is a `Gemfile.lock` file (or `$BUNDLE_GEMFILE.lock` or `gems.locked`) with a `BUNDLED WITH` section,
that version of Bundler will be installed and used.
* If the Ruby ships with Bundler (as a default gem), that version is used.
* Otherwise, the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.4, Bundler 1 on Ruby < 2.4).
* If the Ruby ships with Bundler 2.2+ (as a default gem), that version is used.
* Otherwise, the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.3, Bundler 1 on Ruby < 2.3).

This behavior can be customized, see [action.yml](action.yml) for more details about the `bundler` input.

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ inputs:
description: |
The version of Bundler to install. Either 'Gemfile.lock' (the default), 'default', 'latest', 'none', or a version number (e.g., 1, 2, 2.1, 2.1.4).
For 'Gemfile.lock', the version of the BUNDLED WITH section from the Gemfile.lock if it exists. If the file or section does not exist then the same as 'default'.
For 'default', the version of Bundler that comes with that Ruby by default is used, or if that Ruby comes without Bundler then the same as 'latest'.
For 'latest', the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.4, Bundler 1 on Ruby < 2.4).
For 'default', if the Ruby ships with Bundler 2.2+ as a default gem, that version is used, otherwise the same as 'latest'.
For 'latest', the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.3, Bundler 1 on Ruby < 2.3).
For 'none', nothing is done.
bundler-cache:
description: 'Run "bundle install", and cache the result automatically. Either true or false.'
Expand Down
13 changes: 5 additions & 8 deletions bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,15 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
const floatVersion = common.floatVersion(rubyVersion)

if (bundlerVersion === 'default') {
if (engine === 'ruby' && floatVersion < 3.0 && common.hasBundlerDefaultGem(engine, rubyVersion)) {
// Ruby 2.6 and 2.7 have a old Bundler default gem which does not work well for `gem 'foo', github: 'foo/foo'`:
if (common.isBundler2dot2Default(engine, rubyVersion)) {
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
return '2'
} else if (common.hasBundlerDefaultGem(engine, rubyVersion)) {
// Those Rubies have a old Bundler default gem < 2.2 which does not work well for `gem 'foo', github: 'foo/foo'`:
// https://github.com/ruby/setup-ruby/issues/358#issuecomment-1195899304
// Also, Ruby 2.6 would get Bundler 1 yet Ruby 2.3 - 2.5 get latest Bundler 2 which might be unexpected.
console.log(`Using latest Bundler for ${engine}-${rubyVersion} because the default Bundler gem is too old for that Ruby version`)
bundlerVersion = 'latest'
} else if (common.isBundler2Default(engine, rubyVersion)) {
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
return '2'
} else if (common.isBundler1Default(engine, rubyVersion)) {
console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`)
return '1'
} else {
bundlerVersion = 'latest'
}
Expand Down
12 changes: 12 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export function isBundler2Default(engine, rubyVersion) {
}
}

export function isBundler2dot2Default(engine, rubyVersion) {
if (engine === 'ruby') {
return floatVersion(rubyVersion) >= 3.0
} else if (engine.startsWith('truffleruby')) {
return floatVersion(rubyVersion) >= 22.0
} else if (engine === 'jruby') {
return floatVersion(rubyVersion) >= 9.3
} else {
return false
}
}

export function floatVersion(rubyVersion) {
const match = rubyVersion.match(/^\d+\.\d+/)
if (match) {
Expand Down
26 changes: 18 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions gemfiles/gem_from_github.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ source "https://rubygems.org"

# Ruby < 2.3 only support Bundler 1, which no longer works with gem github:
if RUBY_VERSION >= '2.3'
unless Gem::Version.new(Bundler::VERSION) >= Gem::Version.new("2.2.0")
raise "Expected Bundler 2.2+ is used on Ruby >= 2.3"
end

# From https://github.com/ruby/setup-ruby/issues/358#issuecomment-1195899304
# Tests using github: and the repository uses a non-master default branch.
gem 'rack-test', github: 'rack/rack-test'
Expand Down

0 comments on commit d5ee236

Please sign in to comment.