Last active
December 16, 2015 10:40
-
-
Save mike-boddin/e323916cd34c280a54b2 to your computer and use it in GitHub Desktop.
Collection of git-hooks
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 | |
# base_functions | |
function print_baseline { | |
echo "#" | |
echo "########################################################################" | |
echo "#" | |
} | |
function log { | |
echo "# $@" | |
} | |
function quit { | |
print_baseline | |
exit 0 | |
} | |
print_baseline |
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 | |
# post-receive | |
### STEP 1: Load some convenient functions #################################### | |
# import base_functions | |
# it provides: log, print_baseline, quit | |
source `pwd`/${0%/*}/base_functions | |
### STEP 2: Set params ######################################################## | |
# production-path to copy content to | |
PRODUCTION_PATH=~/html | |
# read stdin into an arry, split by whitespace | |
IFS=' ' read -a INPUT | |
#previous commit id | |
ID_BEFORE=${INPUT[0]} | |
# new commit id | |
ID_AFTER=${INPUT[1]} | |
# branch | |
BRANCH=${INPUT[2]} | |
# the version we want to print to the version-file | |
VERSION=${ID_AFTER:0:7} | |
# the version-file | |
VERSION_FILE=version.txt | |
### STEP 3: check the branch (we only want to process the master-branch) ###### | |
# if not the master-branch was pushed --> exit | |
if ! [[ $BRANCH == *master ]] ; then | |
log this is the ${BRANCH##*/}-branch, no additional action | |
log if you want to deploy to production, please push to the master-branch | |
quit | |
else | |
log push to master, the content will be deployed to production | |
fi | |
### STEP 4: copy over the content ############################################# | |
# copy over content to production | |
export GIT_WORK_TREE=$PRODUCTION_PATH | |
git checkout -f | |
# add version information | |
echo $VERSION > $PRODUCTION_PATH/$VERSION_FILE | |
log production updated to version $VERSION | |
quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
base_functions
This file is loaded by all of the other scripts.
It provides some convenient functions (mainly to prettify the output of the script).
post-receive
This is a server-side script (bare-repo).
The aim of this file is to deploy pushes to the master-branch directly to production-environment.