Skip to content

Commit dbbcf44

Browse files
committed
Skip reinstalling an exact Bundler version that is already installed
When Gemfile.lock names an exact version, `gem install bundler -v X.Y.Z` reinstalls it even if it is already there: RubyGems removes the gem directory and extracts it again. On self-hosted runners that share a tool cache, another job loading Bundler at that moment fails with "cannot load such file -- bundler/dsl". Checking `gem list --installed` first leaves an installed version alone; it is the same gem either way. Version ranges still install, so `bundler: 2` and the like keep picking up new releases. Claude-Session: https://claude.ai/code/session_01QXQDfTwJ3WAbfys8YQKrWF
1 parent 824c0e2 commit dbbcf44

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎bundler.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,24 @@ 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+
// Reinstalling an exact version that is already there changes nothing, and `gem install`
148+
// removes the gem directory before extracting it again, which breaks the other jobs
149+
// sharing a tool cache on self-hosted runners (#191)
150+
if (versionParts >= 3 && await isGemInstalled(gem, 'bundler', bundlerVersion)) {
151+
console.log(`Bundler ${bundlerVersion} is already installed`)
152+
return bundlerVersion
153+
}
154+
147155
await exec.exec(gem, ['install', 'bundler', '-v', bundlerVersionConstraint])
148156

149157
return bundlerVersion
150158
}
151159

160+
async function isGemInstalled(gem, name, version) {
161+
const { exitCode } = await exec.getExecOutput(gem, ['list', '--installed', `^${name}$`, '-v', version], { ignoreReturnCode: true, silent: true })
162+
return exitCode === 0
163+
}
164+
152165
function bundlerConfigSetArgs(bundlerVersion, key, value) {
153166
if (bundlerVersion.startsWith('1')) {
154167
return ['config', '--local', key, value]

‎dist/index.js‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)