Skip to content

Commit d5ee236

Browse files
committed
Ensure Bundler 2.2+ is used for all Rubies which support Bundler 2 (Ruby >= 2.3)
1 parent 8731780 commit d5ee236

File tree

6 files changed

+43
-20
lines changed

6 files changed

+43
-20
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ By default, Bundler is installed as follows:
159159

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

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

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ inputs:
1818
description: |
1919
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).
2020
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'.
21-
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'.
22-
For 'latest', the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.4, Bundler 1 on Ruby < 2.4).
21+
For 'default', if the Ruby ships with Bundler 2.2+ as a default gem, that version is used, otherwise the same as 'latest'.
22+
For 'latest', the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.3, Bundler 1 on Ruby < 2.3).
2323
For 'none', nothing is done.
2424
bundler-cache:
2525
description: 'Run "bundle install", and cache the result automatically. Either true or false.'

bundler.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,15 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
7171
const floatVersion = common.floatVersion(rubyVersion)
7272

7373
if (bundlerVersion === 'default') {
74-
if (engine === 'ruby' && floatVersion < 3.0 && common.hasBundlerDefaultGem(engine, rubyVersion)) {
75-
// Ruby 2.6 and 2.7 have a old Bundler default gem which does not work well for `gem 'foo', github: 'foo/foo'`:
74+
if (common.isBundler2dot2Default(engine, rubyVersion)) {
75+
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
76+
return '2'
77+
} else if (common.hasBundlerDefaultGem(engine, rubyVersion)) {
78+
// Those Rubies have a old Bundler default gem < 2.2 which does not work well for `gem 'foo', github: 'foo/foo'`:
7679
// https://github.com/ruby/setup-ruby/issues/358#issuecomment-1195899304
7780
// Also, Ruby 2.6 would get Bundler 1 yet Ruby 2.3 - 2.5 get latest Bundler 2 which might be unexpected.
7881
console.log(`Using latest Bundler for ${engine}-${rubyVersion} because the default Bundler gem is too old for that Ruby version`)
7982
bundlerVersion = 'latest'
80-
} else if (common.isBundler2Default(engine, rubyVersion)) {
81-
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
82-
return '2'
83-
} else if (common.isBundler1Default(engine, rubyVersion)) {
84-
console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`)
85-
return '1'
8683
} else {
8784
bundlerVersion = 'latest'
8885
}

common.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ export function isBundler2Default(engine, rubyVersion) {
8383
}
8484
}
8585

86+
export function isBundler2dot2Default(engine, rubyVersion) {
87+
if (engine === 'ruby') {
88+
return floatVersion(rubyVersion) >= 3.0
89+
} else if (engine.startsWith('truffleruby')) {
90+
return floatVersion(rubyVersion) >= 22.0
91+
} else if (engine === 'jruby') {
92+
return floatVersion(rubyVersion) >= 9.3
93+
} else {
94+
return false
95+
}
96+
}
97+
8698
export function floatVersion(rubyVersion) {
8799
const match = rubyVersion.match(/^\d+\.\d+/)
88100
if (match) {

dist/index.js

Lines changed: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gemfiles/gem_from_github.gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ source "https://rubygems.org"
22

33
# Ruby < 2.3 only support Bundler 1, which no longer works with gem github:
44
if RUBY_VERSION >= '2.3'
5+
unless Gem::Version.new(Bundler::VERSION) >= Gem::Version.new("2.2.0")
6+
raise "Expected Bundler 2.2+ is used on Ruby >= 2.3"
7+
end
8+
59
# From https://github.com/ruby/setup-ruby/issues/358#issuecomment-1195899304
610
# Tests using github: and the repository uses a non-master default branch.
711
gem 'rack-test', github: 'rack/rack-test'

0 commit comments

Comments
 (0)