Skip to content

Instantly share code, notes, and snippets.

@itxshakil
Created November 3, 2024 06:42
Show Gist options
  • Save itxshakil/54845e124959bfb70d040964ba0a0eef to your computer and use it in GitHub Desktop.
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
#!/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