Skip to content

Instantly share code, notes, and snippets.

@tomaszkubacki
Last active November 29, 2019 19:28
Show Gist options
  • Save tomaszkubacki/ac73323e284a22c59e00653a42ec090b to your computer and use it in GitHub Desktop.
Save tomaszkubacki/ac73323e284a22c59e00653a42ec090b to your computer and use it in GitHub Desktop.
git hook for deploy
#!/bin/bash
TARGET="/home/git/intermediate_dir_for_build"
BUILD_DIR="$TARGET/build"
DEPLOY_DIR="/var/www/deploy_site_name"
GIT_DIR="/home/git/repo_name.git"
BRANCH="master"
REF_MATCH="refs/tags/"
umask 002
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [[ "$ref" = "${REF_MATCH}"* ]]
then
echo "Ref $ref received. Deploying ${BRANCH} branch $DEPLOY_DIR"
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
npm install
npm run build
cp -rf $BUILD_DIR/* $DEPLOY_DIR
else
echo "Ref $ref received. Doing nothing: only the ${REF_MATCH}* makes deploy"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment