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

Improve logging of filetype-specific patterns #345

Merged
merged 13 commits into from Aug 16, 2022
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -212,11 +212,11 @@ With `comment_mode: off`, the `pull-requests: write` permission is not needed.

## Configuration

Files can be selected via the `junit_files`, `xunit_files`, and `trx_files` options.
Files can be selected via the `junit_files`, `nunit_files`, `xunit_files`, and `trx_files` options.
They support [glob wildcards](https://docs.python.org/3/library/glob.html#glob.glob) like `*`, `**`, `?` and `[]`.
The `**` wildcard matches all files and directories recursively: `./`, `./*/`, `./*/*/`, etc.

At least one of `junit_files`, `xunit_files`, and `trx_files` options have to be set.
At least one of `junit_files`, `nunit_files`, `xunit_files`, and `trx_files` options have to be set.

You can provide multiple file patterns, one pattern per line. Patterns starting with `!` exclude the matching files.
There have to be at least one pattern starting without a `!`:
Expand Down
4 changes: 2 additions & 2 deletions python/publish/junit.py
Expand Up @@ -136,8 +136,8 @@ def safe_parse_xml_file(path: str, parse: Callable[[str], JUnitTree]) -> JUnitTr


def progress_safe_parse_xml_file(files: Iterable[str],
parse: Callable[[str], JUnitTree],
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile]) -> Iterable[ParsedJUnitFile]:
parse: Callable[[str], JUnitTree],
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile]) -> Iterable[ParsedJUnitFile]:
return [progress((file, safe_parse_xml_file(file, parse))) for file in files]


Expand Down
16 changes: 8 additions & 8 deletions python/publish_test_results.py
Expand Up @@ -60,17 +60,17 @@ def get_files(multiline_files_globs: str) -> List[str]:
return list(included - excluded)


def expand_glob(pattern: Optional[str], gha: GithubAction) -> List[str]:
def expand_glob(pattern: Optional[str], file_format: str, gha: GithubAction) -> List[str]:
if not pattern:
return []

files = get_files(pattern)

if len(files) == 0:
gha.warning(f'Could not find any files for {pattern}')
gha.warning(f'Could not find any {file_format} files for {pattern}')
else:
logger.info(f'Reading {pattern} ({get_number_of_files(files)}, {get_files_size(files)})')
logger.debug(f'reading {list(files)}')
logger.info(f'Reading {file_format} files {pattern} ({get_number_of_files(files)}, {get_files_size(files)})')
logger.debug(f'reading {file_format} files {list(files)}')

return files

Expand All @@ -93,10 +93,10 @@ def get_number_of_files(files: List[str]) -> str:

def parse_files(settings: Settings, gha: GithubAction) -> ParsedUnitTestResultsWithCommit:
# expand file globs
junit_files = expand_glob(settings.junit_files_glob, gha)
nunit_files = expand_glob(settings.nunit_files_glob, gha)
xunit_files = expand_glob(settings.xunit_files_glob, gha)
trx_files = expand_glob(settings.trx_files_glob, gha)
junit_files = expand_glob(settings.junit_files_glob, 'JUnit', gha)
nunit_files = expand_glob(settings.nunit_files_glob, 'NUnit', gha)
xunit_files = expand_glob(settings.xunit_files_glob, 'XUnit', gha)
trx_files = expand_glob(settings.trx_files_glob, 'TRX', gha)

elems = []

Expand Down
24 changes: 19 additions & 5 deletions python/test/test_action_script.py
Expand Up @@ -805,7 +805,21 @@ def test_parse_files(self):
nunit_files_glob=str(test_files_path / 'nunit' / '**' / '*.xml'),
xunit_files_glob=str(test_files_path / 'xunit' / '**' / '*.xml'),
trx_files_glob=str(test_files_path / 'trx' / '**' / '*.trx'))
actual = parse_files(settings, gha)
with mock.patch('publish_test_results.logger') as l:
actual = parse_files(settings, gha)

self.assertEqual(5, len(l.info.call_args_list))
self.assertTrue(any([call.args[0].startswith(f'Reading JUnit files {settings.junit_files_glob} (26 files, ') for call in l.info.call_args_list]))
self.assertTrue(any([call.args[0].startswith(f'Reading NUnit files {settings.nunit_files_glob} (23 files, ') for call in l.info.call_args_list]))
self.assertTrue(any([call.args[0].startswith(f'Reading XUnit files {settings.xunit_files_glob} (8 files, ') for call in l.info.call_args_list]))
self.assertTrue(any([call.args[0].startswith(f'Reading TRX files {settings.trx_files_glob} (9 files, ') for call in l.info.call_args_list]))
self.assertTrue(any([call.args[0].startswith(f'Finished reading 66 files in ') for call in l.info.call_args_list]))

self.assertEqual(4, len(l.debug.call_args_list))
self.assertTrue(any([call.args[0].startswith('reading JUnit files [') for call in l.debug.call_args_list]))
self.assertTrue(any([call.args[0].startswith('reading NUnit files [') for call in l.debug.call_args_list]))
self.assertTrue(any([call.args[0].startswith('reading XUnit files [') for call in l.debug.call_args_list]))
self.assertTrue(any([call.args[0].startswith('reading TRX files [') for call in l.debug.call_args_list]))

self.assertEqual([], gha.method_calls)

Expand Down Expand Up @@ -878,10 +892,10 @@ def test_parse_files_no_matches(self):
actual = parse_files(settings, gha)

gha.warning.assert_has_calls([
mock.call(f'Could not find any files for {missing_junit}'),
mock.call(f'Could not find any files for {missing_nunit}'),
mock.call(f'Could not find any files for {missing_xunit}'),
mock.call(f'Could not find any files for {missing_trx}')
mock.call(f'Could not find any JUnit files for {missing_junit}'),
mock.call(f'Could not find any NUnit files for {missing_nunit}'),
mock.call(f'Could not find any XUnit files for {missing_xunit}'),
mock.call(f'Could not find any TRX files for {missing_trx}')
])
gha.error.assert_not_called()

Expand Down