Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,15 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
}
}

const floatVersion = common.floatVersion(rubyVersion)

if (bundlerVersion === 'default') {
if (common.isBundler2dot2Default(engine, rubyVersion)) {
if (common.isBundler2dot2PlusDefault(engine, rubyVersion)) {
if (common.windows && engine === 'ruby' && (common.isStableVersion(engine, rubyVersion) || rubyVersion === 'head')) {
// https://github.com/ruby/setup-ruby/issues/371
console.log(`Installing latest Bundler for ${engine}-${rubyVersion} on Windows because bin/bundle does not work in bash otherwise`)
bundlerVersion = 'latest'
} else {
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
return '2'
console.log(`Using Bundler shipped with ${engine}-${rubyVersion}`)
return common.isBundler4PlusDefault(engine, rubyVersion) ? '4' : '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'`:
Expand All @@ -90,8 +88,15 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
}
}

const targetRubyVersion = common.targetRubyVersion(engine, rubyVersion)

if (bundlerVersion === 'latest') {
bundlerVersion = '2'
// Bundler 4 requires Ruby 3.2+
if (targetRubyVersion < 3.2) {
bundlerVersion = '2'
} else {
bundlerVersion = '4'
}
}

if (isValidBundlerVersion(bundlerVersion)) {
Expand All @@ -100,24 +105,29 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
}

// Use Bundler 1 when we know Bundler 2 does not work
if (bundlerVersion.startsWith('2')) {
if (engine === 'ruby' && floatVersion <= 2.2) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2')
// Only use Bundler 4 on Ruby 3.2+
if (common.floatVersion(bundlerVersion) >= 4 && targetRubyVersion < 3.2) {
console.log('Bundler 4 requires Ruby 3.2+, using Bundler 2 instead on Ruby < 3.2')
bundlerVersion = '2'
}

// Use Bundler 1 when we know Bundler 2+ does not work
if (common.floatVersion(bundlerVersion) >= 2) {
if (engine === 'ruby' && targetRubyVersion <= 2.2) {
console.log(`Bundler 2+ requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2`)
bundlerVersion = '1'
} else if (engine === 'ruby' && /^2\.3\.[01]/.test(rubyVersion)) {
console.log('Ruby 2.3.0 and 2.3.1 have shipped with an old rubygems that only works with Bundler 1')
bundlerVersion = '1'
} else if (engine === 'jruby' && rubyVersion.startsWith('9.1')) { // JRuby 9.1 targets Ruby 2.3, treat it the same
console.log('JRuby 9.1 has a bug with Bundler 2 (https://github.com/ruby/setup-ruby/issues/108), using Bundler 1 instead on JRuby 9.1')
console.log('JRuby 9.1 has a bug with Bundler 2+ (https://github.com/ruby/setup-ruby/issues/108), using Bundler 1 instead on JRuby 9.1')
bundlerVersion = '1'
}
}

const targetRubyVersion = common.targetRubyVersion(engine, rubyVersion)
// Use Bundler 2.3 when we use Ruby 2.3.2 - 2.5
// Use Bundler 2.4 when we use Ruby 2.6-2.7
if (bundlerVersion == '2') {
if (bundlerVersion === '2') {
if (targetRubyVersion <= 2.5) { // < 2.3.2 already handled above
console.log('Ruby 2.3.2 - 2.5 only works with Bundler 2.3')
bundlerVersion = '2.3'
Expand All @@ -137,15 +147,23 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
return bundlerVersion
}

function bundlerConfigSetArgs(bundlerVersion, key, value) {
if (bundlerVersion.startsWith('1')) {
return ['config', '--local', key, value]
} else {
return ['config', 'set', '--local', key, value]
}
}

export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion, cacheVersion) {
if (gemfile === null) {
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
return false
}

let envOptions = {}
if (bundlerVersion.startsWith('1') && common.isBundler2Default(engine, rubyVersion)) {
// If Bundler 1 is specified on Rubies which ship with Bundler 2,
if (bundlerVersion.startsWith('1') && common.isBundler2PlusDefault(engine, rubyVersion)) {
// If Bundler 1 is specified on Rubies which ship with Bundler 2+,
// we need to specify which Bundler version to use explicitly until the lockfile exists.
console.log(`Setting BUNDLER_VERSION=${bundlerVersion} for "bundle config|lock" commands below to ensure Bundler 1 is used`)
envOptions = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } }
Expand All @@ -156,10 +174,10 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
// An absolute path, so it is reliably under $PWD/vendor/bundle, and not relative to the gemfile's directory
const bundleCachePath = path.join(process.cwd(), cachePath)

await exec.exec('bundle', ['config', '--local', 'path', bundleCachePath], envOptions)
await exec.exec('bundle', bundlerConfigSetArgs(bundlerVersion, 'path', bundleCachePath), envOptions)

if (fs.existsSync(lockFile)) {
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], envOptions)
await exec.exec('bundle', bundlerConfigSetArgs(bundlerVersion, 'deployment', 'true'), envOptions)
} else {
// Generate the lockfile so we can use it to compute the cache key.
// This will also automatically pick up the latest gem versions compatible with the Gemfile.
Expand Down
19 changes: 14 additions & 5 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function isStableVersion(engine, rubyVersion) {
}

export function hasBundlerDefaultGem(engine, rubyVersion) {
return isBundler1Default(engine, rubyVersion) || isBundler2Default(engine, rubyVersion)
return isBundler1Default(engine, rubyVersion) || isBundler2PlusDefault(engine, rubyVersion)
}

export function isBundler1Default(engine, rubyVersion) {
Expand All @@ -95,7 +95,7 @@ export function isBundler1Default(engine, rubyVersion) {
}
}

export function isBundler2Default(engine, rubyVersion) {
export function isBundler2PlusDefault(engine, rubyVersion) {
if (engine === 'ruby') {
return floatVersion(rubyVersion) >= 2.7
} else if (engine.startsWith('truffleruby')) {
Expand All @@ -107,7 +107,7 @@ export function isBundler2Default(engine, rubyVersion) {
}
}

export function isBundler2dot2Default(engine, rubyVersion) {
export function isBundler2dot2PlusDefault(engine, rubyVersion) {
if (engine === 'ruby') {
return floatVersion(rubyVersion) >= 3.0
} else if (engine.startsWith('truffleruby')) {
Expand All @@ -119,6 +119,13 @@ export function isBundler2dot2Default(engine, rubyVersion) {
}
}

const UNKNOWN_TARGET_RUBY_VERSION = 9.9

export function isBundler4PlusDefault(engine, rubyVersion) {
const version = targetRubyVersion(engine, rubyVersion)
return version != UNKNOWN_TARGET_RUBY_VERSION && version >= 4.0
}

export function targetRubyVersion(engine, rubyVersion) {
const version = floatVersion(rubyVersion)
if (engine === 'ruby') {
Expand All @@ -132,6 +139,8 @@ export function targetRubyVersion(engine, rubyVersion) {
return 2.6
} else if (version === 9.4) {
return 3.1
} else if (version === 10.0) {
return 3.4
}
} else if (engine.startsWith('truffleruby')) {
if (version < 21.0) {
Expand All @@ -147,11 +156,11 @@ export function targetRubyVersion(engine, rubyVersion) {
}
}

return 9.9 // unknown, assume recent
return UNKNOWN_TARGET_RUBY_VERSION // unknown, assume recent
}

export function floatVersion(rubyVersion) {
const match = rubyVersion.match(/^\d+\.\d+/)
const match = rubyVersion.match(/^\d+(\.\d+|$)/)
if (match) {
return parseFloat(match[0])
} else if (isHeadVersion(rubyVersion)) {
Expand Down
76 changes: 52 additions & 24 deletions dist/index.js

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

Loading