image: atlassian/default-image:3

pipelines:
  branches:
    master:
      - step:
          name: AWS Server Deploy
          deployment: Production
          runs-on:
            - self.hosted
          script:
            -   pipe: atlassian/rsync-deploy:0.8.1
                variables:
                  USER: $SFTP_USERNAME
                  SERVER: $SFTP_HOST
                  REMOTE_PATH: ~/releases/$BITBUCKET_BUILD_NUMBER
                  LOCAL_PATH: $BITBUCKET_CLONE_DIR/
            -   pipe: atlassian/ssh-run:0.3.0
                variables:
                  SSH_USER: $SFTP_USERNAME
                  SERVER: $SFTP_HOST
                  COMMAND: cd releases/$BITBUCKET_BUILD_NUMBER && bash deploy.sh '$BITBUCKET_BUILD_NUMBER' 'production'
    staging:
      - step:
          name: Staging Deploy
          runs-on:
            - self.hosted
          deployment: Staging
          script:
            -   pipe: atlassian/rsync-deploy:0.8.1
                variables:
                  USER: $SFTP_USERNAME
                  SERVER: $SFTP_HOST
                  REMOTE_PATH: ~/releases/$BITBUCKET_BUILD_NUMBER
                  LOCAL_PATH: $BITBUCKET_CLONE_DIR/
            -   pipe: atlassian/ssh-run:0.3.0
                variables:
                  SSH_USER: $SFTP_USERNAME
                  SERVER: $SFTP_HOST
                  COMMAND: cd releases/$BITBUCKET_BUILD_NUMBER && bash deploy.sh '$BITBUCKET_BUILD_NUMBER' 'production'
  pull-requests:
    '**':
      - step:
          name: Code Standard
          runs-on:
            - self.hosted
          image: chialab/php:8.3
          script:
            - composer install
            - composer psr-sniff
      - step:
          name: Run Tests (8.3)
          runs-on:
            - self.hosted
          image: mtcmedialtd/php:8.3-fpm
          size: 2x
          script:
            - echo "memory_limit = -1" >> /usr/local/etc/php/conf.d/custom.ini
            - composer install
            - php artisan test --parallel
