diff --git a/bundler.js b/bundler.js index c9556f6..79c4ace 100644 --- a/bundler.js +++ b/bundler.js @@ -68,11 +68,19 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock } } + const floatVersion = common.floatVersion(rubyVersion) + if (bundlerVersion === 'default') { - if (common.isBundler2Default(engine, rubyVersion)) { + 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'`: + // 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)) { + } else if (common.isBundler1Default(engine, rubyVersion) && engine !== 'ruby') { console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`) return '1' } else { @@ -90,8 +98,6 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock throw new Error(`Cannot parse bundler input: ${bundlerVersion}`) } - const floatVersion = common.floatVersion(rubyVersion) - // Use Bundler 1 when we know Bundler 2 does not work if (bundlerVersion.startsWith('2')) { if (engine === 'ruby' && floatVersion <= 2.2) { diff --git a/common.js b/common.js index aa24aee..9dd90f1 100644 --- a/common.js +++ b/common.js @@ -55,6 +55,10 @@ export function isStableVersion(rubyVersion) { return /^\d+(\.\d+)*$/.test(rubyVersion) } +export function hasBundlerDefaultGem(engine, rubyVersion) { + return isBundler1Default(engine, rubyVersion) || isBundler2Default(engine, rubyVersion) +} + export function isBundler1Default(engine, rubyVersion) { if (engine === 'ruby') { return floatVersion(rubyVersion) >= 2.6 && floatVersion(rubyVersion) < 2.7 diff --git a/dist/index.js b/dist/index.js index b599e9b..bf15052 100644 --- a/dist/index.js +++ b/dist/index.js @@ -82,11 +82,19 @@ async function installBundler(bundlerVersionInput, rubygemsInputSet, lockFile, p } } + const floatVersion = common.floatVersion(rubyVersion) + if (bundlerVersion === 'default') { - if (common.isBundler2Default(engine, rubyVersion)) { + 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'`: + // 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)) { + } else if (common.isBundler1Default(engine, rubyVersion) && engine !== 'ruby') { console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`) return '1' } else { @@ -104,8 +112,6 @@ async function installBundler(bundlerVersionInput, rubygemsInputSet, lockFile, p throw new Error(`Cannot parse bundler input: ${bundlerVersion}`) } - const floatVersion = common.floatVersion(rubyVersion) - // Use Bundler 1 when we know Bundler 2 does not work if (bundlerVersion.startsWith('2')) { if (engine === 'ruby' && floatVersion <= 2.2) { @@ -253,6 +259,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ "measure": () => (/* binding */ measure), /* harmony export */ "isHeadVersion": () => (/* binding */ isHeadVersion), /* harmony export */ "isStableVersion": () => (/* binding */ isStableVersion), +/* harmony export */ "hasBundlerDefaultGem": () => (/* binding */ hasBundlerDefaultGem), /* harmony export */ "isBundler1Default": () => (/* binding */ isBundler1Default), /* harmony export */ "isBundler2Default": () => (/* binding */ isBundler2Default), /* harmony export */ "floatVersion": () => (/* binding */ floatVersion), @@ -322,6 +329,10 @@ function isStableVersion(rubyVersion) { return /^\d+(\.\d+)*$/.test(rubyVersion) } +function hasBundlerDefaultGem(engine, rubyVersion) { + return isBundler1Default(engine, rubyVersion) || isBundler2Default(engine, rubyVersion) +} + function isBundler1Default(engine, rubyVersion) { if (engine === 'ruby') { return floatVersion(rubyVersion) >= 2.6 && floatVersion(rubyVersion) < 2.7