Skip to content

Commit

Permalink
python is faster than bash (why? - to investigate)
Browse files Browse the repository at this point in the history
  • Loading branch information
witek-formanski committed Nov 4, 2023
1 parent 853af64 commit 2ae5d5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
38 changes: 23 additions & 15 deletions scripts/test_detector.py
Original file line number Diff line number Diff line change
@@ -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)
print(output_env_var)

0 comments on commit 2ae5d5c

Please sign in to comment.