#!/bin/bash REPORTS_DIR="$1" SPLIT_COUNT=$2 SPLIT_INDEX=$3 # extract tests time from Junit XML reports find "$REPORTS_DIR" -type f -name TEST-*.xml | xargs -I{} bash -c "xmlstarlet sel -t -v 'sum(//testcase/@time)' '{}'; echo '{}' | sed 's/.*TEST\-\(.*\)\.xml/ \1/'" > tmp/timing.tsv # Sort times in descending order IFS=$'\n' sorted=($(sort -nr tmp/timing.tsv)) unset IFS sums=() tests=() # Initialize sums for ((i=0; i> tmp/processedTests.list fi done # Any new test? grep -F --line-regexp -v -f tmp/processedTests.list tmp/currentTests.list > tmp/newTests.list idx_new_test=0 while read -r new_test_name do idx_group=$(( idx_new_test % SPLIT_COUNT )) group=${tests[$idx_group]} tests[$idx_group]="${group}${new_test_name}," idx_new_test=$(( idx_new_test + 1 )) done < tmp/newTests.list # return the requests index, without quotes to drop the last trailing space echo ${tests[$SPLIT_INDEX]//,/ }