diff --git a/post-receive b/post-receive new file mode 100644 index 0000000..f18f38e --- /dev/null +++ b/post-receive @@ -0,0 +1,33 @@ +#!/bin/bash + +# The production directory +TARGET="/var/www/friends.of.mineral.town" +# Local (to server) git repository +GIT_DIR="~/mineral.town.git" +# A temporary directory for deployment +TEMP="~/work" +# Name of production branch +BRANCH="main" + +while read oldrev newrev ref +do + # only checking out the deployment branch + if [ "$ref" = "refs/heads/$BRANCH" ]; + then + mkdir $TEMP + + echo "Ref $ref received. Deploying ${BRANCH} branch to production..." + git --work-tree=$TEMP --git-dir=$GIT_DIR checkout -f $BRANCH + + # build blog + cd $TEMP/blog + hugo -D + + # Replace production directory with updated project files + cd ~ + rm -rf $TARGET + mv $TEMP/ $TARGET/ + else + echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." + fi +done