def main(settings: Settings) -> None: gha = GithubAction() # resolve the files_glob to files files = [str(file) for file in pathlib.Path().glob(settings.files_glob)] if len(files) == 0: gha.warning(f'Could not find any files for {settings.files_glob}') else: logger.info('reading {}'.format(settings.files_glob)) logger.debug('reading {}'.format(list(files))) # get the unit test results parsed = parse_junit_xml_files(files).with_commit(settings.commit) [ gha.error(message=f'Error processing result file: {error.message}', file=error.file, line=error.line, column=error.column) for error in parsed.errors ] # process the parsed results results = get_test_results(parsed, settings.dedup_classes_by_file_name) # turn them into stats stats = get_stats(results) # derive check run conclusion from files conclusion = get_conclusion(parsed) # publish the delta stats gh = github.Github(login_or_token=settings.token, base_url=settings.api_url) Publisher(settings, gh, gha).publish(stats, results.case_results, conclusion)
def main(settings: Settings) -> None: gha = GithubAction() # we cannot create a check run or pull request comment # when running on pull_request event from a fork if settings.event_name == 'pull_request' and \ settings.event.get('pull_request', {}).get('head', {}).get('repo', {}).get('full_name') != settings.repo: gha.warning( f'This action is running on a pull_request event for a fork repository. ' f'It cannot do anything useful like creating check runs or pull request comments.' ) return # resolve the files_glob to files files = [str(file) for file in pathlib.Path().glob(settings.files_glob)] if len(files) == 0: gha.warning(f'Could not find any files for {settings.files_glob}') else: logger.info(f'reading {settings.files_glob}') logger.debug(f'reading {list(files)}') # get the unit test results parsed = parse_junit_xml_files(files).with_commit(settings.commit) [ gha.error(message=f'Error processing result file: {error.message}', file=error.file, line=error.line, column=error.column) for error in parsed.errors ] # process the parsed results results = get_test_results(parsed, settings.dedup_classes_by_file_name) # turn them into stats stats = get_stats(results) # derive check run conclusion from files conclusion = get_conclusion(parsed, fail_on_failures=settings.fail_on_failures, fail_on_errors=settings.fail_on_errors) # publish the delta stats retry = Retry(total=10, backoff_factor=1) gh = github.Github(login_or_token=settings.token, base_url=settings.api_url, retry=retry) Publisher(settings, gh, gha).publish(stats, results.case_results, conclusion)
def main(settings: Settings) -> None: files = [str(file) for file in pathlib.Path().glob(settings.files_glob)] logger.info('reading {}: {}'.format(settings.files_glob, list(files))) # get the unit test results parsed = parse_junit_xml_files(files).with_commit(settings.commit) # process the parsed results results = get_test_results(parsed, settings.dedup_classes_by_file_name) # turn them into stats stats = get_stats(results) # publish the delta stats gh = Github(settings.token) Publisher(settings, gh).publish(stats, results.case_results)
def test_get_stats(self): self.assertEqual(get_stats(UnitTestResults( files=1, suites=2, suite_tests=20, suite_skipped=5, suite_failures=6, suite_errors=7, suite_time=3, cases=40, cases_skipped=11, cases_failures=12, cases_errors=13, cases_time=4, case_results=UnitTestCaseResults(), tests=30, tests_skipped=8, tests_failures=9, tests_errors=10, commit='commit' )), UnitTestRunResults( files=1, suites=2, duration=3, tests=30, tests_succ=3, tests_skip=8, tests_fail=9, tests_error=10, runs=20, runs_succ=2, runs_skip=5, runs_fail=6, runs_error=7, commit='commit' ))