# 10月28日前迁出
os: linux
dist: xenial
language: go

addons:
  hosts:
    - local.iqka.com
services:
  - docker
env:
  global:
    # GITHUB TOKEN
    # https://github.com/settings/tokens
    - CI_USER_TOKEN="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 --private -r yaoapp/gou"

    # CODECOV TOKEN
    # https://app.codecov.io/gh/YaoApp/xiang/settings
    - CODECOV_TOKEN="0e0438c9-b1fc-4bc7-816f-8cf761a3337f"

    # 象传服务配置
    - XIANG_MODE=debug
    - XIANG_SOURCE=$TRAVIS_BUILD_DIR
    - XIANG_ROOT=fs:///$TRAVIS_BUILD_DIR/app

    # 服务配置
    - XIANG_SERVICE_DEBUG=true
    - XIANG_SERVICE_ALLOW="xiang.yao.run:3000|xiang.yao.run:3001"
    - XIANG_SERVICE_HOST=0.0.0.0
    - XIANG_SERVICE_PORT=5099

    # 数据库配置
    - XIANG_DB_DEBUG=true
    - XIANG_DB_PRIMARY="root:123456@tcp(db-server:3308)/xun?charset=utf8mb4&parseTime=True&loc=Local"
    - XIANG_DB_SECONDARY="root:123456@tcp(db-server:3308)/xun?charset=utf8mb4&parseTime=True&loc=Local"
    - XIANG_DB_AESKEY="ZLX=T&f6refeCh-ro*r@"

    # JWT配置
    - XIANG_JWT_DEBUG=true
    - XIANG_JWT_SECRET="bLp@bi!oqo-2U+hoTRUG"

    # 存储配置
    - XIANG_STOR_DEBUG=true
    - XIANG_STOR_PATH="fs:///$TRAVIS_BUILD_DIR/upload"

    # 日志配置
    - XIANG_LOG_ACCESS="fs:///$TRAVIS_BUILD_DIR/logs/access.log"
    - XIANG_LOG_ERROR="fs:///$TRAVIS_BUILD_DIR/logs/error.log"
    - XIANG_LOG_DB="fs:///$TRAVIS_BUILD_DIR/logs/db.log"
    - XIANG_LOG_PLUGIN="fs:///$TRAVIS_BUILD_DIR/logs/plugin.log"

jobs:
  fast_finish: true
  include:
    - name: MySQL8.0-1.17.x
      go: 1.17.x
      env:
        - XIANG_DB_PRIMARY="root:123456@tcp(127.0.0.1:3308)/xun?charset=utf8mb4&parseTime=True&loc=Local"
        - XIANG_DB_SECONDARY="root:123456@tcp(127.0.0.1:3308)/xun?charset=utf8mb4&parseTime=True&loc=Local"
      before_install:
        - echo -e "machine github.com\n  login $CI_USER_TOKEN" > ~/.netrc
        - unit/service.sh mysql8.0 # Start MySQL 8.0 service
    - name: MySQL5.7-1.17.x
      go: 1.17.x
      env:
        - XIANG_DB_PRIMARY="root:123456@tcp(127.0.0.1:3306)/xun?charset=utf8mb4&parseTime=True&loc=Local"
        - XIANG_DB_SECONDARY="root:123456@tcp(127.0.0.1:3306)/xun?charset=utf8mb4&parseTime=True&loc=Local"
      before_install:
        - echo -e "machine github.com\n  login $CI_USER_TOKEN" > ~/.netrc
        - unit/service.sh mysql5.7 # Start MySQL 5.7 service
    - name: MySQL5.6-1.17.x
      go: 1.17.x
      env:
        - XIANG_DB_PRIMARY="root:123456@tcp(127.0.0.1:3307)/xun?charset=utf8mb4&parseTime=True&loc=Local"
        - XIANG_DB_SECONDARY="root:123456@tcp(127.0.0.1:3307)/xun?charset=utf8mb4&parseTime=True&loc=Local"
      before_install:
        - echo -e "machine github.com\n  login $CI_USER_TOKEN" > ~/.netrc
        - unit/service.sh mysql5.6 # Start MySQL 5.6 service
git:
  depth: 10
install:
  - if [[ "${GO111MODULE}" = "on" ]]; then go mod download; fi
  - if [[ "${GO111MODULE}" = "on" ]]; then export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"; fi
  - if [[ "${GO111MODULE}" = "on" ]]; then make tools; fi

go_import_path: github.com/yaoapp/gou

script:
  - export
  - cat ~/.netrc
  - make vet
  - make fmt-check
  - make misspell-check
  - make plugin
  - make migrate
  - make test

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