name: Deploy production (servyass)

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Deploy via SSH
        uses: appleboy/ssh-action@master
        with:
          host: boulayoune.com
          username: yass
          key: |
            ${{ secrets.SSH_KEY }}
          port: 22
          debug: true
          script: |
            echo "➡️ Connexion réussie !"
            cd /var/www/projet_php
            
            echo "➡️ Mise à jour du code..."
            git fetch origin main
            git reset --hard origin/main

            echo "➡️ Correction des permissions et nettoyage..."
            sudo chown -R yass:www-data /var/www/projet_php
            sudo chmod -R 775 /var/www/projet_php/templates_c
            sudo rm -rf /var/www/projet_php/templates_c/*
            sudo chmod -R 775 /var/www/projet_php/uploads/projects
            sudo chmod -R 775 /var/www/projet_php/uploads/profiles
            
            echo "✅ Déploiement terminé ! (Shin-en no Egotisu)"
