image: golang:1.12


cache:
  paths:
    - .gopath/
    - ui/assets_vfsdata.go

before_script:
  - mkdir -p .gopath
  - export GOPATH="$CI_PROJECT_DIR/.gopath"
  - go generate ./ui


stages:
  - vet
  - test
  - build


vet:
  stage: vet
  script:
    - go vet ./...


test-all-but-store:
  stage: test
  script:
    - go test -v -cover $(go list ./... | grep -v tank/store)

test-store-mysql:
  stage: test
  services:
    - mysql:5.7
  variables:
    MYSQL_DATABASE: "tank"
    MYSQL_USER: "tank"
    MYSQL_PASSWORD: "aura"
    MYSQL_RANDOM_ROOT_PASSWORD: "yes"
    AURA_TANK_TEST_DB_TYPE: "mysql"
    AURA_TANK_TEST_DB_HOST: "mysql"
  script:
    - go test -v -cover ./store

test-store-mariadb:
  stage: test
  services:
    - mariadb:10.1
  variables:
    MYSQL_DATABASE: "tank"
    MYSQL_USER: "tank"
    MYSQL_PASSWORD: "aura"
    MYSQL_RANDOM_ROOT_PASSWORD: "yes"
    AURA_TANK_TEST_DB_TYPE: "mysql"
    AURA_TANK_TEST_DB_HOST: "mariadb"
  script:
    - go test -v -cover ./store

test-store-postgres:
  stage: test
  services:
    - postgres:9.6
  variables:
    POSTGRES_DB: "tank"
    POSTGRES_USER: "tank"
    POSTGRES_PASSWORD: "aura"
    AURA_TANK_TEST_DB_TYPE: "postgres"
    AURA_TANK_TEST_DB_HOST: "postgres"
  script:
    - go test -v -cover ./store


build:
  stage: build
  script:
    - go build -ldflags "-extldflags '-static'" -tags netgo -o $CI_PROJECT_DIR/tank ./cmd/tank
    ## sqlite needs cgo... :(
    ##- go build -o $CI_PROJECT_DIR/tank ./cmd/tank
  artifacts:
    paths:
      - tank
