Created
November 3, 2024 06:42
-
-
Save itxshakil/54845e124959bfb70d040964ba0a0eef to your computer and use it in GitHub Desktop.
Automate Migration and Caching Route, Views and Config on Git Pull with Git Hooks
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 "Running optimized post-merge hook..." | |
# Check for new migration files | |
if git diff --name-only HEAD@{1} HEAD | grep -qE '^database/migrations/.*\.php'; then | |
echo "New migrations found. Running database migrations..." | |
php artisan migrate --force | |
else | |
echo "No new migrations found. Skipping migration step." | |
fi | |
# Check for changes in config files | |
if git diff --name-only HEAD@{1} HEAD | grep -qE '^config/.*\.php'; then | |
echo "Config changes detected. Recaching config..." | |
php artisan config:cache | |
else | |
echo "No config changes detected. Skipping config cache." | |
fi | |
# Check for changes in view files | |
if git diff --name-only HEAD@{1} HEAD | grep -qE '^resources/views/.*\.(php|blade\.php)'; then | |
echo "View changes detected. Recaching views..." | |
php artisan view:cache | |
else | |
echo "No view changes detected. Skipping view cache." | |
fi | |
# Check for changes in route files | |
if git diff --name-only HEAD@{1} HEAD | grep -qE '^routes/.*\.php'; then | |
echo "Route changes detected. Recaching routes..." | |
php artisan route:cache | |
else | |
echo "No route changes detected. Skipping route cache." | |
fi | |
echo "Optimized post-merge tasks completed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment