Skip to content

Instantly share code, notes, and snippets.

@Cezarion
Last active August 29, 2015 14:12
Show Gist options
  • Save Cezarion/2bd7c5bf10dbd4ad1bec to your computer and use it in GitHub Desktop.
Save Cezarion/2bd7c5bf10dbd4ad1bec to your computer and use it in GitHub Desktop.
Post receive hook + drush cc all Second file : post receive with switch branch
#!/bin/sh
#Post receive in DEV
#THIS HOOK SWITCH BRANCH
#1. Set Project configuration :
WEB_DIR=/Full/path/to/root/project
GIT_PATH=deploy.git
APP_PATH=deploy
#2. Log files
LOGFILE=./post-receive.log
#3. Run actions and logged in
echo -e "[log] Received push request at $( date +%F)" >> $LOGFILE
echo "[log] Starting Deploy..." >> $LOGFILE
echo "[log] - Starting code update"
#Read revisions
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
echo "[log] - Old SHA: $oldrev New SHA: $newrev Branch Name: $ref" >> $LOGFILE
echo "$branch ref received. Deploying $branch branch to CZN..."
git --work-tree=${WEB_DIR}/${APP_PATH} --git-dir=${WEB_DIR}/${GIT_PATH} checkout ${branch} -f
done
echo "[log] - Finished code update" >> $LOGFILE
#5. Run drush command
#-----------------------------------------------------------------------------------------------
echo "[log] - Starting drush clear cache."
drush cc all --root=${WEB_DIR}/${APP_PATH}
echo "[log] - Finished drush clear cache."
#!/bin/sh
#1. Set Project configuration :
#-----------------------------------------------------------------------------------------------
​WEB_DIR=/Full/Path/to/my/webdir
​GIT_PATH=app-path.git
​APP_PATH=app-path
​ENV=preprod
​​#2. Log file
#-----------------------------------------------------------------------------------------------
​LOGFILE=./post-receive.log
#3. Run actions and logged in
#-----------------------------------------------------------------------------------------------
​echo -e "[log] Received push request at $( date +%F)" >> $LOGFILE
​echo "[log] Starting Deploy..." >> $LOGFILE
​echo "[log] - Starting code update"
#4. Read revisions
#-----------------------------------------------------------------------------------------------
​while read oldrev newrev ref
​do
​ if [[ $ref =~ .*/master$ ]];
​ then
​ echo "[log] - Old SHA: $oldrev New SHA: $newrev Branch Name: $refname" >> $LOGFILE
​ echo "Master ref received. Deploying master branch to ${ENV}..."
​ git --work-tree=${WEB_DIR}/${APP_PATH} --git-dir=${WEB_DIR}/${GIT_PATH} checkout -f
​ else
​ echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
​ fi
​done
​echo "[log] - Finished code update" >> $LOGFILE
#5. Run drush command
#-----------------------------------------------------------------------------------------------
​echo "[log] - Starting drush clear cache."
​drush cc all --root=${WEB_DIR}/${APP_PATH}
​echo "[log] - Finished drush clear cache."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment