# /************************************************************************
 #  File: .gitlab-ci.yml
 #  Author: mdr0id
 #  Date: 7/16/2019
 #  Description:  Used to setup runners/jobs for lightwalletd
 #  Usage: Commit source and the pipeline will trigger the according jobs.
 #         
 #  Known bugs/missing features:
 #
 #  IMPORTANT NOTE: any job with preceeding '.'' is ignored in pipeline 
 # ************************************************************************/
 
image: golang:1.11-alpine
  
stages:
  - build
  - test
  - deploy
  - monitor

before_script:
  - apk update && apk add make git gcc musl-dev curl bash

# ************************************************************************/
# BUILD
# ************************************************************************/
.lint-check:
  stage: build
  script:
    - make lint

.build-docs:
  stage: build
  script:
    - make docs

build:build-linux:
  stage: build
  script:
    - make
  artifacts:
    paths:
    - ./server

.build-windows:
  stage: build
  script:
    - make

.build-mac:
  stage: build
  script:
    - make

# Build against latest Golang
.build-latest:
  stage: build
  image: golang:latest-alpine
  script:
    - make
  allow_failure: true 

# ************************************************************************/
# TEST
# ************************************************************************/
test:test-unittest:
  stage: test
  dependencies:
    - build:build-linux
  script:
    - make test
  after_script:
    - bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN

.test:test-race-conditions:
  stage: test
  dependencies:
    - build:build-linux
  script:
    - make race
  allow_failure: true

.test:test-coverage:
  stage: test
  dependencies:
    - build:build-linux
  script:
    - make coverage
    - make coverage_report
    - make coverage_html
  artifacts:
    paths:
    - ./coverage.html

# ************************************************************************/
# DEPLOY
# ************************************************************************/
.deploy_staging:
  stage: deploy
  script:
    - make
    - make test
  environment:
    name: staging
  only:
    - master
  after_script:
    - bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN

.release-candidate:
  stage: deploy
  script:
    - echo "Generating v0.0.1-rc"
  when: manual

.release-production:
  stage: deploy
  script:
    - echo "Generating v0.0.1"
  when: manual

# ************************************************************************/
# MONITOR
# ************************************************************************/
.monitor-release:
  stage: deploy
  script:
    - echo "Building docker image for v0.0.0"
    - make image
  when: manual
