Skip to content

Instantly share code, notes, and snippets.

@loic-roux-404
Created June 7, 2020 20:43
Show Gist options
  • Save loic-roux-404/159e25db31995952bf0f15c19c32f90a to your computer and use it in GitHub Desktop.
Save loic-roux-404/159e25db31995952bf0f15c19c32f90a to your computer and use it in GitHub Desktop.
deploy hook automation
#!/bin/bash
###
# CONFIG VARS
###
# DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
###
while read oldrev newrev ref
do
# only checking out the branch to deploy
if [[ $ref = refs/heads/$BRANCH ]];
then
echo "Ref '$ref' received."
if [ ! -d "$TARGET" ];
then
echo "'${TARGET}' dir is missing, creating it"
mkdir -p $TARGET
fi
echo "Deploying '${BRANCH}' branch to production"
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout --force $BRANCH
if [ "$RESTART" = true ];
then
echo "Restarting your web server"
status=$(curl --basic --user "${API_KEY} account=${ACCOUNT}:" --data '' --request POST --silent --output /dev/null --write-out '%{http_code}' "https://api.alwaysdata.com/v1/site/${SITE_ID}/restart/")
if [ "$status" = 204 ];
then
echo "Your site is restarted"
else
echo "An error occured when restarting your site, try to restart it manually"
exit 1
fi
fi
exit 0
else
echo "You pushed '$ref' branch,"
echo "but you set '${BRANCH}' branch as deploy branch."
echo "Exiting without error."
exit 0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment