sudo: required
language: go
go:
  - 1.9

notifications:
  email: false

services:
  - docker

addons:
  apt:
    packages:
     - mingw-w64
     - gcc-aarch64-linux-gnu
     - g++-aarch64-linux-gnu
     - gcc-arm-linux-gnueabihf
     - g++-arm-linux-gnueabihf

env:
  - DEP_VERSION="0.4.1"

before_install:
  - curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep
  - chmod +x $GOPATH/bin/dep
  - make download-tools

install:
  - dep ensure -v
  - (cd ui && npm install)

script:
# packr builds a go file for all packr "boxes", this would be f.ex. the spec.json file.
  - make build-js
  - packr
  - 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="-X main.Version=${VERSION} -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod";
      go build -ldflags="$LD_FLAGS" -o build/gotify-linux-amd64;
      CC=x86_64-w64-mingw32-gcc  CXX=x86_64-w64-mingw32-g++  CGO_ENABLED=1 GOOS=windows GOARCH=amd64       go build -ldflags="$LD_FLAGS" -o build/gotify-windows-amd64.exe;
      CC=aarch64-linux-gnu-gcc   CXX=aarch64-linux-gnu-g++   CGO_ENABLED=1 GOOS=linux   GOARCH=arm64       go build -ldflags="$LD_FLAGS" -o build/gotify-linux-arm64;
      CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ CGO_ENABLED=1 GOOS=linux   GOARCH=arm GOARM=7 go build -ldflags="$LD_FLAGS" -o build/gotify-linux-arm-7;
      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