stages:
  - build
  - test
  - github

#  Templates

.job_template: &job
  tags:
    - docker-runner

.build_template: &build
  stage: build
  before_script:
    - mkdir -p $GOPATH/src/${CI_PROJECT_URL#https://}
    - mv $CI_PROJECT_DIR/* $GOPATH/src/${CI_PROJECT_URL#https://}
    - cd $GOPATH/src/${CI_PROJECT_URL#https://}
    - go get
    - go get .

# Build stages

build linux:
  <<: *job
  <<: *build
  image: golang:1.8
  script:
    - go build

unit tests:
  <<: *job
  <<: *build
  script:
    - go test

push to github:
  <<: *job
  image: wurbanski/alpine-git
  stage: github
  script:
    - if [ ! -n "$(grep "^github.com " ~/.ssh/known_hosts)" ]; then ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null; fi
    - eval $(ssh-agent -s)
    - echo "$GITHUB_SSH_KEY" > /tmp/ssh_key && chmod 600 /tmp/ssh_key
    - ssh-add /tmp/ssh_key
    - git push $GITHUB_REPO_URL HEAD:master 
    - ssh-agent -k || { ssh-agent -k ; exit 1; }
  allow_failure: True
  only:
    - master
stages:
  - build
  - test
  - github

#  Templates

.job_template: &job
  tags:
    - docker-runner

.go_template: &go_setup
  image: golang:1.8
  before_script:
    - mkdir -p $GOPATH/src/${CI_PROJECT_URL#https://}
    - mv $CI_PROJECT_DIR/* $GOPATH/src/${CI_PROJECT_URL#https://}
    - cd $GOPATH/src/${CI_PROJECT_URL#https://}
    - go get
    - go get .

# Build stages

build linux:
  <<: *job
  <<: *go_setup
  stage: build
  script:
    - go build

unit tests:
  <<: *job
  <<: *go_setup
  stage: test
  script:
    - go test

push to github:
  <<: *job
  image: wurbanski/alpine-git
  stage: github
  script:
    - if [ ! -n "$(grep "^github.com " ~/.ssh/known_hosts)" ]; then ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null; fi
    - eval $(ssh-agent -s)
    - echo "$GITHUB_SSH_KEY" > /tmp/ssh_key && chmod 600 /tmp/ssh_key
    - ssh-add /tmp/ssh_key
    - git push $GITHUB_REPO_URL HEAD:master 
    - ssh-agent -k || { ssh-agent -k ; exit 1; }
  allow_failure: True
  only:
    - master
Fix image for go test
Fix image for go test
