Skip to content

Instantly share code, notes, and snippets.

@mike-boddin
Last active December 16, 2015 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-boddin/e323916cd34c280a54b2 to your computer and use it in GitHub Desktop.
Save mike-boddin/e323916cd34c280a54b2 to your computer and use it in GitHub Desktop.
Collection of git-hooks
#!/bin/bash
# base_functions
function print_baseline {
echo "#"
echo "########################################################################"
echo "#"
}
function log {
echo "# $@"
}
function quit {
print_baseline
exit 0
}
print_baseline
#!/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
@mike-boddin
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment