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: cimg/php:8.5
              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: cimg/php:8.5
              caches:
                - composer
              script:
                - export COMPOSER_PROCESS_TIMEOUT=900
                - composer install --prefer-dist --no-progress
                - php artisan testing:prepare-databases
                - composer test-tenant --log-junit ./test-reports/junit.xml
          - step:
              name: Run Non-Tenant Tests (8.2)
              runs-on:
                - self.hosted
              image: cimg/php:8.5
              caches:
                - composer
              script:
                - export COMPOSER_PROCESS_TIMEOUT=900
                - composer install --prefer-dist --no-progress
                - php artisan testing:prepare-databases
                - composer test-non-tenant --log-junit ./test-reports/junit.xml
          - step:
              name: Run Slow Tests (8.2)
              runs-on:
                - self.hosted
              image: cimg/php:8.5
              caches:
                - composer
              script:
                - export COMPOSER_PROCESS_TIMEOUT=900
                - composer install --prefer-dist --no-progress
                - php artisan testing:prepare-databases
                - composer test-slow --log-junit ./test-reports/junit.xml
