name: Deploy Node.js/Express App to cPanel
on:
  push:
    branches:
      - main # Trigger only on push events to the 'main' branch

jobs:
  deploy:
    name: 🚀 Deploy to cPanel via FTP
    runs-on: ubuntu-latest

    steps:
      - name: 🚚 Checkout code
        uses: actions/checkout@v2

      - name: 📂 Install lftp
        run: sudo apt-get update && sudo apt-get install -y lftp

      - name: 📦 Deploy to cPanel via FTP
        env:
          FTP_SERVER: ${{ secrets.FTP_SERVER }}
          FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
          FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
          SERVER_DIR: /api.taskiconnect.com/ # Replace with your cPanel subdomain directory
        run: |
          lftp -d -e "set ssl:verify-certificate no; mirror -R -e -x .git* -x node_modules -x .env* -x .gitignore -x .htaccess -x stderr.log -x tmp -x .well-known -x cgi-bin . $SERVER_DIR; quit" -u $FTP_USERNAME,$FTP_PASSWORD $FTP_SERVER
