version: 2

jobs:
  build-ut:
    docker:
      - image: golang:1.13
    working_directory: /go/src/github.com/pingcap/parser
    steps:
      - checkout
      - run:
          name: "Verify parser.go is up-to-date"
          command: |
            mv parser.go parser.go.committed
            make parser
            diff -u parser.go.committed parser.go
      - run:
          name: "Check code format"
          command: make fmt
      - run:
          name: "Build & Test"
          command: make test
      - run:
          name: "Upload coverage"
          command: bash <(curl -s https://codecov.io/bash)
  build-integration:
    docker:
    - image: golang:1.13
    working_directory: /go/src/github.com/pingcap/parser
    steps:
    - checkout
    - run:
        name: "Integration Test"
        command: |
          cd /go/src/github.com/pingcap/
          git clone git@github.com:pingcap/tidb.git
          cd tidb
          git checkout origin/release-4.0
          rm go.sum
          GO111MODULE=on go mod edit -replace github.com/pingcap/parser=github.com/${CIRCLE_PR_USERNAME:-$CIRCLE_PROJECT_USERNAME}/${CIRCLE_PR_REPONAME:-$CIRCLE_PROJECT_REPONAME}@$CIRCLE_SHA1
          # use only 1 thread to minimize memory usage (we've only got 2 CPU + 4 GB on Circle CI).
          make gotest P=1
workflows:
  version: 2
  build_and_test:
    jobs:
    - build-ut
    - build-integration
