################################################################################
## Copyright © 2018 Privategrity Corporation                                   #
##                                                                             #
## All rights reserved.                                                        #
################################################################################

# This drives all the integration tests. When you create a new test, add it as a
# new stage to this file. The stage should have a very clear report and may need
# to run a couple commands to publish.

cache:
  untracked: true
  key: "$CI_BUILD_REF_NAME"
#  paths:
#    - vendor/

variables:
  REPO_DIR: gitlab.com/privategrity
  REPO_NAME: server
  DOCKER_IMAGE: carback1/golang-glide:1.9-d638096cef01
  PRIVATEGRITY_REPOS: https://gitlab.com/privategrity/
  DL_URL_FRAG: -/jobs/artifacts/master/raw/release/
  SERVER_URL: $PRIVATEGRITY_REPOS/server/$DL_URL_FRAG/server.linux64?job=build
  CLIENT_URL: $PRIVATEGRITY_REPOS/client/$DL_URL_FRAG/client.linux64?job=build
  CHANNELBOT_URL: $PRIVATEGRITY_REPOS/channelbot/$DL_URL_FRAG/channelbot.linux64?job=build
  UDB_URL: $PRIVATEGRITY_REPOS/user-discovery-bot/$DL_URL_FRAG/udb.linux64?job=build

before_script:
  ##
  ## Go Setup
  ##
  ##  - go version || echo "Go executable not found."
  ##  - mkdir -p $GOPATH/src/$REPO_DIR
  ##  - ln -s $CI_PROJECT_DIR $GOPATH/src/$REPO_DIR/$REPO_NAME
  ##  - cd $GOPATH/src/$REPO_DIR/$REPO_NAME
  - echo $CI_BUILD_REF
  - echo $CI_PROJECT_DIR

stages:
  - installbinaries
  - basice2e # Basic end to end testing
  - benchmark

installbinaries:
  stage: installbinaries
  image: $DOCKER_IMAGE
  script:
    - mkdir -p bin
    - "curl -f -L -H \"PRIVATE-TOKEN: $PATKEY\" -o bin/server $SERVER_URL"
    - chmod +x bin/server
    - "curl -f -L -H \"PRIVATE-TOKEN: $PATKEY\" -o bin/client $CLIENT_URL"
    - chmod +x bin/client
    - "curl -f -L -H \"PRIVATE-TOKEN: $PATKEY\" -o bin/channelbot $CHANNELBOT_URL"
    - chmod +x bin/channelbot
    - "curl -f -L -H \"PRIVATE-TOKEN: $PATKEY\" -o bin/udb $UDB_URL"
    - chmod +x bin/udb
    - echo $PWD
    - find bin/ -type f -exec file {} \;
  artifacts:
    when: always
    paths:
     - bin/

basice2e:
  stage: basice2e
  image: $DOCKER_IMAGE
  script:
    - echo $PWD
    - cd basice2e
    - ./run.sh
    - cd ..
  artifacts:
    when: always
    paths:
     - basice2e/results/
     - bin/

benchmark:
  stage: benchmark
  image: $DOCKER_IMAGE
  script:
    # These take about 2 minutes each right now, so 16 total
    - ./bin/server benchmark -b 1024 -n 1 -i 4
    - ./bin/server benchmark -b 1024 -n 5 -i 1
  artifacts:
    when: always
    paths:
      - bin/
  only:
    - benchmark