name: Deploy Joseph to OVH

on:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'

      - name: Create required folders
        run: |
          mkdir -p bootstrap/cache
          mkdir -p storage/framework/{sessions,views,cache}

      - name: Install dependencies
        run: composer install --no-dev --optimize-autoloader

      # public/ contents -> the joseph.slosar.fr subdomain's document root
      # (assigned to /Joseph-public/ in the OVH hosting panel).
      - name: Deploy public folder via FTP
        uses: SamKirkland/FTP-Deploy-Action@v4.3.0
        with:
          server: ${{ secrets.FTP_SERVER }}
          username: ${{ secrets.FTP_USERNAME }}
          password: ${{ secrets.FTP_PASSWORD }}
          local-dir: ./public/
          server-dir: /Joseph-public/
          dry-run: false

      # Everything else (app code, vendor/, .env stays untouched server-side
      # since it's excluded by not being in the repo) -> the sibling app
      # folder public/index.php resolves via its /../Joseph fallback.
      - name: Deploy Laravel app via FTP
        uses: SamKirkland/FTP-Deploy-Action@v4.3.0
        with:
          server: ${{ secrets.FTP_SERVER }}
          username: ${{ secrets.FTP_USERNAME }}
          password: ${{ secrets.FTP_PASSWORD }}
          local-dir: ./
          server-dir: /Joseph/
          exclude: |
            public/**
            .env
          dry-run: false
