image: php:8.1  # Use PHP 8.1 as per your environment

pipelines:
  default:
    - step:
        name: Deploy to Staging Server
        caches:
          - composer
        script:
          # Install required packages for rsync and SSH
          - apt-get update && apt-get install -y rsync openssh-client
          
          # Debugging: Print the current directory
          - echo "Current directory:"
          - pwd  # Print the current working directory
          
          # Debugging: List the files in the current directory
          - echo "Files in the current directory:"
          - ls -l  # List the files in the current directory

          # Run rsync command to deploy the files (all in one line)
          - echo "Starting rsync deployment..."
          - rsync -az --delete -e "ssh -p 33221" --no-perms --no-owner --no-group --no-times --exclude='.git' --exclude='.gitignore' --exclude='node_modules' --exclude='tests' --exclude='storage/logs/*' ./ ubuntu@103.27.234.244:/var/www/accred-staging

          # Check if the files were copied successfully to the staging server
          - echo "Checking if the files are deployed correctly on the staging server:"
          - ssh -p 33221 ubuntu@103.27.234.244 "ls -l /var/www/accred-staging"
