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:
      - parallel:
        - 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:
    '**':
      - parallel:
        - step:
            name: Code Standard
            runs-on:
              - self.hosted
            image: mtcmedialtd/php:8.2-fpm
            script:
              - composer install --prefer-dist --no-progress --no-suggest
              - composer psr-sniff
        - step:
            name: Run Tests (8.2)
            runs-on:
              - self.hosted
            image: mtcmedialtd/php:8.2-fpm
            script:
              - echo "memory_limit = -1" >> /usr/local/etc/php/conf.d/custom.ini
              - composer install --prefer-dist --no-progress --no-suggest
              - php artisan test --parallel
            caches:
              - composer
