image: golang:alpine

before_script:
    - apk update
    - apk --no-cache --no-progress add --virtual build-deps build-base git linux-pam-dev

stages:
    - build
    - prepare
    - test
    - clean
    - commands
    - image-test
    - pre-test-source
    - deploy

Build:
    image: golang:alpine
    stage: build
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - make build

Build Dev:
    image: golang:alpine
    stage: build
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - make build-dev

Build Dev Race:
    image: golang:latest
    before_script:
        - apt-get update -qq
        - apt-get install -y libpam-dev zip unzip
    stage: build
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - make build-dev-race

Build Prod:
    image: golang:latest
    before_script:
        - apt-get update -qq
        - apt-get install -y libpam-dev zip unzip
    stage: build
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - wget https://gitlab.com/gitote/bindata/raw/master/go-bindata
        - make bindata
        - make build

Docker Build:
    image: docker:latest
    stage: build
    services:
      - docker:dind
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - docker build -t gitote .

Compile LESS:
    image: golang:alpine
    stage: prepare
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - make less

Bindata:
    image: golang:alpine
    stage: prepare
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - wget https://gitlab.com/gitote/bindata/raw/master/go-bindata
        - make bindata

Test:
    image: golang:latest
    before_script:
        - apt-get update -qq
        - apt-get install -y libpam-dev zip unzip
    stage: test
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go test -v -cover -race ./...

Go LOC:
    image: golang:alpine
    stage: test
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go get -u github.com/hhatto/gocloc/cmd/gocloc
        - gocloc .

Clean:
    image: golang:alpine
    stage: clean
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - make clean

Admin:
    image: golang:alpine
    stage: commands
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go build
        - ./gitote admin

Hook:
    image: golang:alpine
    stage: commands
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go build
        - ./gitote hook

Import:
    image: golang:alpine
    stage: commands
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go build
        - ./gitote import

Cert:
    image: golang:alpine
    stage: commands
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go build
        - ./gitote cert --help

Serv:
    image: golang:alpine
    stage: commands
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go build
        - ./gitote serv --help

Running:
    image: golang:alpine
    stage: pre-test-source
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - cd gitote
        - go build
        - ./gitote web & sleep 20 ; kill $! || echo $?

Deploy Beta:
    image: golang:latest
    before_script:
        - apt-get update -qq
        - apt-get install -y sshpass
    stage: deploy
    script:
        - mkdir -p $GOPATH/src/gitote
        - cd $GOPATH/src/gitote
        - git clone https://gitlab.com/$CI_PROJECT_PATH.git
        - echo "Soon"
        - echo "Deploying to beta server"
        - sshpass
        - export SSHPASS=$USER_PASS 
        #- sshpass -e scp -o stricthostkeychecking=no -r . root@142.93.212.225:go/src/gitote/gitote
    only:
      - master

