version: 2.1

jobs:
  run-static-analyses:
    parameters:
      version:
        type: string
    working_directory: /home/circleci/app
    docker:
      - image: circleci/golang:<< parameters.version >>
        environment:
          GO111MODULE: "on"
    steps:
      - checkout
      - restore_cache:
          keys:
            - golang-<< parameters.version >>-{{ checksum "go.sum" }}
      - run: make ci-install-go-tools
      - save_cache:
          key: golang-<< parameters.version >>-{{ checksum "go.sum" }}
          paths:
            - "/go/pkg/mod"
      - run:
          name: run static analysis
          command: make ci-static-analysis

  run-tests:
    parameters:
      version:
        type: string
    working_directory: /home/circleci/app
    docker:
      - image: circleci/golang:<< parameters.version >>
        environment:
          GO111MODULE: "on"
    steps:
      - checkout
      - restore_cache:
          keys:
            - golang-<< parameters.version >>-{{ checksum "go.sum" }}
      - run: make ci-install-go-tools
      - save_cache:
          key: golang-<< parameters.version >>-{{ checksum "go.sum" }}
          paths:
            - "/go/pkg/mod"
      - run:
          name: run unit tests
          command: make ci-unit-test


workflows:
  commit:
    jobs:
      - run-static-analyses:
          version: "1.15"
      - run-tests:
          version: "1.14"
      - run-tests:
          version: "1.15"
