Skip to content

Commit

Permalink
fix(manager/bundler): Update conservatively if strict fails (#26929)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
benlangfeld and rarkins committed Jan 30, 2024
1 parent 23b7cc1 commit 9608537
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/modules/manager/bundler/artifacts.spec.ts
Expand Up @@ -881,6 +881,38 @@ describe('modules/manager/bundler/artifacts', () => {
{ cmd: 'bundler lock --update foo bar' },
]);
});

it('handles failure of strict updating', async () => {
const execError = new ExecError('Exec error', {
cmd: '',
stdout: '',
stderr: 'version solving has failed',
options: { encoding: 'utf8' },
});
fs.readLocalFile.mockResolvedValue('Current Gemfile.lock');
const execSnapshots = mockExecSequence([
execError,
{ stdout: '', stderr: '' },
]);
git.getRepoStatus.mockResolvedValueOnce(
partial<StatusResult>({
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' },
]);
});
});
});
});
19 changes: 19 additions & 0 deletions lib/modules/manager/bundler/artifacts.ts
Expand Up @@ -245,6 +245,25 @@ 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')) {
logger.debug('Failed to lock strictly, retrying non-strict');
const newConfig = {
...config,
postUpdateOptions: [
...(config.postUpdateOptions ?? []),
'bundlerConservative',
],
};
return updateArtifacts(
{
packageFileName,
updatedDeps,
newPackageFileContent,
config: newConfig,
},
recursionLimit - 1,
);
}
const resolveMatches: string[] = getResolvedPackages(output).filter(
(depName) => !updatedDepNames.includes(depName),
);
Expand Down

0 comments on commit 9608537

Please sign in to comment.