Splitting tests with split-by between nodes using a custom logic


I would like to split tests using circleci tests split CLI command using the --split-by=timings.

I would have 4 nodes and would like to evenly split tests that are in my /app/ folder between first two nodes, and the other tests that are in the /web/ folder between last two nodes.

I tried a few scenarios but can’t get it to work - here is mu current implementation:

#!/bin/bash -eo pipefail
half_node_total=$((CIRCLE_NODE_TOTAL / 2))
if [ "$CIRCLE_NODE_INDEX" -lt "$half_node_total" ]; then
  all-my-tests.txt | grep -E "/app/" | circleci tests split --split-by=timings > test_rta_list.txt
  all-my-tests.txt | grep -E "/web/" | circleci tests split --split-by=timings > test_rta_list.txt

The problem is that in the first two nodes the /app/ portion of tests is executed as expected ( I currently have only 2 tests and they are split between the first 2 nodes), however with the last two nodes (/web/), the output produced by circleci tests split --split-by=timings > test_rta_list.txt yields an empty test_rta_list.txt file meaning no tests are executed in the last 2 nodes.

Any ideas?