Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pip-compile): Correctly report errors when a lock file is unchanged #29363

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}