Skip to content

Commit 084885e

Browse files
committed
Only set $BUNDLER_VERSION when needed (Bundler 1, Ruby >= 2.7)
1 parent efd6675 commit 084885e

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

common.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ export function isStableVersion(rubyVersion) {
4040
return /^\d+(\.\d+)*$/.test(rubyVersion)
4141
}
4242

43+
export function isBundler2Default(engine, rubyVersion) {
44+
if (engine === 'ruby') {
45+
return isHeadVersion(rubyVersion) || floatVersion(rubyVersion) >= 2.7
46+
} else if (engine === 'truffleruby') {
47+
return isHeadVersion(rubyVersion)
48+
} else {
49+
return false
50+
}
51+
}
52+
53+
export function floatVersion(rubyVersion) {
54+
const match = rubyVersion.match(/^\d+\.\d+/)
55+
if (match) {
56+
return parseFloat(match[0])
57+
} else {
58+
return 0.0
59+
}
60+
}
61+
4362
export async function hashFile(file) {
4463
// See https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts
4564
const hash = crypto.createHash('sha256')

dist/index.js

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

index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi
222222
bundlerVersion = '1'
223223
}
224224

225-
if ((engine === 'ruby' || engine === 'truffleruby') && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') {
225+
if (common.isHeadVersion(rubyVersion) && common.isBundler2Default(engine, rubyVersion) && bundlerVersion === '2') {
226226
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
227227
} else if (engine === 'truffleruby' && !common.isHeadVersion(rubyVersion) && bundlerVersion === '1') {
228228
console.log(`Using Bundler 1 shipped with ${engine}`)
@@ -240,20 +240,25 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b
240240
return false
241241
}
242242

243-
// Before the lockfile exists, we need to specify which Bundler version to use explicitly
244-
const optionsWithBundlerVersion = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } }
243+
let envOptions = {}
244+
if (bundlerVersion.startsWith('1') && common.isBundler2Default(engine, rubyVersion)) {
245+
// If Bundler 1 is specified on Rubies which ship with Bundler 2,
246+
// we need to specify which Bundler version to use explicitly until the lockfile exists.
247+
console.log(`Setting BUNDLER_VERSION=${bundlerVersion} for "bundle config|lock" commands below to ensure Bundler 1 is used`)
248+
envOptions = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } }
249+
}
245250

246251
// config
247252
const path = 'vendor/bundle'
248253

249-
await exec.exec('bundle', ['config', '--local', 'path', path], optionsWithBundlerVersion)
254+
await exec.exec('bundle', ['config', '--local', 'path', path], envOptions)
250255

251256
if (fs.existsSync(lockFile)) {
252-
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], optionsWithBundlerVersion)
257+
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], envOptions)
253258
} else {
254259
// Generate the lockfile so we can use it to compute the cache key.
255260
// This will also automatically pick up the latest gem versions compatible with the Gemfile.
256-
await exec.exec('bundle', ['lock'], optionsWithBundlerVersion)
261+
await exec.exec('bundle', ['lock'], envOptions)
257262
}
258263

259264
// cache key

0 commit comments

Comments
 (0)