1 #!/bin/bash
2
3 # Get array of workspaces
4 # convert NDJSON stream to an array of arrays, divided by chunk size
5 # The reason we do a conditional here is that github actions thinks that there is
6 # a secret present with the output of this and therefore refuses to share data between jobs
7 if [ -z "${CHUNKS}" ]; then
8 export CHUNKS=$(yarn workspaces list --json | jq -j '[inputs | .name]' | jq -r | jq -cM '[_nwise(length / 2 | ceil)]')
9 fi
10
11 # get the workspaces of the current CHUNK environment
12 workspaces=$(echo $CHUNKS | jq -r ".[$CHUNK]")
13
14 echo "workspaces - $workspaces"
15 # Initialize an empty string for the filters
16 filters=""
17
18 # Loop through each workspace in the array
19 for workspace in $(echo "$workspaces" | jq -r '.[]'); do
20 # Add the workspace name to the filters array as an argument
21 filters+=" --filter=${workspace}"
22 done
23
24 command="yarn run test $filters $@"
25 # Run the test in the selected chunk
26 eval "$command"