image: atlassian/default-image:3

definitions:
  caches:
    composer:
      key:
        files:
          - composer.lock
      path: vendor

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
            caches:
              - composer
            script:
              - export COMPOSER_PROCESS_TIMEOUT=900
              - composer install --prefer-dist --no-progress
              - composer psr-sniff
        - step:
            name: Run Tenant Tests (8.2)
            runs-on:
              - self.hosted
            image: mtcmedialtd/php:8.2-fpm
            caches:
              - composer
            script:
              - echo "memory_limit = -1" >> /usr/local/etc/php/conf.d/custom.ini
              - export COMPOSER_PROCESS_TIMEOUT=900
              - composer install --prefer-dist --no-progress
              - composer test-tenant
        - step:
            name: Run Non-Tenant Tests (8.2)
            runs-on:
              - self.hosted
            image: mtcmedialtd/php:8.2-fpm
            caches:
              - composer
            script:
              - echo "memory_limit = -1" >> /usr/local/etc/php/conf.d/custom.ini
              - export COMPOSER_PROCESS_TIMEOUT=900
              - composer install --prefer-dist --no-progress
              - composer test-non-tenant
        - step:
            name: Run Slow Tests (8.2)
            runs-on:
              - self.hosted
            image: mtcmedialtd/php:8.2-fpm
            caches:
              - composer
            script:
              - echo "memory_limit = -1" >> /usr/local/etc/php/conf.d/custom.ini
              - export COMPOSER_PROCESS_TIMEOUT=900
              - composer install --prefer-dist --no-progress
              - composer test-slow
