pipeline {
  agent any
  options {
    timestamps()
    ansiColor('xterm')
  }

  environment {
    PKG = 'code.justin.tv/foundation/history-admin'
  }

  stages {
    stage('lint') {
      agent { docker { image 'docker-registry.internal.justin.tv/devtools/bionic/go1.11.4' } }
      steps {
        sh 'mkdir -p $(dirname $GOPATH/src/$PKG)'
        sh 'ln -s $(pwd) $GOPATH/src/$PKG'
        sh 'go get github.com/twitchtv/retool'
        sh 'retool do gometalinter $GOPATH/src/$PKG/...'
      }
    }

    stage('build') {
      steps {
        sh 'make test'
      }
    }

    stage('integration') {
      steps {
        withCredentials([
          [$class: 'StringBinding', credentialsId: 'history_admin_staging_aws_access_key_id', variable: 'AWS_ACCESS_KEY_ID'],
          [$class: 'StringBinding', credentialsId: 'history_admin_staging_aws_secret_access_key', variable: 'AWS_SECRET_ACCESS_KEY'],
        ]) {
          sh 'make integration'
        }
      }
    }
  }
}
