Skip to content

Commit

Permalink
fix(pip-compile): Correctly report errors when a lock file is unchang…
Browse files Browse the repository at this point in the history
…ed (#29363)
  • Loading branch information
mbudnek committed May 31, 2024
1 parent 4313b9b commit 635854e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
35 changes: 33 additions & 2 deletions lib/modules/manager/pip-compile/artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { codeBlock } from 'common-tags';
import { mockDeep } from 'jest-mock-extended';
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../../test/exec-util';
import {
envMock,
mockExecAll,
mockExecSequence,
} from '../../../../test/exec-util';
import { Fixtures } from '../../../../test/fixtures';
import { env, fs, git, mocked, partial } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
Expand Down Expand Up @@ -80,7 +84,7 @@ describe('modules/manager/pip-compile/artifacts', () => {
expect(execSnapshots).toEqual([]);
});

it('returns null if unchanged', async () => {
it('returns null if all unchanged', async () => {
fs.readLocalFile.mockResolvedValueOnce(simpleHeader);
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce('new lock');
Expand Down Expand Up @@ -615,5 +619,32 @@ describe('modules/manager/pip-compile/artifacts', () => {
'pip-compile --output-file=requirements.txt requirements.in --upgrade-package=foo==1.0.2 --upgrade-package=bar==2.0.0',
);
});

it('reports errors when a lock file is unchanged', async () => {
fs.readLocalFile.mockResolvedValue(simpleHeader);
mockExecSequence([
new Error('Oh noes!'),
{ stdout: 'This one worked', stderr: '' },
]);
git.getRepoStatus.mockResolvedValue(
partial<StatusResult>({
modified: [],
}),
);
const results = await updateArtifacts({
packageFileName: 'requirements.in',
updatedDeps: [],
newPackageFileContent: 'some new content',
config: {
...config,
lockFiles: ['requirements1.txt', 'requirements2.txt'],
},
});
expect(results).toMatchObject([
{
artifactError: { lockFile: 'requirements1.txt', stderr: 'Oh noes!' },
},
]);
});
});
});
19 changes: 9 additions & 10 deletions lib/modules/manager/pip-compile/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,15 @@ export async function updateArtifacts({
logger.trace({ env: execOptions.extraEnv }, 'pip-compile extra env vars');
await exec(cmd, execOptions);
const status = await getRepoStatus();
if (!status?.modified.includes(outputFileName)) {
return null;
if (status?.modified.includes(outputFileName)) {
result.push({
file: {
type: 'addition',
path: outputFileName,
contents: await readLocalFile(outputFileName, 'utf8'),
},
});
}
result.push({
file: {
type: 'addition',
path: outputFileName,
contents: await readLocalFile(outputFileName, 'utf8'),
},
});
} catch (err) {
// istanbul ignore if
if (err.message === TEMPORARY_ERROR) {
Expand All @@ -150,5 +149,5 @@ export async function updateArtifacts({
}
}
logger.debug('pip-compile: Returning updated output file(s)');
return result;
return result.length === 0 ? null : result;
}

0 comments on commit 635854e

Please sign in to comment.