Last active
April 5, 2016 22:05
-
-
Save psi/859e91ae9acd35cd6e7717025da277b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
changed_cookbooks=$(git diff --name-only ${TRAVIS_COMMIT_RANGE} | grep 'cookbooks/r5' | awk -F '/' '{print $2}' | sort | uniq | wc -l) | |
if [ "$changed_cookbooks" -eq 0 ] && [ -z "$TEST_ALL_COOKBOOKS" ]; then | |
echo "No cookbook changes detected. Skipping cookbook tests." | |
exit 0 | |
else | |
echo "Found ${changed_cookbooks} changed cookbook(s). We'll test all cookbooks." | |
fi | |
# Function to test a single cookbook | |
test_cookbook() { | |
cookbook=$1 | |
log_file=${TRAVIS_BUILD_DIR}/logs/kitchen/${cookbook}.log | |
cd ${TRAVIS_BUILD_DIR}/cookbooks/${cookbook} | |
kitchen test --concurrency --destroy=always > ${log_file} 2>&1 | |
# If Test-Kitchen fails, spit out the log | |
if [ "$?" != 0 ]; then | |
echo "=========== ${cookbook} Test-Kitchen failed" | |
cat ${log_file} | |
echo | |
return 1 | |
fi | |
return 0 | |
} | |
# Export the test_cookbook function so it's available to child processes of parallel | |
export -f test_cookbook | |
mkdir -p ${TRAVIS_BUILD_DIR}/logs/kitchen | |
# For now, if we find any cookbook change, we'll test all cookbooks | |
export cookbooks=$(ls -1 ${TRAVIS_BUILD_DIR}/cookbooks | grep '^r5-') | |
num_jobs=$(echo ${cookbooks} | wc -w) | |
echo "Testing ${num_jobs} cookbook(s) in parallel" | |
parallel --gnu --jobs ${num_jobs} --joblog /tmp/kitchen_jobs.log test_cookbook ::: ${cookbooks} | |
exit_code=$? | |
cat /tmp/kitchen_jobs.log | |
exit ${exit_code} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment