From 7fa0e269a4e109a5768fb0c2ae98e4d236c1857a Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 31 Dec 2025 19:55:12 +0100 Subject: [PATCH] Set BUNDLER_VERSION whenever we know which version to use * Fixes https://github.com/ruby/setup-ruby/issues/845 --- .github/workflows/test.yml | 13 +++++++++++++ bundler.js | 8 ++++---- dist/index.js | 8 ++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad8edbabb..775a053f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -352,6 +352,19 @@ jobs: bundler: 2.2.3 - run: bundle --version | grep -F "Bundler version 2.2.3" + # https://github.com/ruby/setup-ruby/issues/845 + testOlderBundlerVersion: + name: "Test with an older Bundler version than the one of the default gem" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: ./ + with: + ruby-version: '4.0' + bundler: 2.7.2 + bundler-cache: true + - run: bundle --version | grep -F "Bundler version 2.7.2" + testBundlerPre: name: "Test with a Bundler pre/rc version" runs-on: ubuntu-latest diff --git a/bundler.js b/bundler.js index 28f4ca9a3..ff8fc9c3c 100644 --- a/bundler.js +++ b/bundler.js @@ -162,10 +162,10 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer } let envOptions = {} - 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`) + if (bundlerVersion.match(/^\d+/)) { + // If a specific Bundler version is given or determined, we need to specify the version to use explicitly until the lockfile exists. + // Otherwise, a newer version of Bundler might be used. + console.log(`Setting BUNDLER_VERSION=${bundlerVersion} for "bundle config|lock" commands below to ensure Bundler ${bundlerVersion} is used`) envOptions = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } } } diff --git a/dist/index.js b/dist/index.js index 7834ceb51..736f97e69 100644 --- a/dist/index.js +++ b/dist/index.js @@ -176,10 +176,10 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b } let envOptions = {} - 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`) + if (bundlerVersion.match(/^\d+/)) { + // If a specific Bundler version is given or determined, we need to specify the version to use explicitly until the lockfile exists. + // Otherwise, a newer version of Bundler might be used. + console.log(`Setting BUNDLER_VERSION=${bundlerVersion} for "bundle config|lock" commands below to ensure Bundler ${bundlerVersion} is used`) envOptions = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } } }