From d6a695ac2aaee26c3b9ec1d2537f94ea0dfa7f6e Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 2 May 2022 19:39:53 +0200 Subject: [PATCH] Do not install Bundler if RubyGems was updated * Updating RubyGems will install Bundler as a side effect. * Fixes https://github.com/ruby/setup-ruby/issues/326 --- action.yml | 3 ++- bundler.js | 7 ++++++- dist/index.js | 14 ++++++++++---- index.js | 7 ++++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index a0814df..228438c 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,8 @@ inputs: For 'default', no action is taken and the version of RubyGems that comes with Ruby by default is used. For 'latest', `gem update --system` is run to update to the latest RubyGems version. Similarly, if a version number is given, `gem update --system ` is run to update to that version of RubyGems, as long as that version is newer than the one provided by default. - Defaults to 'default'. + required: false + default: 'default' bundler: description: | The version of Bundler to install. Either 'none', 'latest', 'Gemfile.lock', or a version number (e.g., 1, 2, 2.1, 2.1.4). diff --git a/bundler.js b/bundler.js index eafab3a..1097fe7 100644 --- a/bundler.js +++ b/bundler.js @@ -50,9 +50,14 @@ async function afterLockFile(lockFile, platform, engine, rubyVersion) { } } -export async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) { +export async function installBundler(bundlerVersionInput, rubygemsInputSet, lockFile, platform, rubyPrefix, engine, rubyVersion) { let bundlerVersion = bundlerVersionInput + if (rubygemsInputSet && bundlerVersion === 'default') { + console.log('Using the Bundler installed by updating RubyGems') + return 'unknown' + } + if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { bundlerVersion = readBundledWithFromGemfileLock(lockFile) diff --git a/dist/index.js b/dist/index.js index cd55451..82b8074 100644 --- a/dist/index.js +++ b/dist/index.js @@ -64,9 +64,14 @@ async function afterLockFile(lockFile, platform, engine, rubyVersion) { } } -async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) { +async function installBundler(bundlerVersionInput, rubygemsInputSet, lockFile, platform, rubyPrefix, engine, rubyVersion) { let bundlerVersion = bundlerVersionInput + if (rubygemsInputSet && bundlerVersion === 'default') { + console.log('Using the Bundler installed by updating RubyGems') + return 'unknown' + } + if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { bundlerVersion = readBundledWithFromGemfileLock(lockFile) @@ -60882,7 +60887,8 @@ async function setupRuby(options = {}) { await common.measure('Print Ruby version', async () => await exec.exec('ruby', ['--version'])) - if (inputs['rubygems'] !== 'default') { + const rubygemsInputSet = inputs['rubygems'] !== 'default' + if (rubygemsInputSet) { await common.measure('Updating RubyGems', async () => rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix)) } @@ -60895,11 +60901,11 @@ async function setupRuby(options = {}) { } const [gemfile, lockFile] = bundler.detectGemfiles() - let bundlerVersion = "unknown" + let bundlerVersion = 'unknown' if (inputs['bundler'] !== 'none') { bundlerVersion = await common.measure('Installing Bundler', async () => - bundler.installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version)) + bundler.installBundler(inputs['bundler'], rubygemsInputSet, lockFile, platform, rubyPrefix, engine, version)) } if (inputs['bundler-cache'] === 'true') { diff --git a/index.js b/index.js index 8fdf457..77a11f9 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,8 @@ export async function setupRuby(options = {}) { await common.measure('Print Ruby version', async () => await exec.exec('ruby', ['--version'])) - if (inputs['rubygems'] !== 'default') { + const rubygemsInputSet = inputs['rubygems'] !== 'default' + if (rubygemsInputSet) { await common.measure('Updating RubyGems', async () => rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix)) } @@ -79,11 +80,11 @@ export async function setupRuby(options = {}) { } const [gemfile, lockFile] = bundler.detectGemfiles() - let bundlerVersion = "unknown" + let bundlerVersion = 'unknown' if (inputs['bundler'] !== 'none') { bundlerVersion = await common.measure('Installing Bundler', async () => - bundler.installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version)) + bundler.installBundler(inputs['bundler'], rubygemsInputSet, lockFile, platform, rubyPrefix, engine, version)) } if (inputs['bundler-cache'] === 'true') {