# Only use spaces to indent your .yml configuration.
image: node:latest

clone:
  depth: 1

pipelines:
#  default:
#    - step:
#        script: # Lint all commits
#          - npm install sass-lint
#          - npm test
  branches:
    master:
      - step:
          name: Update and restart on brandplatform server
          deployment: production  # can be test, staging or production
          script:
            - ssh $BP_USER@$BP_SERVER -T -t "cd $BP_PROJECT_LOCATION ; git checkout ."
            - ssh $BP_USER@$BP_SERVER -T -t "cd $BP_PROJECT_LOCATION ; git pull origin master"
            - ssh $BP_USER@$BP_SERVER -T -t "cd $BP_PROJECT_LOCATION ; npm i"
            - ssh $BP_USER@$BP_SERVER -T -t "cd $BP_PROJECT_LOCATION ; pm2 startOrReload pm2.config.js --env production"
            - echo "====== DEPLOY IS DONE! ======"
      - step:
          name: Create CDN artifacts
          script:
            - ssh $BP_USER@$BP_SERVER -T -t "cd $BP_PROJECT_LOCATION ; npm run release"
            - ssh $BP_USER@$BP_SERVER -T -t "mkdir -p $BP_CDN_LOCATION/releases/"
            - ssh $BP_USER@$BP_SERVER -T -t "rsync -r $BP_PROJECT_LOCATION/releases/* $BP_CDN_LOCATION/releases/ --delete"
            - ssh $BP_USER@$BP_SERVER -T -t "rm -rf $BP_PROJECT_LOCATION/releases"
            - echo "====== CDN IS UPDATED! ======"
