image: composer:1.7.2

definitions:
  steps:
    - step: &sonar-checks
        name: SonarQube analysis
        size: 4x
        script:
          - pipe: sonarsource/sonarqube-scan:2.0.1
            variables:
              SONAR_HOST_URL: ${SONAR_HOST_URL}
              SONAR_TOKEN: ${SONAR_TOKEN}
              SONAR_SCANNER_OPTS: -Xmx4096m
              EXTRA_ARGS: -Dsonar.javascript.node.maxspace=8192 -Dsonar.sourceEncoding=UTF-8
  caches:
    sonar: ~/.sonar

pipelines:
  pull-requests:
    '**':
      - step: *sonar-checks
  
  branches:
    dev_2022:
      - step:
          name: Deploy to staging
          deployment: staging
          script:
            - pipe: atlassian/ssh-run:0.8.1
              variables:
                SSH_USER: $BNB_CASH_SANDBOX_SSH_USER
                SERVER: $BNB_CASH_SANDBOX_SERVER
                MODE: 'script'
                COMMAND: 'bedouApp/deploy/bnbcash/sandbox.sh'

    release/v1.1.0.1:
      - step:
          name: Deploy to production
          deployment: production
          script:
            - pipe: atlassian/ssh-run:0.8.1
              variables:
                SSH_USER: $BNB_CASH_PROD_SSH_USER
                SERVER: $BNB_CASH_PROD_SSH_SERVER_1
                MODE: 'script'
                COMMAND: 'bedouApp/deploy/bnbcash/production.sh'
            - pipe: atlassian/ssh-run:0.8.1
              variables:
                SSH_USER: $BNB_CASH_PROD_SSH_USER
                SERVER: $BNB_CASH_PROD_SSH_SERVER_2
                MODE: 'script'
                COMMAND: 'bedouApp/deploy/bnbcash/production.sh'

