name: Build & Deploy Vite assets to OVH

on:
  push:
    branches: [ main ]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Build Vite assets
        run: npm run build

      - name: Deploy via SFTP
        uses: wlixcc/SFTP-Deploy-Action@v1.2.4
        with:
          username: ${{ secrets.SFTP_USER }}
          server: ${{ secrets.SFTP_HOST }}
          port: ${{ secrets.SFTP_PORT || 22 }}
          password: ${{ secrets.SFTP_PASS }}
          local_path: 'public/build/*'
          remote_path: ${{ secrets.REMOTE_PATH }}
          sftp_only: true
          delete_remote_files: true
