From a5a3b90fc5c2205716195f1ec7ce57c41f310d63 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Tue, 30 Jan 2024 13:14:52 -0300 Subject: [PATCH] fix(manager/bundler): Multiple indications of strict mode failure See: * https://github.com/renovatebot/renovate/pull/26929 * https://github.com/rubygems/rubygems/issues/7369 --- lib/modules/manager/bundler/artifacts.spec.ts | 35 ++++++++++++++++++- lib/modules/manager/bundler/artifacts.ts | 6 +++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/bundler/artifacts.spec.ts b/lib/modules/manager/bundler/artifacts.spec.ts index 114ad5d8995d2f..66cb6af9da5584 100644 --- a/lib/modules/manager/bundler/artifacts.spec.ts +++ b/lib/modules/manager/bundler/artifacts.spec.ts @@ -882,7 +882,7 @@ describe('modules/manager/bundler/artifacts', () => { ]); }); - it('handles failure of strict updating', async () => { + it('handles failure of strict updating for version solving', async () => { const execError = new ExecError('Exec error', { cmd: '', stdout: '', @@ -913,6 +913,39 @@ describe('modules/manager/bundler/artifacts', () => { { cmd: 'bundler lock --minor --conservative --update foo' }, ]); }); + + it('handles failure of strict updating for missing gem', async () => { + // See https://github.com/rubygems/rubygems/issues/7369 + const execError = new ExecError('Exec error', { + cmd: '', + stdout: '', + stderr: "Could not find gems matching 'foo ", + options: { encoding: 'utf8' }, + }); + fs.readLocalFile.mockResolvedValue('Current Gemfile.lock'); + const execSnapshots = mockExecSequence([ + execError, + { stdout: '', stderr: '' }, + ]); + git.getRepoStatus.mockResolvedValueOnce( + partial({ + modified: ['Gemfile.lock'], + }), + ); + + const res = await updateArtifacts({ + packageFileName: 'Gemfile', + updatedDeps: [{ depName: 'foo', updateType: 'minor' }], + newPackageFileContent: '{}', + config, + }); + + expect(res).toMatchObject([{ file: { path: 'Gemfile.lock' } }]); + expect(execSnapshots).toMatchObject([ + { cmd: 'bundler lock --minor --strict --update foo' }, + { cmd: 'bundler lock --minor --conservative --update foo' }, + ]); + }); }); }); }); diff --git a/lib/modules/manager/bundler/artifacts.ts b/lib/modules/manager/bundler/artifacts.ts index e7c5f7dd43d3a2..5b4f527a0aee51 100644 --- a/lib/modules/manager/bundler/artifacts.ts +++ b/lib/modules/manager/bundler/artifacts.ts @@ -245,7 +245,11 @@ export async function updateArtifacts( memCache.set('bundlerArtifactsError', BUNDLER_INVALID_CREDENTIALS); throw new Error(BUNDLER_INVALID_CREDENTIALS); } - if (recursionLimit > 0 && output.includes('version solving has failed')) { + if ( + recursionLimit > 0 && + (output.includes('version solving has failed') || + output.includes('Could not find gem')) + ) { logger.debug('Failed to lock strictly, retrying non-strict'); const newConfig = { ...config,