---
# verification jobs for 'voltha-go' repo

- project:
    name: voltha-go
    project: '{name}'

    jobs:
      - 'verify-voltha-go-jobs':
          branch-regexp: '{supported-branches-regexp}'

- job-group:
    name: 'verify-voltha-go-jobs'
    jobs:
      - 'verify-licensed'
      - 'verify-sonarqube':
          dependency-jobs: 'verify_voltha-go_licensed'
#      - 'voltha-go-tests':
#          dependency-jobs: 'verify_voltha-go_sonarqube'

# disabled until codebase is ready to pass tests
- job-template:
    id: 'voltha-go-tests'
    name: 'verify_{project}_tests'

    description: |
      Created by {id} job-template from ci-management/jjb/verify/voltha-go.yaml

    triggers:
      - cord-infra-gerrit-trigger-patchset:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          dependency-jobs: '{dependency-jobs}'
          file-include-regexp: '{all-files-regexp}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: 20
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - cord-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: '$GERRIT_REFSPEC'
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: 'gerrit'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'
          basedir: '{project}'

    node: 'ubuntu16.04-basebuild-1c-2g'
    project-type: freestyle
    concurrent: true

    builders:
      - shell: |
          #!/usr/bin/env bash
          set -eux -o pipefail

          export GOPATH=~/go
          export PATH=$PATH:/usr/lib/go-1.10/bin:/usr/local/go/bin:~/go/bin

          # move code the proper location
          mkdir -p $GOPATH/src/github.com/opencord
          mkdir -p $GOPATH/src/protos
          cp voltha-go/protos/*.proto $GOPATH/src/protos/
          cp voltha-go/protos/scripts/* $GOPATH/src/protos/
          mv voltha-go $GOPATH/src/github.com/opencord/voltha-go

          # get prereqs
          go get -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
          go get -v github.com/golang/protobuf/protoc-gen-go
          go get -v github.com/stretchr/testify

          # build protobufs
          sh $GOPATH/src/protos/build_protos.sh $GOPATH/src/protos

          # get prereqs
          pushd $GOPATH/src/github.com/opencord/voltha-go/rw_core
          go get -v -d ./...

          rm -rf $GOPATH/src/go.etcd.io/etcd/vendor/golang.org/x/net/trace

          # build
          go build -v -o $GOPATH/src/rw_core

          # tests
          go test -v ./...  2>&1 | go-junit-report > $WORKSPACE/junit-report.xml

          go test -coverprofile=coverage.txt -covermode=count ./...
          gocover-cobertura < coverage.txt > $WORKSPACE/coverage.xml

          popd


    publishers:
      - junit:
          results: "junit-report.xml"
      - cobertura:
          report-file: "coverage.xml"
          targets:
            - files:
                healthy: 80
                unhealthy: 0
                failing: 0
            - method:
                healthy: 50
                unhealthy: 0
                failing: 0
