Created
August 7, 2016 13:01
-
-
Save lfalmeida/6d34228b16215b44b2d2b0ebbf65e09d to your computer and use it in GitHub Desktop.
Script para hook pre-receive que executa os testes unitários e rejeita em caso de falha
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 | |
printMessage () { | |
if [ $# -eq 0 ]; then | |
echo "Usage: printMessage MESSAGE [printMessage_CHARACTER]" | |
return 1 | |
fi | |
echo "" | |
echo "" | |
printf -v _hr "%*s" 80 && echo -en ${_hr// /${2--}} && echo -e "\r\033[2C$1" | |
echo "" | |
} | |
while read oldrev newrev refname | |
do | |
# Executar este script somente para o branch master | |
if [[ $refname = "refs/heads/master" ]] ; then | |
printMessage "[ Preparing to run phpunit for $newrev ... ]" | |
# Como este é um repositório bare, precisamos colocar os arquivos em algum lugar | |
# neste caso, o diretório /tmp | |
git archive $newrev | tar -x -C /tmp | |
printMessage "[ Executando testes para $newrev ... ]" | |
# This part is the actual code which is used to run our tests | |
# In my case, the phpunit testsuite resides in the tests directory, so go there | |
cd /var/www/html/projeto | |
# executando a bateria de testes | |
./vendor/bin/phpunit # > /dev/null | |
# $? esta variável armazena o retorno do último comando executado | |
rc=$? | |
if [[ $rc != 0 ]] ; then | |
# Um código de retorno diferente de zero significa que os testes falharam | |
printMessage "[ Os testes falharam na rev $newrev - ***PUSH REJEITADO*** ]" | |
printMessage "[ Execute os testes localmente e confirme que todos os testes estejam passando ]" | |
exit $rc | |
fi | |
fi | |
done | |
# Se tudo der ok, finalizamos com retorno de sucesso | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment