Skip to content

Instantly share code, notes, and snippets.

@vool
Last active May 5, 2022 22:39
Show Gist options
  • Save vool/2e76b5062b71c8aab354 to your computer and use it in GitHub Desktop.
Save vool/2e76b5062b71c8aab354 to your computer and use it in GitHub Desktop.
Post receive hook for Laravel website deploy
#!/bin/bash
echo "********************"
echo "Post receive hook: Updating website"
echo "********************"
#set the git repo dir
GIT_REPO_DIR=~/git/<repo>.git
echo "The git repo dir is $GIT_REPO_DIR"
WEBROOT=/var/www/<website>
GIT_WORK_TREE=$WEBROOT git checkout -f
#change directory to the project dir
cd $WEBROOT
rm -f storage/cache/*
echo 'cache cleared'
rm -f storage/views/*
echo 'views cleared'
composer install
php artisan migrate --no-interaction
#Basset
#php artisan basset:build
#Bower
# only run if bower.json has changed
echo "** Bower **"
# switch to webroot
cd $GIT_REPO_DIR
# geting a 'fatal: ambiguous argument' from this ?
#changedfiles=( `git diff-tree --no-commit-id --name-only HEAD@{1} HEAD` )
changedfiles=( `git diff-tree --no-commit-id --name-only HEAD^ HEAD` )
#switch back
cd $WEBROOT
if [[ "${changedfiles[*]}" =~ "bower.json" ]]; then
echo "bower installing"
bower install
echo "bower pruning"
bower prune
fi
php artisan cache:clear
@tjventurini
Copy link

Nice inspiration, thank you. Quick note: you have composer install twice in it.

@abkiran
Copy link

abkiran commented Sep 4, 2018

How do I revert back the release to the previous commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment