77 AutoTestsInfo ,
88 is_build_finished ,
99 is_build_success ,
10+ is_last_build_successful ,
1011 is_shell_uses_package ,
1112 trigger_auto_tests_build2 ,
1213)
1617
1718
1819def main (tc_user : str , tc_password : str ):
19- triggered_builds : dict [str , int ] = {}
20- builds_statuses : dict [str , bool ] = {}
2120 errors = []
21+ triggered_builds = {}
2222 tc = TeamCity (TC_URL , auth = (tc_user , tc_password ))
2323 tests_info = AutoTestsInfo .get_current (tc )
24+ if tests_info .re_run_builds :
25+ click .echo ("Re run failed builds" )
26+ else :
27+ click .echo ("Run automated tests" )
2428
2529 for shell_name in tests_info .supported_shells :
2630 try :
27- if is_shell_uses_package (shell_name , tests_info ):
28- click .echo (f"{ shell_name } Automation tests build triggering" )
29- build_id = trigger_auto_tests_build2 (tc , shell_name , tests_info )
30- triggered_builds [shell_name ] = build_id
31- else :
32- click .echo (f"{ shell_name } skipped tests" )
31+ triggered_builds = _run_tests_for_shell (tc , shell_name , tests_info )
3332 except Exception as e :
3433 errors .append (e )
3534 click .echo (e , err = True )
3635
36+ builds_statuses , new_errors = _wait_build_finish (tc , triggered_builds )
37+ errors .extend (new_errors )
38+
39+ if errors :
40+ raise Exception ("There were errors running automation tests." )
41+ return all (builds_statuses .values ())
42+
43+
44+ def _run_tests_for_shell (
45+ tc : TeamCity , shell_name : str , tests_info : AutoTestsInfo
46+ ) -> dict [str , int ]:
47+ triggered_builds = {}
48+ if is_shell_uses_package (shell_name , tests_info ):
49+ if tests_info .re_run_builds :
50+ if is_last_build_successful (tc , shell_name , tests_info ):
51+ click .echo (
52+ f"{ shell_name } last auto tests for this package and commit "
53+ f"id was successful, skip it"
54+ )
55+ else :
56+ click .echo (f"{ shell_name } Re run automation tests" )
57+ build_id = trigger_auto_tests_build2 (tc , shell_name , tests_info )
58+ triggered_builds [shell_name ] = build_id
59+ else :
60+ click .echo (f"{ shell_name } Automation tests build triggering" )
61+ build_id = trigger_auto_tests_build2 (tc , shell_name , tests_info )
62+ triggered_builds [shell_name ] = build_id
63+ else :
64+ click .echo (f"{ shell_name } is not uses package with this version, skipped tests" )
65+ return triggered_builds
66+
67+
68+ def _wait_build_finish (
69+ tc : TeamCity , triggered_builds : dict [str , int ]
70+ ) -> tuple [dict [str , bool ], list [Exception ]]:
71+ builds_statuses = {}
72+ errors = []
3773 while triggered_builds :
3874 time .sleep (BUILDS_CHECK_DELAY )
3975 for shell_name , build_id in triggered_builds .copy ().items ():
@@ -49,7 +85,4 @@ def main(tc_user: str, tc_password: str):
4985 except Exception as e :
5086 errors .append (e )
5187 click .echo (e , err = True )
52-
53- if errors :
54- raise Exception ("There were errors running automation tests." )
55- return all (builds_statuses .values ())
88+ return builds_statuses , errors
0 commit comments