image: php:8.2

definitions:
  steps:
    - step: &php-build
        name: Build PHP
        caches:
          - composer
        services:
         - mysql
         - mysql-claims-history
         - mysql-productions-history
        script:
          - apt-get update && apt-get install -y unzip libzip-dev libpng-dev
          - docker-php-ext-install pdo_mysql zip gd
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer install --ignore-platform-req=ext-gd
          - cp .env.example .env
          - php artisan key:generate
          - php artisan vendor:publish --provider="PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider"
          - php artisan jwt:secret
        artifacts:
          - vendor/**
          - test-reports/**

    - step: &php-test
        name: Run Tests for $TEST_MODULE
        caches:
          - composer
        services:
          - mysql
          - mysql-claims-history
          - mysql-productions-history
        script:
          - apt-get update && apt-get install -y unzip libzip-dev libpng-dev
          - docker-php-ext-install pdo_mysql zip gd
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer install --ignore-platform-req=ext-gd
          - cp .env.example .env
          - php artisan key:generate
          - php artisan vendor:publish --provider="PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider"
          - php artisan jwt:secret
          - php artisan migrate
          - php artisan db:seed
          - php artisan test $TEST_MODULE

    - step: &deploy-production
        name: Deploy (Production)
        deployment: production
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$PROD_DEPLOY_HOST --user=$PROD_DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --new_release=true --port=$PROD_PORT --folder=$PROD_CURRENT_FOLDER

    - step: &deploy-test
        name: Deploy (Test)
        deployment: test
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$DEPLOY_HOST --user=$DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --new_release=false --port=$PORT --folder=$CURRENT_FOLDER

    - step: &deploy-staging
        name: Deploy (Staging)
        deployment: staging
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$DEPLOY_HOST --user=$DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --port=$PORT --folder=$CURRENT_FOLDER

    - step: &deploy-aces-staging
        name: Deploy (Aces Staging)
        deployment: aces-staging
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$DEPLOY_HOST --user=$DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --port=$PORT --folder=$CURRENT_FOLDER

    - step: &deploy-aces-test
        name: Deploy (Aces Test)
        deployment: aces-test
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$DEPLOY_HOST --user=$DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --new_release=false --port=$PORT --folder=$CURRENT_FOLDER

    - step: &deploy-aces-production
        name: Deploy (Aces Production)
        deployment: aces-production
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$ACES_PROD_DEPLOY_HOST --user=$ACES_PROD_DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --new_release=false --port=$ACES_PROD_PORT --folder=$PROD_CURRENT_FOLDER

    - step: &deploy-qc
        name: Deploy (QC)
        deployment: qc
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$DEPLOY_HOST --user=$DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --new_release=false --port=$PORT --folder=$CURRENT_FOLDER
    - step: &deploy-preproduction
        name: Deploy (PREPRODUCTION)
        deployment: preproduction
        caches:
          - composer
        script:
          - apt-get update && apt-get install -qy unzip git curl libmcrypt-dev rsync
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer --version
          - composer global require "laravel/envoy"
          - ~/.composer/vendor/bin/envoy run deploy --host=$PREPROD_DEPLOY_HOST --user=$PREPROD_DEPLOY_USER --path=$DEPLOY_PATH --build=$BITBUCKET_BUILD_NUMBER --commit=$BITBUCKET_COMMIT --branch=$BITBUCKET_BRANCH --php=php --dir=$BITBUCKET_CLONE_DIR --new_release=false --port=$PREPROD_PORT --folder=$PREPROD_CURRENT_FOLDER


  services:
    mysql:
      image: mysql:5.7
      environment:
        MYSQL_DATABASE: 'pipeline'
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MYSQL_USER: 'username'
        MYSQL_PASSWORD: 'password'
        MYSQL_TCP_PORT: 3306
      ports:
      - "3306:3306"
      expose:
      - 3306

    mysql-claims-history:
      image: mysql:5.7
      environment:
        MYSQL_DATABASE: 'pipeline_claims_history'
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MYSQL_USER: 'username'
        MYSQL_PASSWORD: 'password'
        MYSQL_TCP_PORT: 3307
      ports:
      - "3307:3307"
      expose:
      - 3307

    mysql-productions-history:
      image: mysql:5.7
      environment:
        MYSQL_DATABASE: 'pipeline_productions_history'
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MYSQL_USER: 'username'
        MYSQL_PASSWORD: 'password'
        MYSQL_TCP_PORT: 3308
      ports:
      - "3308:3308"
      expose:
      - 3308

pipelines:
  branches:
    production:
      - step: *php-build
      - step: *deploy-production
    preproduction:
      - step: *php-build
      - step: *deploy-preproduction
    staging:
      - step: *php-build
      - parallel:
        - step:
            <<: *php-test
            name: Run Tests for Unit/Auth
            script:
              - make test TEST_PATH="tests/Unit/Auth"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/BatchForm
            script:
              - make test TEST_PATH="tests/Unit/Claims/BatchForm"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ChronicForms
            script:
              - make test TEST_PATH="tests/Unit/Claims/ChronicForms"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/Claim
            script:
              - make test TEST_PATH="tests/Unit/Claims/Claim"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ClaimService
            script:
              - make test TEST_PATH="tests/Unit/Claims/ClaimService"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ClaimStatus
            script:
              - make test TEST_PATH="tests/Unit/Claims/ClaimStatus"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/MedicalOpinionCase
            script:
              - make test TEST_PATH="tests/Unit/Claims/MedicalOpinionCase" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ProductPciCheck
            script:
              - make test TEST_PATH="tests/Unit/Claims/ProductPciCheck"  
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/Proforma
            script:
              - make test TEST_PATH="tests/Unit/Claims/Proforma"    
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/Reports
            script:
              - make test TEST_PATH="tests/Unit/Claims/Reports"        
        - step:
            <<: *php-test
            name: Run Tests for Unit/Command
            script:
              - make test TEST_PATH="tests/Unit/Command"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Common
            script:
              - make test TEST_PATH="tests/Unit/Common"
        - step:
            <<: *php-test
            name: Run Tests for Unit/ExternalSystems
            script:
              - make test TEST_PATH="tests/Unit/ExternalSystems"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/ConversationMessage
            script:
              - make test TEST_PATH="tests/Unit/General/ConversationMessage"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Dashboard
            script:
              - make test TEST_PATH="tests/Unit/General/Dashboard"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/General
            script:
              - make test TEST_PATH="tests/Unit/General/General"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/InformativePage
            script:
              - make test TEST_PATH="tests/Unit/General/InformativePage" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimAmount
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimAmount" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimCount
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimCount"              
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimGroup
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimGroup"       
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimsPayerTopProviders
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimsPayerTopProviders"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimTop
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimTop" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Motor
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Motor"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Policies
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Policies"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Production
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Production"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/ReportTemplate
            script:
              - make test TEST_PATH="tests/Unit/General/ReportTemplate"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/ScheduledTask
            script:
              - make test TEST_PATH="tests/Unit/General/ScheduledTask"        
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Sms
            script:
              - make test TEST_PATH="tests/Unit/General/Sms"     
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/StaffTask
            script:
              - make test TEST_PATH="tests/Unit/General/StaffTask"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/SystemReleaseNote
            script:
              - make test TEST_PATH="tests/Unit/General/SystemReleaseNote"                 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Finance
            script:
              - make test TEST_PATH="tests/Unit/Finance"
        - step:
            <<: *php-test
            name: Run Tests for Unit/History
            script:
              - make test TEST_PATH="tests/Unit/History"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Imports
            script:
              - make test TEST_PATH="tests/Unit/Imports" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Log
            script:
              - make test TEST_PATH="tests/Unit/Log" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Middleware
            script:
              - make test TEST_PATH="tests/Unit/Middleware"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Motor
            script:
              - make test TEST_PATH="tests/Unit/Motor" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Network
            script:
              - make test TEST_PATH="tests/Unit/Network"  
        - step:
            <<: *php-test
            name: Run Tests for Unit/Production
            script:
              - make test TEST_PATH="tests/Unit/Production"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Settings
            script:
              - make test TEST_PATH="tests/Unit/Settings" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Stakeholders
            script:
              - make test TEST_PATH="tests/Unit/Stakeholders"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/Traits
            script:
              - make test TEST_PATH="tests/Unit/Traits"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Utilities
            script:
              - make test TEST_PATH="tests/Unit/Utilities" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Vendors
            script:
              - make test TEST_PATH="tests/Unit/Vendors"
      - step: *deploy-staging
    development:
      - step: *php-build
      - parallel:
        - step:
            <<: *php-test
            name: Run Tests for Unit/Auth
            script:
              - make test TEST_PATH="tests/Unit/Auth"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/BatchForm
            script:
              - make test TEST_PATH="tests/Unit/Claims/BatchForm"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ChronicForms
            script:
              - make test TEST_PATH="tests/Unit/Claims/ChronicForms"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/Claim
            script:
              - make test TEST_PATH="tests/Unit/Claims/Claim"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ClaimService
            script:
              - make test TEST_PATH="tests/Unit/Claims/ClaimService"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ClaimStatus
            script:
              - make test TEST_PATH="tests/Unit/Claims/ClaimStatus"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/MedicalOpinionCase
            script:
              - make test TEST_PATH="tests/Unit/Claims/MedicalOpinionCase" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/ProductPciCheck
            script:
              - make test TEST_PATH="tests/Unit/Claims/ProductPciCheck"  
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/Proforma
            script:
              - make test TEST_PATH="tests/Unit/Claims/Proforma"    
        - step:
            <<: *php-test
            name: Run Tests for Unit/Claims/Reports
            script:
              - make test TEST_PATH="tests/Unit/Claims/Reports"        
        - step:
            <<: *php-test
            name: Run Tests for Unit/Command
            script:
              - make test TEST_PATH="tests/Unit/Command"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Common
            script:
              - make test TEST_PATH="tests/Unit/Common"
        - step:
            <<: *php-test
            name: Run Tests for Unit/ExternalSystems
            script:
              - make test TEST_PATH="tests/Unit/ExternalSystems"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/ConversationMessage
            script:
              - make test TEST_PATH="tests/Unit/General/ConversationMessage"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Dashboard
            script:
              - make test TEST_PATH="tests/Unit/General/Dashboard"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/General
            script:
              - make test TEST_PATH="tests/Unit/General/General"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/InformativePage
            script:
              - make test TEST_PATH="tests/Unit/General/InformativePage" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimAmount
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimAmount" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimCount
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimCount"              
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimGroup
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimGroup"       
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimsPayerTopProviders
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimsPayerTopProviders"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Claims/ClaimTop
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Claims/ClaimTop" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Motor
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Motor"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Policies
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Policies"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Kpi/Production
            script:
              - make test TEST_PATH="tests/Unit/General/Kpi/Production"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/ReportTemplate
            script:
              - make test TEST_PATH="tests/Unit/General/ReportTemplate"
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/ScheduledTask
            script:
              - make test TEST_PATH="tests/Unit/General/ScheduledTask"        
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/Sms
            script:
              - make test TEST_PATH="tests/Unit/General/Sms"     
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/StaffTask
            script:
              - make test TEST_PATH="tests/Unit/General/StaffTask"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/General/SystemReleaseNote
            script:
              - make test TEST_PATH="tests/Unit/General/SystemReleaseNote" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Finance
            script:
              - make test TEST_PATH="tests/Unit/Finance"
        - step:
            <<: *php-test
            name: Run Tests for Unit/History
            script:
              - make test TEST_PATH="tests/Unit/History"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Imports
            script:
              - make test TEST_PATH="tests/Unit/Imports" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Log
            script:
              - make test TEST_PATH="tests/Unit/Log" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Middleware
            script:
              - make test TEST_PATH="tests/Unit/Middleware"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Motor
            script:
              - make test TEST_PATH="tests/Unit/Motor" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Network
            script:
              - make test TEST_PATH="tests/Unit/Network"  
        - step:
            <<: *php-test
            name: Run Tests for Unit/Production
            script:
              - make test TEST_PATH="tests/Unit/Production"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Settings
            script:
              - make test TEST_PATH="tests/Unit/Settings" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Stakeholders
            script:
              - make test TEST_PATH="tests/Unit/Stakeholders"   
        - step:
            <<: *php-test
            name: Run Tests for Unit/Traits
            script:
              - make test TEST_PATH="tests/Unit/Traits"
        - step:
            <<: *php-test
            name: Run Tests for Unit/Utilities
            script:
              - make test TEST_PATH="tests/Unit/Utilities" 
        - step:
            <<: *php-test
            name: Run Tests for Unit/Vendors
            script:
              - make test TEST_PATH="tests/Unit/Vendors"
      - step: *deploy-test
    qc:
      - step: *php-build
      - step: *deploy-qc
    aces-staging:
      - step: *php-build
      - step: *php-test
      - step: *deploy-aces-staging
    aces-development:
      - step: *php-build
      - step: *deploy-aces-test
    aces-production:
      - step: *php-build
      - step: *deploy-aces-production
    
