Skip to content

Commit

Permalink
fix(bundler): Set exec cwd to lock file (#24379)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-wonolo committed Sep 13, 2023
1 parent c5aae24 commit ef504c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
23 changes: 23 additions & 0 deletions lib/modules/manager/bundler/artifacts.spec.ts
Expand Up @@ -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<StatusResult>({
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);
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/bundler/artifacts.ts
Expand Up @@ -174,7 +174,7 @@ export async function updateArtifacts(
}

const execOptions: ExecOptions = {
cwdFile: packageFileName,
cwdFile: lockFileName,
extraEnv: {
...bundlerHostRulesVariables,
GEM_HOME: await ensureCacheDir('bundler'),
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/manager/bundler/common.ts
Expand Up @@ -76,8 +76,9 @@ export function getBundlerConstraint(
export async function getLockFilePath(
packageFilePath: string
): Promise<string> {
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;
}

0 comments on commit ef504c0

Please sign in to comment.