Last active
August 7, 2016 12:49
-
-
Save lfalmeida/b00027f11cb9531e78e3 to your computer and use it in GitHub Desktop.
git hook post-receive
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
#!/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 "" | |
} | |
printMessage "[ Iniciando script de deploy... ]" | |
WORK_TREE="/var/www/html/projeto" | |
# ajustando ambiente para o git | |
unset GIT_DIR | |
# acessando o diretório da aplicação | |
cd $WORK_TREE | |
# solicitando as tags disponíveis no remoto | |
printMessage "[ Obtendo a tag mais nova disponível no remoto ]" | |
git fetch --tags | |
# selecionando a tag mais nova | |
latestTag=$(git describe $(git rev-list --tags --max-count=1)) | |
# checkout para a versão mais nova | |
printMessage "[ Realizando checkout para a versão ${latestTag} ]" | |
git checkout --force "${latestTag}" | |
printMessage "[ Instalando dependências com composer ]" | |
composer install --no-interaction | |
printMessage "[ Instalando dependências com npm ]" | |
npm install | |
printMessage "[ Deploy concluído ]" | |
echo "" | |
echo $(git status) | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment