# https://docs.travis-ci.com/user/reference/overview/#virtualisation-environment-vs-operating-system
sudo: false
dist: trusty

language: go
go:
  - "1.10"

# Only clone the most recent commit.
git:
  depth: 1

env:
  - DEP_VERSION="0.5.0"

before_install:
  # Dump environment variables
  - printenv
  # Download the binary to bin folder in $GOPATH
  - curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep
  # Make the binary executable
  - chmod +x $GOPATH/bin/dep

install:
  - "go get -u github.com/jteeuwen/go-bindata/..."
  - "dep ensure"

before_script:
  - "go-bindata
       -o=\"${GOPATH}/src/github.com/boramalper/magnetico/cmd/magneticow/bindata.go\"
       -prefix=\"${GOPATH}/src/github.com/boramalper/magnetico/cmd/magneticow/data/\"
       ${GOPATH}/src/github.com/boramalper/magnetico/cmd/magneticow/data/..."

script:
  # The Unit Tests
  - "go test github.com/boramalper/magnetico/cmd/magneticod/..."
  - "go test github.com/boramalper/magnetico/cmd/magneticow/..."
  - "go test github.com/boramalper/magnetico/pkg/persistence/..."

  # Static Analysis (vet)
  - "go vet github.com/boramalper/magnetico/cmd/magneticod/..."
  - "go vet github.com/boramalper/magnetico/cmd/magneticow/..."
  - "go vet github.com/boramalper/magnetico/pkg/persistence/..."

  # Formatting Errors
  #
  # Since gofmt returns zero even if there are files to be formatted, we use:
  #
  #   ! gofmt -d ${GOPATH}/path/ 2>&1 | read
  #
  # to return 1 if there are files to be formatted, and 0 if not.
  #
  # https://groups.google.com/forum/#!topic/Golang-Nuts/pdrN4zleUio
  - "! gofmt -l ${GOPATH}/src/github.com/boramalper/magnetico/cmd/magneticod/ 2>&1 | read"
  - "! gofmt -l ${GOPATH}/src/github.com/boramalper/magnetico/cmd/magneticow/ 2>&1 | read"
  - "! gofmt -l ${GOPATH}/src/github.com/boramalper/magnetico/pkg/persistence/ 2>&1 | read"
