Last active
May 5, 2022 22:39
-
-
Save vool/2e76b5062b71c8aab354 to your computer and use it in GitHub Desktop.
Post receive hook for Laravel website deploy
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 | |
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' | |
php artisan migrate --no-interaction | |
# 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 | |
# check if node package has been updated, if so install | |
if [[ "${changedfiles[*]}" =~ "package.lock" ]]; then | |
echo "package.lock changed: Installing npm dependencies..." | |
npm install | |
fi | |
# check if composer has been updated, if so install | |
# Check if the composer.lock file is present | |
if [[ "${changedfiles[*]}" =~ "composer.lock" ]]; then | |
# Install or update packages specified in the lock file | |
echo "composer.lock has been updated - do install" | |
composer install --no-dev | |
fi | |
php artisan cache:clear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I revert back the release to the previous commit?