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

feat(postUpgradeTasks): improve debug logging #31514

Merged
merged 1 commit into from
Sep 21, 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
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<BranchUpgradeConfig>([
{
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<StatusResult>({
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',
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)) {
Expand Down