Skip to content

Commit 4e1189c

Browse files
committed
Use the Bundler shipped with that Ruby by default
* Fixes #358
1 parent a54c48c commit 4e1189c

File tree

6 files changed

+79
-62
lines changed

6 files changed

+79
-62
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,12 @@ should be able to fix them by setting `rubygems: 3.0.0` or higher.
155155

156156
### Bundler
157157

158-
By default, if there is a `Gemfile.lock` file (or `$BUNDLE_GEMFILE.lock` or `gems.locked`) with a `BUNDLED WITH` section,
159-
that version of Bundler will be installed and used.
160-
Otherwise, the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.4, Bundler 1 on Ruby < 2.4).
158+
By default, Bundler is installed as follows:
159+
160+
* If there is a `Gemfile.lock` file (or `$BUNDLE_GEMFILE.lock` or `gems.locked`) with a `BUNDLED WITH` section,
161+
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).
161164

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

action.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ inputs:
1616
Similarly, if a version number is given, `gem update --system <version>` is run to update to that version of RubyGems, as long as that version is newer than the one provided by default.
1717
bundler:
1818
description: |
19-
The version of Bundler to install. Either 'none', 'latest', 'Gemfile.lock', or a version number (e.g., 1, 2, 2.1, 2.1.4).
20-
For 'Gemfile.lock', the version is determined based on the BUNDLED WITH section from the file Gemfile.lock, $BUNDLE_GEMFILE.lock or gems.locked.
21-
Defaults to 'default', which means 'Gemfile.lock' if the file exists and 'latest' otherwise.
19+
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).
20+
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).
23+
For 'none', nothing is done.
2224
bundler-cache:
2325
description: 'Run "bundle install", and cache the result automatically. Either true or false.'
2426
default: 'false'

bundler.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,29 @@ async function afterLockFile(lockFile, platform, engine, rubyVersion) {
5353
export async function installBundler(bundlerVersionInput, rubygemsInputSet, lockFile, platform, rubyPrefix, engine, rubyVersion) {
5454
let bundlerVersion = bundlerVersionInput
5555

56-
if (rubygemsInputSet && bundlerVersion === 'default') {
56+
if (rubygemsInputSet && (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock')) {
5757
console.log('Using the Bundler installed by updating RubyGems')
5858
return 'unknown'
5959
}
6060

61-
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
62-
bundlerVersion = readBundledWithFromGemfileLock(lockFile)
61+
if (bundlerVersion === 'Gemfile.lock') {
62+
let bundlerVersionFromGemfileLock = readBundledWithFromGemfileLock(lockFile)
6363

64-
if (!bundlerVersion) {
64+
if (bundlerVersionFromGemfileLock) {
65+
bundlerVersion = bundlerVersionFromGemfileLock
66+
} else {
67+
bundlerVersion = 'default'
68+
}
69+
}
70+
71+
if (bundlerVersion === 'default') {
72+
if (common.isBundler2Default(engine, rubyVersion)) {
73+
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
74+
return '2'
75+
} else if (common.isBundler1Default(engine, rubyVersion)) {
76+
console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`)
77+
return '1'
78+
} else {
6579
bundlerVersion = 'latest'
6680
}
6781
}
@@ -92,30 +106,14 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
92106
}
93107
}
94108

95-
// Workaround for truffleruby 22.0 + latest Bundler, use shipped Bundler instead: https://github.com/oracle/truffleruby/issues/2586
96-
const truffleruby22workaround = engine.startsWith('truffleruby') && rubyVersion.startsWith('22.0')
97-
const useShippedBundler2 = common.isHeadVersion(rubyVersion) || truffleruby22workaround
109+
const gem = path.join(rubyPrefix, 'bin', 'gem')
110+
// Workaround for https://github.com/rubygems/rubygems/issues/5245
111+
const force = (platform.startsWith('windows-') && engine === 'ruby' && floatVersion >= 3.1) ? ['--force'] : []
98112

99-
if (useShippedBundler2 && common.isBundler2Default(engine, rubyVersion) && bundlerVersion.startsWith('2')) {
100-
// Avoid installing a newer Bundler version for head versions as it might not work.
101-
// For releases, even if they ship with Bundler 2 we install the latest Bundler.
102-
if (truffleruby22workaround) {
103-
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion} (workaround for https://github.com/oracle/truffleruby/issues/2586 on truffleruby 22.0)`)
104-
} else {
105-
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion} (head versions do not always support the latest Bundler release)`)
106-
}
107-
} else if (engine.startsWith('truffleruby') && common.isBundler1Default(engine, rubyVersion) && bundlerVersion.startsWith('1')) {
108-
console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion} (required for truffleruby < 21.0)`)
109-
} else {
110-
const gem = path.join(rubyPrefix, 'bin', 'gem')
111-
// Workaround for https://github.com/rubygems/rubygems/issues/5245
112-
const force = (platform.startsWith('windows-') && engine === 'ruby' && floatVersion >= 3.1) ? ['--force'] : []
113+
const versionParts = [...bundlerVersion.matchAll(/\d+/g)].length
114+
const bundlerVersionConstraint = versionParts === 3 ? bundlerVersion : `~> ${bundlerVersion}.0`
113115

114-
const versionParts = [...bundlerVersion.matchAll(/\d+/g)].length
115-
const bundlerVersionConstraint = versionParts === 3 ? bundlerVersion : `~> ${bundlerVersion}.0`
116-
117-
await exec.exec(gem, ['install', 'bundler', ...force, '-v', bundlerVersionConstraint])
118-
}
116+
await exec.exec(gem, ['install', 'bundler', ...force, '-v', bundlerVersionConstraint])
119117

120118
return bundlerVersion
121119
}

common.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ export function isStableVersion(rubyVersion) {
5656
}
5757

5858
export function isBundler1Default(engine, rubyVersion) {
59-
return !isBundler2Default(engine, rubyVersion)
59+
if (engine === 'ruby') {
60+
return floatVersion(rubyVersion) >= 2.6 && floatVersion(rubyVersion) < 2.7
61+
} else if (engine.startsWith('truffleruby')) {
62+
return floatVersion(rubyVersion) < 21.0
63+
} else if (engine === 'jruby') {
64+
return false
65+
} else {
66+
return false
67+
}
6068
}
6169

6270
export function isBundler2Default(engine, rubyVersion) {

dist/index.js

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

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const windows = common.windows
1212
const inputDefaults = {
1313
'ruby-version': 'default',
1414
'rubygems': 'default',
15-
'bundler': 'default',
15+
'bundler': 'Gemfile.lock',
1616
'bundler-cache': 'false',
1717
'working-directory': '.',
1818
'cache-version': bundler.DEFAULT_CACHE_VERSION,

0 commit comments

Comments
 (0)