diff --git a/tools/gated_check_in/check_tdd.py b/tools/gated_check_in/check_tdd.py new file mode 100644 index 0000000000000000000000000000000000000000..a652b6ae695402ff8bf08a4801f62c7fc7a5b8a0 --- /dev/null +++ b/tools/gated_check_in/check_tdd.py @@ -0,0 +1,69 @@ +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 not check_directory_matches(file_path, "test"): + check_result = False + if "modified" in changed_file_list: + for file_path in changed_file_list["modified"]: + if not check_directory_matches(file_path, "test"): + check_result = False + if "deleted" in changed_file_list: + for file_path in changed_file_list["deleted"]: + if not check_directory_matches(file_path, "test"): + check_result = False + if "rename" in changed_file_list: + for rename_pair in changed_file_list["rename"]: + if not check_directory_matches(rename_pair[1], "test"): + check_result = False + return check_result + + +def check_directory_matches(path_str, target_str): + parts = path_str.split('/') + for part in parts: + if part == target_str: + return True + return False + + +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 diff --git a/tools/gated_check_in/check_webview.py b/tools/gated_check_in/check_webview.py new file mode 100644 index 0000000000000000000000000000000000000000..c372a3d1c61e7ca1f47efdb61c23730ad9a558a9 --- /dev/null +++ b/tools/gated_check_in/check_webview.py @@ -0,0 +1,77 @@ +import json +import subprocess +import argparse +import os + + + +def check_file_paths(json_data): + check_result = False + for key in json_data: + if key =='base/web/webview': + changed_file_list = json_data[key]["changed_file_list"] + if "added" in changed_file_list: + for file_path in changed_file_list["added"]: + if check_directory_matches(file_path, "ohos_interface"): + check_result = True + return check_result + if "modified" in changed_file_list: + for file_path in changed_file_list["modified"]: + if check_directory_matches(file_path, "ohos_interface"): + check_result = True + return check_result + if "deleted" in changed_file_list: + for file_path in changed_file_list["deleted"]: + if check_directory_matches(file_path, "ohos_interface"): + check_result = True + return check_result + if "rename" in changed_file_list: + for rename_pair in changed_file_list["rename"]: + if check_directory_matches(rename_pair[1], "ohos_interface"): + check_result = True + return check_result + return check_result + + +def check_directory_matches(path_str, target_str): + parts = path_str.split('/') + for part in parts: + if part == target_str: + return True + return False + +def run_build_command(): + commands = [ + "./prebuilts_download.sh", + ["bash", "build.sh", "rk3568", "-t", "w", "-A", "-ccache"], + "./sign.sh rk3568" + ] + for command in commands: + try: + if isinstance(command, str): + command = command.split() + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + if process.returncode != 0: + print('Command execution failed: %s' % stderr) + exit(1) + else: + print(stdout) + except Exception as e: + print('An unexpected error occurred: %s' % e) + exit(1) + + + +if __name__ == '__main__': + try: + with open('change_info.json', 'r') as file: + change_info = json.load(file) + except Exception as e: + print('An unexpected error occurred') + run_build_command() + else: + if check_file_paths(change_info): + run_build_command() + else: + print('do not need to build')