def upload_test_report_as_gist(test_report, descr=None, fn=None): """Upload test report as a gist.""" if descr is None: descr = "EasyBuild test report" if fn is None: fn = 'easybuild_test_report_%s.md' % strftime("%Y%M%d-UTC-%H-%M-%S", gmtime()) user = build_option('github_user') gist_url = create_gist(test_report, descr=descr, fn=fn, github_user=user) return gist_url
def create_test_report(msg, ecs_with_res, init_session_state, pr_nr=None, gist_log=False): """Create test report for easyconfigs PR, in Markdown format.""" user = build_option('github_user') end_time = gmtime() # create a gist with a full test report test_report = [] if pr_nr is not None: test_report.extend([ "Test report for https://github.com/hpcugent/easybuild-easyconfigs/pull/%s" % pr_nr, "", ]) test_report.extend([ "#### Test result", "%s" % msg, "", ]) build_overview = [] for (ec, ec_res) in ecs_with_res: test_log = '' if ec_res.get('success', False): test_result = 'SUCCESS' else: # compose test result string test_result = 'FAIL ' if 'err' in ec_res: if isinstance(ec_res['err'], EasyBuildError): test_result += '(build issue)' else: test_result += '(unhandled exception: %s)' % ec_res['err'].__class__.__name__ else: test_result += '(unknown cause, not an exception?!)' # create gist for log file (if desired and available) if gist_log and 'log_file' in ec_res: logtxt = read_file(ec_res['log_file']) partial_log_txt = '\n'.join(logtxt.split('\n')[-500:]) descr = "(partial) EasyBuild log for failed build of %s" % ec['spec'] if pr_nr is not None: descr += " (PR #%s)" % pr_nr fn = '%s_partial.log' % os.path.basename(ec['spec'])[:-3] gist_url = create_gist(partial_log_txt, fn, descr=descr, github_user=user) test_log = "(partial log available at %s)" % gist_url build_overview.append(" * **%s** _%s_ %s" % (test_result, os.path.basename(ec['spec']), test_log)) test_report.extend(["#### Overview of tested easyconfigs (in order)"] + build_overview + [""]) time_format = "%a, %d %b %Y %H:%M:%S +0000 (UTC)" start_time = strftime(time_format, init_session_state['time']) end_time = strftime(time_format, end_time) test_report.extend(["#### Time info", " * start: %s" % start_time, " * end: %s" % end_time, ""]) eb_config = [x for x in sorted(init_session_state['easybuild_configuration'])] test_report.extend([ "#### EasyBuild info", " * easybuild-framework version: %s" % FRAMEWORK_VERSION, " * easybuild-easyblocks version: %s" % EASYBLOCKS_VERSION, " * command line:", "```", "eb %s" % ' '.join(sys.argv[1:]), "```", " * full configuration (includes defaults):", "```", ] + eb_config + ["````", ""]) system_info = init_session_state['system_info'] system_info = [" * _%s:_ %s" % (key.replace('_', ' '), system_info[key]) for key in sorted(system_info.keys())] test_report.extend(["#### System info"] + system_info + [""]) module_list = init_session_state['module_list'] if module_list: module_list = [" * %s" % mod['mod_name'] for mod in module_list] else: module_list = [" * (none)"] test_report.extend(["#### List of loaded modules"] + module_list + [""]) environ_dump = init_session_state['environment'] environment = [] env_filter = build_option('test_report_env_filter') for key in sorted(environ_dump.keys()): if env_filter is not None and env_filter.search(key): continue else: environment += ["%s = %s" % (key, environ_dump[key])] test_report.extend(["#### Environment", "```"] + environment + ["```"]) return '\n'.join(test_report)
def create_test_report(msg, ecs_with_res, init_session_state, pr_nr=None, gist_log=False): """Create test report for easyconfigs PR, in Markdown format.""" user = build_option('github_user') end_time = gmtime() # create a gist with a full test report test_report = [] if pr_nr is not None: test_report.extend([ "Test report for https://github.com/hpcugent/easybuild-easyconfigs/pull/%s" % pr_nr, "", ]) test_report.extend([ "#### Test result", "%s" % msg, "", ]) build_overview = [] for (ec, ec_res) in ecs_with_res: test_log = '' if ec_res.get('success', False): test_result = 'SUCCESS' else: # compose test result string test_result = 'FAIL ' if 'err' in ec_res: if isinstance(ec_res['err'], EasyBuildError): test_result += '(build issue)' else: test_result += '(unhandled exception: %s)' % ec_res[ 'err'].__class__.__name__ else: test_result += '(unknown cause, not an exception?!)' # create gist for log file (if desired and available) if gist_log and 'log_file' in ec_res: logtxt = read_file(ec_res['log_file']) partial_log_txt = '\n'.join(logtxt.split('\n')[-500:]) descr = "(partial) EasyBuild log for failed build of %s" % ec[ 'spec'] if pr_nr is not None: descr += " (PR #%s)" % pr_nr fn = '%s_partial.log' % os.path.basename(ec['spec'])[:-3] gist_url = create_gist(partial_log_txt, fn, descr=descr, github_user=user) test_log = "(partial log available at %s)" % gist_url build_overview.append( " * **%s** _%s_ %s" % (test_result, os.path.basename(ec['spec']), test_log)) test_report.extend(["#### Overview of tested easyconfigs (in order)"] + build_overview + [""]) time_format = "%a, %d %b %Y %H:%M:%S +0000 (UTC)" start_time = strftime(time_format, init_session_state['time']) end_time = strftime(time_format, end_time) test_report.extend([ "#### Time info", " * start: %s" % start_time, " * end: %s" % end_time, "" ]) eb_config = [ x for x in sorted(init_session_state['easybuild_configuration']) ] test_report.extend([ "#### EasyBuild info", " * easybuild-framework version: %s" % FRAMEWORK_VERSION, " * easybuild-easyblocks version: %s" % EASYBLOCKS_VERSION, " * command line:", "```", "eb %s" % ' '.join(sys.argv[1:]), "```", " * full configuration (includes defaults):", "```", ] + eb_config + ["````", ""]) system_info = init_session_state['system_info'] system_info = [ " * _%s:_ %s" % (key.replace('_', ' '), system_info[key]) for key in sorted(system_info.keys()) ] test_report.extend(["#### System info"] + system_info + [""]) module_list = init_session_state['module_list'] if module_list: module_list = [" * %s" % mod['mod_name'] for mod in module_list] else: module_list = [" * (none)"] test_report.extend(["#### List of loaded modules"] + module_list + [""]) environ_dump = init_session_state['environment'] environment = [] env_filter = build_option('test_report_env_filter') for key in sorted(environ_dump.keys()): if env_filter is not None and env_filter.search(key): continue else: environment += ["%s = %s" % (key, environ_dump[key])] test_report.extend(["#### Environment", "```"] + environment + ["```"]) return '\n'.join(test_report)