From ef504c07383046fb40309ad9886afdc0ca310d45 Mon Sep 17 00:00:00 2001 From: Jorge Villacorta <58479606+jorge-wonolo@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:36:34 -0400 Subject: [PATCH] fix(bundler): Set exec cwd to lock file (#24379) --- lib/modules/manager/bundler/artifacts.spec.ts | 23 +++++++++++++++++++ lib/modules/manager/bundler/artifacts.ts | 2 +- lib/modules/manager/bundler/common.ts | 5 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/modules/manager/bundler/artifacts.spec.ts b/lib/modules/manager/bundler/artifacts.spec.ts index d4bbf4d8b8e866..d8fdc1c09e0433 100644 --- a/lib/modules/manager/bundler/artifacts.spec.ts +++ b/lib/modules/manager/bundler/artifacts.spec.ts @@ -103,6 +103,29 @@ describe('modules/manager/bundler/artifacts', () => { ]); }); + it('executes commands from lockFile path', async () => { + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(); + const execSnapshots = mockExecAll(); + git.getRepoStatus.mockResolvedValueOnce( + partial({ + modified: [], + }) + ); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock'); + expect( + await updateArtifacts({ + packageFileName: 'teamA/Gemfile', + updatedDeps: [{ depName: 'foo' }, { depName: 'bar' }], + newPackageFileContent: 'Updated Gemfile content', + config, + }) + ).toBeNull(); + expect(execSnapshots).toMatchObject([ + { options: { cwd: '/tmp/github/some/repo' } }, + ]); + }); + it('works for default binarySource', async () => { fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.readLocalFile.mockResolvedValueOnce(null); diff --git a/lib/modules/manager/bundler/artifacts.ts b/lib/modules/manager/bundler/artifacts.ts index 7e363484cea25e..a1a14341248fd9 100644 --- a/lib/modules/manager/bundler/artifacts.ts +++ b/lib/modules/manager/bundler/artifacts.ts @@ -174,7 +174,7 @@ export async function updateArtifacts( } const execOptions: ExecOptions = { - cwdFile: packageFileName, + cwdFile: lockFileName, extraEnv: { ...bundlerHostRulesVariables, GEM_HOME: await ensureCacheDir('bundler'), diff --git a/lib/modules/manager/bundler/common.ts b/lib/modules/manager/bundler/common.ts index 8e35c77ea57b0d..43e55f5f31df90 100644 --- a/lib/modules/manager/bundler/common.ts +++ b/lib/modules/manager/bundler/common.ts @@ -76,8 +76,9 @@ export function getBundlerConstraint( export async function getLockFilePath( packageFilePath: string ): Promise { - logger.debug(`Looking for lockfile for ${packageFilePath}`); - return (await localPathExists(`${packageFilePath}.lock`)) + const lockFilePath = (await localPathExists(`${packageFilePath}.lock`)) ? `${packageFilePath}.lock` : `Gemfile.lock`; + logger.debug(`Lockfile for ${packageFilePath} found in ${lockFilePath}`); + return lockFilePath; }