diff --git a/.github/workflows/ci_pipeline.yml b/.github/workflows/ci_pipeline.yml index 9efaef8..51fb527 100644 --- a/.github/workflows/ci_pipeline.yml +++ b/.github/workflows/ci_pipeline.yml @@ -21,7 +21,7 @@ jobs: - name: Detect tests for C++ id: detect_tests_cpp run: | - TEST_RESULTS="$(bash scripts/test_detector.sh cpp)" + TEST_RESULTS="$(py scripts/test_detector.py cpp)" echo "Test Results:" echo "$TEST_RESULTS" echo "::set-output name=test_results::$TEST_RESULTS" @@ -41,7 +41,7 @@ jobs: - name: Detect tests for C id: detect_tests_c run: | - TEST_RESULTS="$(bash scripts/test_detector.sh c)" + TEST_RESULTS="$(py scripts/test_detector.py c)" echo "Test Results:" echo "$TEST_RESULTS" echo "::set-output name=test_results::$TEST_RESULTS" diff --git a/scripts/test_detector.py b/scripts/test_detector.py index 13faa7a..6647c76 100644 --- a/scripts/test_detector.py +++ b/scripts/test_detector.py @@ -1,23 +1,31 @@ import os -import sys import re +import sys test_folder = sys.argv[1] -files = [f.split('.')[0] for f in os.listdir(f'tests/{test_folder}')] -tests_dict = dict() +tests_dict = {} + +for root, dirs, files in os.walk('tests'): + for file in files: + if file.endswith('.in') and root.endswith(test_folder): + file_path = os.path.join(root, file) + src_file_path = os.path.dirname(file_path) + file_name = os.path.basename(file) + base_name = os.path.splitext(file_name)[0] + file_number = int(re.findall(r'\d+$', base_name)[0]) + name = re.sub(r'\d+$', '', base_name) + full_name = os.path.join(src_file_path, name) + if full_name in tests_dict: + if file_number > tests_dict[full_name]: + tests_dict[full_name] = file_number + else: + tests_dict[full_name] = file_number -for file in files: - file_number = re.findall(r'\d+', file)[-1] - file_name = file[:len(file) - len(file_number)] - if file_name in tests_dict.keys(): - tests_dict[file_name] = max(tests_dict[file_name], int(file_number)) - else: - tests_dict[file_name] = int(file_number) +output_env_var = "" +for test_name in tests_dict: + output_env_var += f"{test_name}:{tests_dict[test_name]}," -output_env_var = '' -for test_name, tests_number in tests_dict.items(): - output_env_var += test_name + ':' + str(tests_number) + ',' -output_env_var = output_env_var.rstrip(output_env_var[-1]) +output_env_var = output_env_var[:-1] -print(output_env_var) \ No newline at end of file +print(output_env_var)