diff --git a/README.md b/README.md index 470392e6..ced5d9bf 100644 --- a/README.md +++ b/README.md @@ -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 `!`: diff --git a/python/publish/junit.py b/python/publish/junit.py index d225d6dc..0ec988e9 100644 --- a/python/publish/junit.py +++ b/python/publish/junit.py @@ -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] diff --git a/python/publish_test_results.py b/python/publish_test_results.py index f12539ea..2e89ec52 100644 --- a/python/publish_test_results.py +++ b/python/publish_test_results.py @@ -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 @@ -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 = [] diff --git a/python/test/test_action_script.py b/python/test/test_action_script.py index cd9f810b..b34e7a80 100644 --- a/python/test/test_action_script.py +++ b/python/test/test_action_script.py @@ -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) @@ -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()