diff --git a/src/drivers/test/build_create_analyze_test.py b/src/drivers/test/build_create_analyze_test.py index 8fd025d2..2de90139 100644 --- a/src/drivers/test/build_create_analyze_test.py +++ b/src/drivers/test/build_create_analyze_test.py @@ -766,15 +766,16 @@ def find_last_xlsx_file(curr_results_path): else: detailed = False - curr_results_timestamp = curr_results_path.split("--")[-1].replace(".xlsx", "") files = os.listdir() + print(files) files = [x for x in files if "diff" not in x] if detailed: - files = [x for x in files if x.endswith(".xlsx") and "detailed" in x and curr_results_timestamp not in x] + files = [x for x in files if x.endswith(".xlsx") and "detailed" in x and x != curr_results_path] else: - files = [x for x in files if x.endswith(".xlsx") and "detailed" not in x and curr_results_timestamp not in x] + files = [x for x in files if x.endswith(".xlsx") and "detailed" not in x and x != curr_results_path] files.sort(key=os.path.getmtime, reverse=True) - + if len(files) == 0: + return None return files[0] @@ -788,30 +789,23 @@ def compare_health_results(curr_results_path): Returns: None """ - if not args.connection_string or not args.share_name and not args.local_result_storage: + if not args.connection_string or not args.share_name: raise Exception("Azure credentials not provided. Cannot compare results.") - # get most recent xlsx results file - if args.local_result_storage: - prev_results = find_last_xlsx_file(curr_results_path) - if prev_results == None: - print("No previous results found.") - return None - else: - try: - prev_results = 'azure-'+curr_results_path - _ = download_file_from_azure(file_to_download=prev_results, - file_name=curr_results_path, file_directory="") - - except Exception as e: - if "ResourceNotFound" in str(e): - print("No previous results found. Uploading current results to Azure...") - upload_results_to_azure(file_to_upload=curr_results_path, - file_name=curr_results_path, file_directory="") - exit(1) - else: - print("Error downloading previous results ") - exit(1) + try: + prev_results = 'azure-'+curr_results_path + _ = download_file_from_azure(file_to_download=prev_results, + file_name=curr_results_path, file_directory="") + + except Exception as e: + if "ResourceNotFound" in str(e): + print("No previous results found. Uploading current results to Azure...") + upload_results_to_azure(file_to_upload=curr_results_path, + file_name=curr_results_path, file_directory="") + exit(1) + else: + print("Error downloading previous results ") + exit(1) prev_results_df = pd.read_excel(prev_results, index_col=0, sheet_name=0) prev_results_codeql_version_df = pd.read_excel(prev_results, index_col=0, sheet_name=1) @@ -838,6 +832,8 @@ def compare_health_results(curr_results_path): upload_results_to_azure(file_to_upload=curr_results_path, file_name=curr_results_path, file_directory="") exit(1) + + with pd.ExcelWriter("diff" + curr_results_path) as writer: diff_results.to_excel(writer, sheet_name="Diff") codeql_version_df.to_excel(writer, sheet_name="Current CodeQL Version") @@ -846,23 +842,25 @@ def compare_health_results(curr_results_path): prev_results_codeql_version_df.to_excel(writer, sheet_name="Previous CodeQL Version") prev_results_codeql_packs_df.to_excel(writer, sheet_name="Previous CodeQL Packs") prev_results_system_info_df.to_excel(writer, sheet_name="Previous System Info") - - print("Saved diff results") - # upload new results to Azure - if not args.local_result_storage: - - print("Uploading results") - upload_results_to_azure(file_to_upload=curr_results_path, - file_name=curr_results_path, file_directory="") - # upload diff to Azure - print("Uploading diff results") - upload_results_to_azure(file_to_upload="diff" + curr_results_path, - file_name="diff" + curr_results_path, file_directory="") - - #upload_blob_to_azure("diff"+curr_results_path) # TODO this doesnt work in github actions - - # delete downloaded file + print("Saved diff results") + + no_diffs = all(diff_results.isnull().all()) + if not no_diffs: + print("Differences found in results!") + exit(1) + if no_diffs or args.overwrite_azure_results: + print("No differences found in results") + # upload new results to Azure + if not args.local_result_storage: + print("Uploading results") + upload_results_to_azure(file_to_upload=curr_results_path, + file_name=curr_results_path, file_directory="") + # upload diff to Azure + print("Uploading diff results") + upload_results_to_azure(file_to_upload="diff" + curr_results_path, + file_name="diff" + curr_results_path, file_directory="") + # delete downloaded file os.remove(prev_results) print("Deleted previous results") @@ -943,104 +941,30 @@ def find_sln_file(path): if __name__ == "__main__": # Sys input flags - parser = argparse.ArgumentParser(description='Build, create, and analyze CodeQL databases for testing queries. Running this script without any flags will run all queries on their respective driver template project with injected tests from driver_snippet.c') - parser.add_argument('-e', '--external_drivers', - help='Use external drivers at for testing instead of drivers in the repo', - type=str, - required=False, - ) - parser.add_argument('-l', '--no_clean', - help='Do not clean the working directory before running tests', - action='store_true', - required=False, - ) - parser.add_argument('-b', '--existing_database', - help='Use existing database at for testing instead of creating a new one', - type=str, - required=False, - ) - parser.add_argument('-d', '--debug_only', - help='Debug only', - action='store_true', - required=False, - ) - parser.add_argument('-r', '--release_only', - help='Release only', - action='store_true', - required=False, - ) - parser.add_argument('-n', '--no_build', - help='Do not build the driver before running the test', - action='store_true', - required=False, - ) - parser.add_argument('-o', '--override_template', - help='Override the template used for the test using