version: 2
jobs:
  build:
    working_directory: /go/src/github.com/go-tamate/tamate-mysql
    docker:
      - image: circleci/golang:1.12
        environment:
          - GO111MODULE: "on"
          - REVIEWDOG_VERSION: 0.9.8
      - image: circleci/mysql:5.7
        environment:
          - MYSQL_ROOT_PASSWORD: example
    steps:
      - checkout
      - restore_cache:
          key: gomod-{{ .Branch }}-{{ checksum "go.mod" }}
      - run:
          command: go mod download
      - save_cache:
          key: gomod-{{ .Branch }}-{{ checksum "go.mod" }}
          paths:
            - /go/pkg/mod/cache
      - run:
          name: Install linters
          command: |
            curl -fSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 -o ./reviewdog && chmod +x ./reviewdog
            go get github.com/mgechev/revive
            go get honnef.co/go/tools/cmd/megacheck
            go get github.com/kisielk/errcheck
      - run: ./reviewdog -ci="circle-ci" -conf=.reviewdog.yml
      - run:
          name: Wait for db
          command: dockerize -wait tcp://localhost:3306 -timeout 1m
      - run: go test -v -race ./...
