diff --git a/tools/gated_check_in/.keep b/tools/gated_check_in/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/gated_check_in/check_tdd.py b/tools/gated_check_in/check_tdd.py new file mode 100644 index 0000000000000000000000000000000000000000..4b3381213e3fbf42b703037ca1c66e29cf8deb61 --- /dev/null +++ b/tools/gated_check_in/check_tdd.py @@ -0,0 +1,61 @@ +import json +import subprocess +import argparse +import os + + +def check_file_paths(json_data): + check_result = True + for key in json_data: + changed_file_list = json_data[key]["changed_file_list"] + if "added" in changed_file_list: + for file_path in changed_file_list["added"]: + if "test" not in file_path: + check_result = False + if "modified" in changed_file_list: + for file_path in changed_file_list["modified"]: + if "test" not in file_path: + check_result = False + if "deleted" in changed_file_list: + for file_path in changed_file_list["deleted"]: + if "test" not in file_path: + check_result = False + if "rename" in changed_file_list: + for rename_pair in changed_file_list["rename"]: + if "test" not in rename_pair[1]: + check_result = False + return check_result + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--build', required=True) + args = parser.parse_args() + build_command = args.build + command_list = build_command.split() + try: + with open('change_info.json', 'r') as file: + change_info = json.load(file) + except Exception as e: + print(f'An unexpected error occurred: {e}') + try: + result = subprocess.run(command_list, text=True, check=True) + print(result.stdout) + except subprocess.CalledProcessError as e: + print(f'Command execution failed: {e}') + exit(1) + else: + if check_file_paths(change_info): + print('Modify only test cases and do not need to be executed') + if not os.path.exists('out'): + os.mkdir('out') + file_path = 'out/smoke_check.json' + with open(file_path, 'w') as f: + json.dump({}, f) + else: + try: + result = subprocess.run(command_list, text=True, check=True) + print(result.stdout) + except subprocess.CalledProcessError as e: + print(f'Command execution failed: {e}') + exit(1) \ No newline at end of file