@ -7,9 +7,14 @@
"""
"""
CLI tool that analyses a Shippable run ' s test result and re-balances the test targets into new groups.
CLI tool that analyses a Shippable run ' s test result and re-balances the test targets into new groups.
Before running this script you must run download . py like
Before running this script you must run download . py like :
. / download . py https : / / app . shippable . com / github / < team > / < repo > / runs / < run_num > - - test - results - - job - number x - - job - number y
Or to get all job results from a run :
. / download . py https : / / app . shippable . com / github / < team > / < repo > / runs / < run_num > - - test - results - - all
. / download . py https : / / app . shippable . com / github / < team > / < repo > / runs / < run_num > - - test - results - - job - number x - - job - number y
Set the dir < team > / < repo > / < run_num > as the value of ' -p/--test-path ' for this script .
Set the dir < team > / < repo > / < run_num > as the value of ' -p/--test-path ' for this script .
"""
"""
@ -23,6 +28,8 @@ import operator
import os
import os
import re
import re
from glob import glob
try :
try :
import argcomplete
import argcomplete
except ImportError :
except ImportError :
@ -72,29 +79,31 @@ def get_raw_test_targets(args, test_path):
target_times = { }
target_times = { }
for job_id in os . listdir ( test_path ) :
for job_id in os . listdir ( test_path ) :
json_path = os . path . join ( test_path , job_id , ' test.json ' )
json_path = os . path . join ( test_path , job_id , ' test ' , ' testresults ' , ' data ' )
if not os . path . isfile ( json_path ) :
# Some tests to do not have a data directory
if not os . path . exists ( json_path ) :
continue
json_file = glob ( os . path . join ( json_path , ' *integration-*.json ' ) ) [ 0 ]
if not os . path . isfile ( json_file ) :
if args . verbose :
if args . verbose :
print ( " The test json file ' %s ' does not exist or is not a file, skipping test job run " % json_path )
print ( " The test json file ' %s ' does not exist or is not a file, skipping test job run " % json_ file )
continue
continue
with open ( json_path , mode = ' rb ' ) as fd :
with open ( json_ file , mode = ' rb ' ) as fd :
test_info = json . loads ( fd . read ( ) . decode ( ' utf-8 ' ) )
test_info = json . loads ( fd . read ( ) . decode ( ' utf-8 ' ) )
for test in test_info :
targets = test_info . get ( ' targets ' , { } )
if not test . get ( ' path ' , ' ' ) . endswith ( ' .json ' ) or ' contents ' not in test . keys ( ) :
continue
info = json . loads ( test [ ' contents ' ] )
for target_name , target_info in info. get ( ' targets' , { } ) . items ( ) :
for target_name , target_info in targets . items ( ) :
target_runtime = int ( target_info . get ( ' run_time_seconds ' , 0 ) )
target_runtime = int ( target_info . get ( ' run_time_seconds ' , 0 ) )
# If that target already is found and has a higher runtime than the current one, ignore this entry.
# If that target already is found and has a higher runtime than the current one, ignore this entry.
if target_times . get ( target_name , 0 ) > target_runtime :
if target_times . get ( target_name , 0 ) > target_runtime :
continue
continue
target_times [ target_name ] = target_runtime
target_times [ target_name ] = target_runtime
return dict ( sorted ( target_times . items ( ) , key = lambda i : i [ 1 ] , reverse = True ) )
return dict ( sorted ( target_times . items ( ) , key = lambda i : i [ 1 ] , reverse = True ) )