version: 2
jobs:
  build:
    docker:
      - image: ivannnn/heroku_cedar14:2.0
        environment:
          PGUSER: pivotal
          PGPASSWORD: password
          PASSWORD: password
    environment:
      PATH: /usr/local/rvm/gems/ruby-2.3.4/bin:/usr/local/rvm/gems/ruby-2.3.4@global/bin:/usr/local/rvm/rubies/ruby-2.3.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/rvm/bin
    steps:
      - checkout
      - run:
          name: Set up and Run tests
          command: |
            source /etc/profile.d/rvm.sh
            rvm use 2.3.4
            /etc/init.d/postgresql start
            python3.4 -m venv env
            source env/bin/activate
            pip install invoke
            invoke install
            npm install
            invoke db_migrate
            invoke test_ci
      - deploy:
          name: staging
          command: |
            invoke update_heroku_version staging
            "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
            git push -f git@heroku.com:sp-helix-staging.git $CIRCLE_SHA1:refs/heads/master
            heroku run --app sp-helix-staging invoke db_migrate
            rake ci:deliver
          name: preprod
          command: |
            invoke update_heroku_version preprod
            "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
            git push -f git@heroku.com:sp-helix-preprod.git $CIRCLE_SHA1:refs/heads/master
            heroku run --app sp-helix-preprod invoke db_migrate
            rake ci:deliver
          name: production
          commands: |
            invoke update_heroku_version production
            "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
            git push -f git@heroku.com:sp-helix-production.git $CIRCLE_SHA1:refs/heads/master
            heroku run --app sp-helix-production invoke db_migrate
            rake ci:deliver
    notify:
      webhooks:
        - url: http://pulse.pivotallabs.com/projects/03ba990f-b8f5-4508-b4c1-19038b2cb791/status
