diff --git a/CHANGELOG.md b/CHANGELOG.md index bef3054..861e23c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.5.0] - 2025-01-XX +### Added +- Post-deployment optimization commands matching GitHub Actions workflow: + - Application optimization (`optimize:clear` and `optimize`) + - Event caching (`event:clear` and `event:cache`) + - Queue worker restart (`queue:restart`) + - Horizon termination (`horizon:terminate`) + - Application cache clearing (`cache:clear`) + - OPcache clearing (`opcache:clear`) +- Configurable caching commands (config, route, view) via config file flags + ### Fixed - Fixed `.env` file being overwritten during incremental deployments - Fixed app key regeneration breaking user sessions on subsequent deployments @@ -19,7 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - App key generation only runs if `APP_KEY` is not set in `.env` - Storage symlink creation only runs if symlink doesn't exist - Safe for incremental deployments - preserves user data and configuration files -- Migrations now check for `.env` existence before running +- Removed redundant `.env` file existence checks (file is guaranteed to exist at post-deployment stage) +- `hostinger:deploy` command now matches GitHub Actions workflow post-deployment behavior ### Changed - Deployment commands are now idempotent - safe to run multiple times without side effects diff --git a/src/Commands/DeploySharedCommand.php b/src/Commands/DeploySharedCommand.php index d71bd9d..7afcf24 100644 --- a/src/Commands/DeploySharedCommand.php +++ b/src/Commands/DeploySharedCommand.php @@ -358,12 +358,11 @@ class DeploySharedCommand extends BaseHostingerCommand $commands[] = "if [ -d public ] && [ ! -L public_html ] && [ ! -d public_html ]; then ln -s public public_html; fi"; // Generate app key ONLY if APP_KEY is not set in .env - // Check if .env exists AND if APP_KEY line exists and is not empty - $commands[] = "if [ -f .env ] && ! grep -q '^APP_KEY=base64:' .env 2>/dev/null && ! grep -q '^APP_KEY=\"base64:' .env 2>/dev/null; then php artisan key:generate --quiet; fi"; + $commands[] = "if ! grep -q '^APP_KEY=base64:' .env 2>/dev/null && ! grep -q '^APP_KEY=\"base64:' .env 2>/dev/null; then php artisan key:generate --quiet; fi"; - // Run migrations only if .env exists (app is configured) + // Run migrations if (config('hostinger-deploy.deployment.run_migrations', true)) { - $commands[] = "if [ -f .env ]; then echo 'yes' | php artisan migrate --quiet; fi"; + $commands[] = "echo 'yes' | php artisan migrate --quiet"; } // Create storage link only if it doesn't exist @@ -371,6 +370,45 @@ class DeploySharedCommand extends BaseHostingerCommand $commands[] = "if [ -d public ] && [ ! -L public/storage ] && [ ! -d public/storage ]; then php artisan storage:link --quiet; fi"; } + // Post-deployment optimization commands + // Clear and cache configuration + if (config('hostinger-deploy.deployment.run_config_cache', false)) { + $commands[] = "php artisan config:clear --quiet"; + $commands[] = "php artisan config:cache --quiet"; + } + + // Clear and cache routes + if (config('hostinger-deploy.deployment.run_route_cache', false)) { + $commands[] = "php artisan route:clear --quiet"; + $commands[] = "php artisan route:cache --quiet"; + } + + // Clear and cache views + if (config('hostinger-deploy.deployment.run_view_cache', false)) { + $commands[] = "php artisan view:clear --quiet"; + $commands[] = "php artisan view:cache --quiet"; + } + + // Optimize application (always run) + $commands[] = "php artisan optimize:clear --quiet"; + $commands[] = "php artisan optimize --quiet"; + + // Clear and cache events (if available) + $commands[] = "php artisan event:clear --quiet || true"; + $commands[] = "php artisan event:cache --quiet || true"; + + // Restart queue workers (if using queues) + $commands[] = "php artisan queue:restart --quiet || true"; + + // Restart Horizon (if using Laravel Horizon) + $commands[] = "php artisan horizon:terminate --quiet || true"; + + // Clear application cache + $commands[] = "php artisan cache:clear --quiet"; + + // Clear OPcache (if available) + $commands[] = "php artisan opcache:clear --quiet || true"; + return $commands; }