diff --git a/common.js b/common.js index d16152c..de7293c 100644 --- a/common.js +++ b/common.js @@ -40,6 +40,25 @@ export function isStableVersion(rubyVersion) { return /^\d+(\.\d+)*$/.test(rubyVersion) } +export function isBundler2Default(engine, rubyVersion) { + if (engine === 'ruby') { + return isHeadVersion(rubyVersion) || floatVersion(rubyVersion) >= 2.7 + } else if (engine === 'truffleruby') { + return isHeadVersion(rubyVersion) + } else { + return false + } +} + +export function floatVersion(rubyVersion) { + const match = rubyVersion.match(/^\d+\.\d+/) + if (match) { + return parseFloat(match[0]) + } else { + return 0.0 + } +} + export async function hashFile(file) { // See https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts const hash = crypto.createHash('sha256') diff --git a/dist/index.js b/dist/index.js index ed5e00c..c083475 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32114,6 +32114,8 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "measure", function() { return measure; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isHeadVersion", function() { return isHeadVersion; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isStableVersion", function() { return isStableVersion; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isBundler2Default", function() { return isBundler2Default; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "floatVersion", function() { return floatVersion; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hashFile", function() { return hashFile; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getVirtualEnvironmentName", function() { return getVirtualEnvironmentName; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shouldUseToolCache", function() { return shouldUseToolCache; }); @@ -32163,6 +32165,25 @@ function isStableVersion(rubyVersion) { return /^\d+(\.\d+)*$/.test(rubyVersion) } +function isBundler2Default(engine, rubyVersion) { + if (engine === 'ruby') { + return isHeadVersion(rubyVersion) || floatVersion(rubyVersion) >= 2.7 + } else if (engine === 'truffleruby') { + return isHeadVersion(rubyVersion) + } else { + return false + } +} + +function floatVersion(rubyVersion) { + const match = rubyVersion.match(/^\d+\.\d+/) + if (match) { + return parseFloat(match[0]) + } else { + return 0.0 + } +} + async function hashFile(file) { // See https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts const hash = crypto.createHash('sha256') @@ -51416,7 +51437,7 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi bundlerVersion = '1' } - if ((engine === 'ruby' || engine === 'truffleruby') && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') { + if (common.isHeadVersion(rubyVersion) && common.isBundler2Default(engine, rubyVersion) && bundlerVersion === '2') { console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`) } else if (engine === 'truffleruby' && !common.isHeadVersion(rubyVersion) && bundlerVersion === '1') { console.log(`Using Bundler 1 shipped with ${engine}`) @@ -51434,20 +51455,25 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b return false } - // Before the lockfile exists, we need to specify which Bundler version to use explicitly - const optionsWithBundlerVersion = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } } + let envOptions = {} + if (bundlerVersion.startsWith('1') && common.isBundler2Default(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 } } + } // config const path = 'vendor/bundle' - await exec.exec('bundle', ['config', '--local', 'path', path], optionsWithBundlerVersion) + await exec.exec('bundle', ['config', '--local', 'path', path], envOptions) if (fs.existsSync(lockFile)) { - await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], optionsWithBundlerVersion) + await exec.exec('bundle', ['config', '--local', '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. - await exec.exec('bundle', ['lock'], optionsWithBundlerVersion) + await exec.exec('bundle', ['lock'], envOptions) } // cache key diff --git a/index.js b/index.js index 7d0e58a..5c84491 100644 --- a/index.js +++ b/index.js @@ -222,7 +222,7 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi bundlerVersion = '1' } - if ((engine === 'ruby' || engine === 'truffleruby') && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') { + if (common.isHeadVersion(rubyVersion) && common.isBundler2Default(engine, rubyVersion) && bundlerVersion === '2') { console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`) } else if (engine === 'truffleruby' && !common.isHeadVersion(rubyVersion) && bundlerVersion === '1') { console.log(`Using Bundler 1 shipped with ${engine}`) @@ -240,20 +240,25 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b return false } - // Before the lockfile exists, we need to specify which Bundler version to use explicitly - const optionsWithBundlerVersion = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } } + let envOptions = {} + if (bundlerVersion.startsWith('1') && common.isBundler2Default(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 } } + } // config const path = 'vendor/bundle' - await exec.exec('bundle', ['config', '--local', 'path', path], optionsWithBundlerVersion) + await exec.exec('bundle', ['config', '--local', 'path', path], envOptions) if (fs.existsSync(lockFile)) { - await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], optionsWithBundlerVersion) + await exec.exec('bundle', ['config', '--local', '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. - await exec.exec('bundle', ['lock'], optionsWithBundlerVersion) + await exec.exec('bundle', ['lock'], envOptions) } // cache key