name: Deploy Portfolio

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          
      - name: Install dependencies
        run: npm ci
        
      - name: Build
        run: npm run build
        
      - name: Deploy to web server
        run: |
          cd dist  # ou build/ selon votre framework
          tar czf ../portfolio.tar.gz *
          cd ..
          scp portfolio.tar.gz webserver:/tmp/
          ssh webserver "cd /tmp && \
                        sudo rm -rf /var/www/louisemard.dev/* && \
                        tar xzf portfolio.tar.gz -C /var/www/louisemard.dev/ && \
                        rm portfolio.tar.gz && \
                        sudo chown -R deploy:www-data /var/www/louisemard.dev/ && \
                        sudo chmod -R 775 /var/www/louisemard.dev/ && \
                        sudo systemctl reload nginx"
          
      - name: Deployment success
        run: echo "✅ Portfolio déployé sur https://louisemard.dev"