Skip to content

Instantly share code, notes, and snippets.

@lfalmeida
Last active August 19, 2016 20:28
Show Gist options
  • Save lfalmeida/1e3ec50c78a70bf0c21bf47cb6253f29 to your computer and use it in GitHub Desktop.
Save lfalmeida/1e3ec50c78a70bf0c21bf47cb6253f29 to your computer and use it in GitHub Desktop.
Hook para deploy utilizando tags
#!/bin/bash
## Print horizontal printMessager with message
printMessage () {
if [ $# -eq 0 ]; then
echo "Usage: printMessage MESSAGE [printMessage_CHARACTER]"
return 1
fi
echo ""
printf -v _hr "%*s" $(tput cols) && echo -en ${_hr// /${2--}} && echo -e "\r\033[2C$1"
}
printMessage "[ Iniciando script de deploy... ]"
WORK_TREE="/var/www/html"
# 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
# --- Projeto Laravel ----------------------------
printMessage "[ Limpando cache ]"
php artisan cache:clear
printMessage "[ Executando migrations ]"
php artisan migrate
# -------------------------------------------------
printMessage "[ Deploy concluído ]"
echo $(git status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment