Skip to content

Commit acd187c

Browse files
committed
Install an exact Bundler version with --conservative
Reinstalling an exact version that is already installed changes nothing, but `gem install` removes the gem directory before extracting it again. On self-hosted runners that share a tool cache, a concurrent job then fails at `bundle config` with "cannot load such file -- .../bundler-X.Y.Z/lib/bundler/dsl" (#191). With `--conservative`, RubyGems returns before touching anything when the requirement is already met, including by a default gem. Only exact versions pass the flag, so a `~>` constraint still gets the latest matching release rather than the Bundler the Ruby shipped with (see #48). `--conservative` has worked this way for `gem install` since RubyGems 1.8.23.
1 parent 824c0e2 commit acd187c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎bundler.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
144144
const versionParts = [...bundlerVersion.matchAll(/\d+/g)].length
145145
const bundlerVersionConstraint = versionParts >= 3 ? bundlerVersion : `~> ${bundlerVersion}.0`
146146

147-
await exec.exec(gem, ['install', 'bundler', '-v', bundlerVersionConstraint])
147+
const args = ['install', 'bundler', '-v', bundlerVersionConstraint]
148+
// Reinstalling an exact version that is already there changes nothing, and `gem install`
149+
// removes the gem directory before extracting it again, which breaks the other jobs
150+
// sharing a tool cache on self-hosted runners (#191). A `~>` constraint still gets the
151+
// latest matching release rather than whatever Bundler the Ruby shipped with.
152+
if (versionParts >= 3) {
153+
args.push('--conservative')
154+
}
155+
await exec.exec(gem, args)
148156

149157
return bundlerVersion
150158
}

‎dist/index.js‎

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)