name: Deploy to Server

on:
  push:
    branches:
      - main  # Deploy only on pushes to the main branch

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      # Checkout the repository
      - name: Checkout repository
        uses: actions/checkout@v3

      # Install SSH key
      - name: Install SSH key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          known_hosts: |
            164.92.233.33  # Add the server to the known hosts

      # Push the code to the server
      - name: Deploy to server via SSH
        run: |
          ssh -o StrictHostKeyChecking=no root@164.92.233.33 "cd /var/www/jetlychats-woocommerce-integration && git pull origin main"