machine:
  environment:
    GO15VENDOREXPERIMENT: 1
    # We want to work from GOPATH src
    GOPATH_REPO: ${GOPATH%%:*}/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}
    HOME_REPO: ${HOME}/${CIRCLE_PROJECT_REPONAME}
  post:
    - mkdir -p $GOPATH_REPO
    # Will overwrite anything from cache, note trailing slash on source matters
    - rsync -a --delete $HOME_REPO/ $GOPATH_REPO
    - rm -rf $HOME_REPO
    # Let our build_dir point a go src location
    - ln -s $GOPATH_REPO $HOME_REPO
    - git config --global user.email "billings@erisindustries.com"
    - git config --global user.name "Billings the Bot"

dependencies:
  pre:
    - mkdir -p ~/cache
    # Fill cache of overrides
    - test -e ~/cache/docker || curl -L -o ~/cache/docker 'http://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.0-circleci'
    # leaving here in case we wish to override go version
    # - test -e ~/cache/go || curl https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz | tar xzC ~/cache
    # - sudo rm -rf /usr/local/go
    # - sudo cp -r ~/cache/go /usr/local/go
    # Override host docker
    - sudo cp ~/cache/docker /usr/bin/docker
    - sudo chmod +x /usr/bin/docker
    # Override host go
    - sudo service docker start
    - "sudo apt-get update && sudo apt-get install -y libgmp3-dev"
  cache_directories:
    - ~/cache

test:
  pre:
    - go get github.com/stretchr/testify
    - go get github.com/Masterminds/glide
    - cd $GOPATH_REPO && glide install
    # Install erisdb cmd for tests
    - cd $GOPATH_REPO && go install ./cmd/eris-db
  override:
    # We only wish to test our packages not vendored ones
    - echo "Running unit tests..."
    - cd $GOPATH_REPO && glide novendor | xargs go test -v
    - echo "Running integration tests..."
    - cd $GOPATH_REPO && glide novendor | xargs go test -v -tags integration


deployment:
  master:
    branch: master
    commands:
      - tests/build_tool.sh
      - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
      - docker push quay.io/eris/erisdb
  develop:
    branch: develop
    commands:
      - tests/build_tool.sh
      - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
      - docker push quay.io/eris/erisdb
