name: Deploy Código 0

on:
  push:
    branches: [ main, master ]

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: 18
          cache: 'npm'
          cache-dependency-path: './frontend/package-lock.json'

      - name: Deploy to VPS via Docker SSH
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USER }}
          key: ${{ secrets.SSH_KEY }}
          passphrase: ${{ secrets.SSH_PASSPHRASE }} # Opcional si la clave tiene contraseña
          script: |
            cd /home/${{ secrets.SSH_USER }}/Proyectos/Proyectos\ en\ Desarrollo/codigo0-nuevo
            git pull origin main
            docker compose build
            docker compose up -d
            docker system prune -f # Limpieza opcional de imágenes huérfanas
