Skip to content

Instantly share code, notes, and snippets.

@fahmilatib
Last active January 22, 2021 18:42
Show Gist options
  • Save fahmilatib/82ce5414350a85585d209c3b3f8acaa4 to your computer and use it in GitHub Desktop.
Save fahmilatib/82ce5414350a85585d209c3b3f8acaa4 to your computer and use it in GitHub Desktop.
Git post-receive hook
#!/bin/sh
git_dir=$(pwd)
production_dir=<path>
artisan() { php artisan $1; }
cd "$production_dir"
# Begin maintenance mode
artisan 'down --retry=60'
cd "$git_dir"
# Checkout latest version and remove untracked files
git --work-tree=$production_dir checkout -f
git --work-tree=$production_dir clean -df
cd "$production_dir"
# Refresh PHP dependencies
composer install --no-dev
# Optimize Laravel
artisan cache:clear
artisan config:cache
artisan route:cache
artisan view:clear
# Recompile assets
yarn && yarn run production
# End maintenance mode
artisan up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment