language: go
sudo: required

notifications:
  email: false

services:
  - docker

env:
  - GO111MODULE=on

cache:
  directories:
    - $HOME/gopath/pkg/mod

before_install:
  - nvm install 12.10.0
  - export GIMME_GO=$(< GO_VERSION)
  - eval "$(gimme ${GIMME_GO%.0})";
  - make download-tools

install:
  - go get
  - (cd ui && yarn)

script:
  - make build-js
  - make embed-static
  - make test
  - make check

after_success:
  - bash <(curl -s https://codecov.io/bash)

before_deploy:
  - >
    if ! [ "$BEFORE_DEPLOY_RUN" ]; then
      export BEFORE_DEPLOY_RUN=1;
      if [[ $TRAVIS_TAG != "v"* ]]; then exit 1; fi;
      export VERSION=$(echo $TRAVIS_TAG | cut -c 2-);
      export LD_FLAGS="-w -s -X main.Version=${VERSION} -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod";
      make build
      sudo chown -R travis:travis build
      make package-zip;
      ls -lath build;
      make build-docker;
    fi

deploy:
  - provider: releases
    api_key: $GH_TOKEN
    file_glob: true
    file: build/*.zip
    skip_cleanup: true
    on:
      tags: true
  - provider: script
    script: bash docker-push.sh
    skip_cleanup: true
    on:
      tags: true
