Last active
June 6, 2022 23:40
-
-
Save jtsternberg/11e95ad15ac0075c040e27cccfc324f4 to your computer and use it in GitHub Desktop.
Pagely post-receive hook which updates submodules with each push. (https://support.pagely.com/hc/en-us/articles/203031474-Setting-up-git-on-Pagely-VPS-Enterprise-for-1-click-deployment)
This file contains hidden or 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 | |
# | |
## store the arguments given to the script | |
read oldrev newrev refname | |
## Where to store the log information about the updates | |
LOGFILE=./post-receive.log | |
# The deployed directory (the running site) | |
DEPLOYDIR=/directory/to/deploy/to | |
GITDIR=/directory/above/hooks/repo_name.git | |
blue='\033[1;34m' | |
no_color='\033[0m' | |
# %ae = Extract the user email from the last commit (author email) | |
USER_EMAIL=$(git log -1 --format=format:%ae HEAD) | |
# %an = Extract the username from the last commit (author name) | |
USER_NAME=$(git log -1 --format=format:%an HEAD) | |
## Record the fact that the push has been received | |
echo -e "Received Push Request at $( date +%Y-%m-%d:%H:%M:%S ) by $USER_NAME ($USER_EMAIL)" >> $LOGFILE | |
echo " - Old SHA: $oldrev New SHA: $newrev Branch Name: $refname" >> $LOGFILE | |
## Update the deployed copy | |
echo "Starting Deploy" >> $LOGFILE | |
echo " - Starting code deployment (to $DEPLOYDIR)" | |
# Move into the deploy directory | |
cd "$DEPLOYDIR"; | |
# Then do a fresh checkout | |
git --git-dir="$GITDIR" --work-tree="$DEPLOYDIR" checkout -f; | |
# Then do a fresh update of all submodules. | |
git --git-dir="$GITDIR" --work-tree="$DEPLOYDIR" submodule update --init --recursive | |
# We're done in the deploy directory, so navigate back. | |
cd - | |
# Heyo, it's Zao! | |
echo -e "${blue}"; | |
echo ' '; | |
echo ' , '; | |
echo ' : '; | |
echo ' ::: '; | |
echo ' ::: '; | |
echo ' ::::: '; | |
echo ' :::::, '; | |
echo ' ::::.:: '; | |
echo ' .:::: ::, '; | |
echo ' :::: ::: '; | |
echo ' ::::: .::: '; | |
echo ' :::: :::: ......... ...... ...... '; | |
echo ' :::: ,:::: . .` . .. `. '; | |
echo ' ::::: ::::. .. .` `. `. '; | |
echo ' :::: ::::: . . `. .` . '; | |
echo ' ::::` ::::. .` . .. . .` '; | |
echo ' ,:::: ::::: ,: . ...... . .. '; | |
echo ' :::: ,:::: :: .. .. `. . .. '; | |
echo ' :::` ::::, :: . . `. . .` '; | |
echo ' ::: ::::: :: . `. `. . . '; | |
echo ' ::. ::::` :: .` `. .. .. . '; | |
echo ' :: ,:::: ,:: .. . ... .. . '; | |
echo ' .: :::: ::: ......... ... ..` . ... .. '; | |
echo ' : :::, .::: `` `` '; | |
echo ' , ::: :::: '; | |
echo ' ::: ::::. '; | |
echo ' :: ::::: '; | |
echo ' :: :::::: '; | |
echo ' .:; .;::::: '; | |
echo ' :;;;;;:::. '; | |
echo ' `;;;;;::, '; | |
echo ' `;;;;;` '; | |
echo ' ` '; | |
echo ' '; | |
echo -e "${no_color}"; | |
echo " - Finished code deployment | |
" | |
echo "Finished Deploy | |
" >> $LOGFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment