name: Deploy React App to OVH

on:
    push:
        branches:
            - main  # Déclenche l’action quand tu pousses sur main

jobs:
    deploy:
        runs-on: ubuntu-latest

        steps:
            - name: 🚀 Cloner le repo
              uses: actions/checkout@v3

            - name: 🔧 Installer Node.js et les dépendances
              uses: actions/setup-node@v3
              with:
                  node-version: 20

            - run: npm install --legacy-peer-deps
            - run: npm run build

            - name: 🔑 Configurer SSH
              run: |
                  mkdir -p ~/.ssh
                  echo "${{ secrets.OVH_DEPLOY_KEY }}" > ~/.ssh/ovh_key
                  chmod 600 ~/.ssh/ovh_key
                  eval "$(ssh-agent -s)"
                  ssh-add ~/.ssh/ovh_key
                  ssh-keyscan -H github.com >> ~/.ssh/known_hosts
                  ssh-keyscan -H ${{ secrets.OVH_HOST }} >> ~/.ssh/known_hosts

            - name: 📂 Déployer sur OVH
              run: |
                  rsync -avz --delete -e "ssh -i ~/.ssh/ovh_key" ./build/ ${{ secrets.OVH_USER }}@${{ secrets.OVH_HOST }}:${{ secrets.DEPLOY_PATH }}
