Last active
December 20, 2015 13:39
-
-
Save rodolfo42/6140163 to your computer and use it in GitHub Desktop.
Hook para post-receive do Git (apos o repositorio receber um payload). Analisa para ver se algum commit foi feito para o branch $targetBranch, e, somente neste caso, atualiza o $webroot com os conteudos da working tree desta branch usando git checkout
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 | |
# DocumentRoot do Apache | |
webroot=/var/www/approot | |
# branch que será considerado como versão para produção | |
targetBranch=master | |
# funcao para logar uma mensagem em um log e tambem exibir no client | |
log() { | |
msg=$1 | |
echo "[$(date +"%d-%m-%Y %T")] $msg" >> checkout.log | |
echo $msg | |
} | |
# revisoes sao recebidas atraves do STDIN e podem ser varias | |
while read oldrev newrev refname | |
do | |
# pega o branch que foi commitado | |
branch=$(git rev-parse --symbolic --abbrev-ref $refname) | |
if [ "$targetBranch" == "$branch" ]; then | |
# pegar short hash | |
shortHash=$( git rev-parse --short $newrev ) | |
log "checking out $shortHash > $webroot..." | |
GIT_WORK_TREE=$webroot git checkout -f | |
log "done" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment