diff --git a/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts b/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts index da750d0b0a4166..dd823de3abfa1b 100644 --- a/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts +++ b/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts @@ -1,4 +1,4 @@ -import { fs, git, partial } from '../../../../../test/util'; +import { fs, git, logger, partial } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { StatusResult } from '../../../../util/git/types'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; @@ -114,5 +114,58 @@ describe('workers/repository/update/branch/execute-post-upgrade-commands', () => expect(res.updatedArtifacts).toHaveLength(0); expect(fs.writeLocalFile).toHaveBeenCalledTimes(1); }); + + it('logs files which do not match fileFilters', async () => { + const commands = partial([ + { + manager: 'some-manager', + branchName: 'main', + postUpgradeTasks: { + executionMode: 'branch', + commands: ['command'], + fileFilters: ['*.txt'], + }, + }, + ]); + const config: BranchConfig = { + manager: 'some-manager', + updatedPackageFiles: [ + { type: 'addition', path: 'some-existing-dir', contents: '' }, + { type: 'addition', path: 'artifact', contents: '' }, + ], + upgrades: [], + branchName: 'main', + baseBranch: 'base', + }; + git.getRepoStatus.mockResolvedValueOnce( + partial({ + modified: ['not-a-txt-file'], + not_added: [], + deleted: [], + }), + ); + GlobalConfig.set({ + localDir: __dirname, + allowedPostUpgradeCommands: ['some-command'], + }); + fs.localPathIsFile + .mockResolvedValueOnce(true) + .mockResolvedValueOnce(false); + fs.localPathExists + .mockResolvedValueOnce(true) + .mockResolvedValueOnce(true); + + const res = await postUpgradeCommands.postUpgradeCommandsExecutor( + commands, + config, + ); + + expect(res.updatedArtifacts).toHaveLength(0); + expect(fs.writeLocalFile).toHaveBeenCalledTimes(1); + expect(logger.logger.debug).toHaveBeenCalledWith( + { file: 'not-a-txt-file' }, + 'Post-upgrade file did not match any file filters', + ); + }); }); }); diff --git a/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts b/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts index fd4aa9d14bae2d..b295198c37036a 100644 --- a/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts +++ b/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts @@ -109,9 +109,32 @@ export async function postUpgradeCommandsExecutor( const status = await getRepoStatus(); - for (const relativePath of status.modified.concat(status.not_added)) { + logger.trace({ status }, 'git status after post-upgrade tasks'); + + logger.debug( + { + addedCount: status.not_added?.length, + modifiedCount: status.modified?.length, + deletedCount: status.deleted?.length, + }, + 'git status counts after post-upgrade tasks', + ); + + const addedOrModifiedFiles = [ + ...coerceArray(status.not_added), + ...coerceArray(status.modified), + ]; + + logger.trace({ addedOrModifiedFiles }, 'Added or modified files'); + logger.debug( + `Checking ${addedOrModifiedFiles.length} added or modified files for post-upgrade changes`, + ); + + for (const relativePath of addedOrModifiedFiles) { + let fileMatched = false; for (const pattern of fileFilters) { if (minimatch(pattern, { dot: true }).match(relativePath)) { + fileMatched = true; logger.debug( { file: relativePath, pattern }, 'Post-upgrade file saved', @@ -135,6 +158,12 @@ export async function postUpgradeCommandsExecutor( ); } } + if (!fileMatched) { + logger.debug( + { file: relativePath }, + 'Post-upgrade file did not match any file filters', + ); + } } for (const relativePath of coerceArray(status.deleted)) {