From 635854e321423a68ee9c31b1822ad7b1dbcc19ce Mon Sep 17 00:00:00 2001 From: Miles Budnek Date: Fri, 31 May 2024 01:19:04 -0400 Subject: [PATCH] fix(pip-compile): Correctly report errors when a lock file is unchanged (#29363) --- .../manager/pip-compile/artifacts.spec.ts | 35 +++++++++++++++++-- lib/modules/manager/pip-compile/artifacts.ts | 19 +++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/lib/modules/manager/pip-compile/artifacts.spec.ts b/lib/modules/manager/pip-compile/artifacts.spec.ts index d106fe441663f6..861c5127bc1242 100644 --- a/lib/modules/manager/pip-compile/artifacts.spec.ts +++ b/lib/modules/manager/pip-compile/artifacts.spec.ts @@ -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'; @@ -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'); @@ -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({ + 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!' }, + }, + ]); + }); }); }); diff --git a/lib/modules/manager/pip-compile/artifacts.ts b/lib/modules/manager/pip-compile/artifacts.ts index 7f8b2ad3434071..6ce9b28b927b50 100644 --- a/lib/modules/manager/pip-compile/artifacts.ts +++ b/lib/modules/manager/pip-compile/artifacts.ts @@ -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) { @@ -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; }