I have just started writing a web application.
I am using GIT for version control and I have git and web server in the same computer.
Application has 3 environments: dev, test and production
I want to use git hook after every commit to update dev, test or production application.
what is the best practice for this?
I need something like this:
Thanks!
I've just written a hook / mini bash script to solve this problem
#!/bin/bash
if git log --pretty=format:%s -1 | grep -q "^test: "
then
#action / update dev/test
elif git log --pretty=format:%s -1 | grep -q "^production: "
then
#action / update dev/test/production
else
#action / update dev
fi
It is my first bash script so.. please help to improve this :)
Based on Irakli idea, here is what I have working as a post-receive in my repo...
#!/bin/bash
MESSAGE=$(git log -1 HEAD --pretty=format:%s)
if [[ "$MESSAGE" == *\[staging\]* ]];
then
#action / update staging
# another method not being used...
# GIT_WORK_TREE=/path/to/working/site/ git checkout -q -f staging
echo "NOTE: Beginning Auto-Push to Staging Server... "
`git push staging`
echo "========================================================
======== Done! Pushed to STAGING.com =============
======== Thanks Captain. Keep up the good work! ========
========================================================"
elif [[ "$MESSAGE" == *\[production\]* ]];
then
#action / update production
echo "NOTE: Beginning Auto-Push to Production Server... "
# `git push production`
echo "========================================================
======== Done!!! Pushed to Production.com =======
======== Test immediately for any errors! =========
========================================================"
fi
Note:
to make the 'git push staging' work, you need to have a .git/hooks/post-reveive hook on that working tree. I used this code except I added 'umask 002 && git reset --hard' at the bottom.
I also had to add a denyrecive to that working tree's .git/config file:
[receive]
denycurrentbranch = ignore
Note 2:
Please note this setup IS NOT for everyone... only for small(ish) sites where quick & dirty updates are fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With