Created
June 7, 2020 20:43
-
-
Save loic-roux-404/159e25db31995952bf0f15c19c32f90a to your computer and use it in GitHub Desktop.
deploy hook automation
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 | |
### | |
# 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