Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
a circleci parallelism script optimized for rspec.this script is based on https://circleci.com/docs/parallel-manual-setup#balancing
#!/bin/bash
i=0
files=()
# sort spec files by number of examples for better balancing
for file in $(find ./spec -name "*_spec.rb" -print0 | xargs -0 grep -e "^ *it" -c | sort -t: -k2,2rn | awk -F":" '{ print $1 }')
do
if [ $(($i % $CIRCLE_NODE_TOTAL)) -eq $CIRCLE_NODE_INDEX ]
then
files+=" $file"
fi
((i++))
done
echo "specs to be tested: ${files[@]}"
bundle exec rspec ${files[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment