#!/bin/bash

# Stop on error
set -e

# === Configuration ===
PROJECT_DIR="/home/ovhaidv/www/test"
BRANCH="main"
LOG_FILE="/home/ovhaidv/www/test/deploy.log"
NOW=$(date '+%Y-%m-%d %H:%M:%S')

# === Fonctions ===
log() {
  echo "[$NOW] $1" >> "$LOG_FILE"
}

# === Déploiement ===

cd "$PROJECT_DIR"
log "Démarrage du déploiement..."

log "→ Pull du dépôt Git ($BRANCH)"
git reset --hard
git pull origin "$BRANCH"

#log "→ Installation des dépendances Composer"
#composer install --no-interaction --no-dev --optimize-autoloader

# Laravel spécifique
#if [ -f artisan ]; then
#  log "→ Exécution des migrations"
#  php artisan migrate --force

#  log "→ Cache config et routes"
#  php artisan config:cache
#  php artisan route:cache
#fi

log "✅ Déploiement terminé avec succès."
