-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest-parallel.sh
executable file
·44 lines (33 loc) · 1.24 KB
/
test-parallel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Spec directory argument
SPEC_DIR=$1
if [ -z "$SPEC_DIR" ]; then
echo "Error: Spec directory is required."
exit 1
fi
# List all spec files
SPEC_FILES=$(find $SPEC_DIR -name '*.js')
TOTAL_SPECS=$(echo "$SPEC_FILES" | wc -l)
echo Total number of specs $TOTAL_SPECS
# Determine the number of files to run on this container
FILES_PER_CONTAINER=$(( TOTAL_SPECS / CIRCLE_NODE_TOTAL ))
echo Files per container $FILES_PER_CONTAINER
REMAINDER=$(( TOTAL_SPECS % CIRCLE_NODE_TOTAL ))
echo Remainder specs $REMAINDER
# Adjust the number of files for this container if necessary
if (( CIRCLE_NODE_INDEX < REMAINDER )); then
(( FILES_PER_CONTAINER++ ))
fi
# Determine the range of files to run on this container
START_INDEX=$(( CIRCLE_NODE_INDEX * FILES_PER_CONTAINER + 1 ))
if (( CIRCLE_NODE_INDEX < REMAINDER )); then
START_INDEX=$(( START_INDEX + CIRCLE_NODE_INDEX ))
else
START_INDEX=$(( START_INDEX + REMAINDER ))
fi
END_INDEX=$(( START_INDEX + FILES_PER_CONTAINER - 1 ))
# Get the list of files to run on this container
SPECS_TO_RUN=$(echo "$SPEC_FILES" | sed -n "$START_INDEX,$END_INDEX p" | tr '\n' ',')
SPECS_TO_RUN=$(echo "$SPECS_TO_RUN" | sed 's/,$//')
echo "export SPECS_TO_RUN=\"$SPECS_TO_RUN\"" >> $BASH_ENV
echo $SPECS_TO_RUN