Last active
June 2, 2016 06:49
-
-
Save mihaeu/7526e9172231936b1b3fe712d814096d to your computer and use it in GitHub Desktop.
Bash script to insure that your code coverage is above a certain limit (e.g. for the CI server or pre-commit hook)
This file contains 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
#!/usr/bin/env bash | |
# This is just a quick hack to determine if the code coverage | |
# is enough or not. Change the path to PHPUnit if needed. | |
# | |
# @author Michael Haeuslmann <haeuslmann@gmail.com> | |
NO_COLOR='\x1b[0m' | |
OK_COLOR='\x1b[32;01m' | |
ERROR_COLOR='\x1b[31;01m' | |
WARN_COLOR='\x1b[33;01m' | |
min_cov=95 | |
cov=`vendor/bin/phpunit --coverage-text --colors=never \ | |
| egrep -o "Lines:[[:space:]]+([0-9])+" \ | |
| head -n1 \ | |
| sed 's/Lines: *//'` | |
if [ "$cov" -eq "100" ]; then | |
printf "${OK_COLOR}✓ Coverage is $cov%%${NO_COLOR}\n" | |
elif [ "$cov" -ge "$min_cov" ]; then | |
printf "${WARN_COLOR}! Coverage is only $cov%%${NO_COLOR}\n" | |
else | |
printf "${ERROR_COLOR}✗ Coverage is only $cov%%, but needs to be at least $min_cov%%${NO_COLOR}\n" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment