From a7e714a28ca76a74b59590c443de9efbb4064420 Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 23 Apr 2024 22:22:42 +0800 Subject: [PATCH] ci: add check-all scripts Signed-off-by: peefy --- Makefile | 3 +++ scripts/check-all.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 scripts/check-all.py diff --git a/Makefile b/Makefile index 8369e8e..f575e3f 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ test: ./scripts/test.sh + +check-all: + python3 ./scripts/check-all.py diff --git a/scripts/check-all.py b/scripts/check-all.py new file mode 100644 index 0000000..4878a6b --- /dev/null +++ b/scripts/check-all.py @@ -0,0 +1,48 @@ +import os +import subprocess +from concurrent.futures import ThreadPoolExecutor + + +def run_kcl_command(path): + """ + Executes the kcl run command + """ + print(f"Running 'kcl run' in {path}...") + result = subprocess.run(["kcl", "run"], cwd=path, capture_output=True, text=True) + if result.stderr: + print(f"Error running 'kcl run' in {path}: {result.stderr}") + else: + print(f"Output from running 'kcl run' in {path}: {result.stdout}") + + +def find_and_run_kcl(paths_list): + """ + Concurrently executes the kcl run command in paths containing kcl.mod + """ + with ThreadPoolExecutor() as executor: + executor.map(run_kcl_command, paths_list) + + +def find_kcl_mod_files(directory): + """ + Recursively searches for paths containing the kcl.mod file + """ + paths_with_kcl_mod = [] + for root, dirs, files in os.walk(directory): + if "kcl.mod" in files: + paths_with_kcl_mod.append(root) + return paths_with_kcl_mod + + +def main(): + examples_dir = "examples" # Set the path of the examples folder + paths_with_kcl_mod = find_kcl_mod_files(examples_dir) + if paths_with_kcl_mod: + print(f"Found {len(paths_with_kcl_mod)} paths with 'kcl.mod'.") + find_and_run_kcl(paths_with_kcl_mod) + else: + print("No 'kcl.mod' files found in the directory.") + + +if __name__ == "__main__": + main()