<commit_before>version: 2.1

references:
  common_envs: &COMMON_ENVS
    GOMAXPROCS: 1
    NOMAD_SLOW_TEST: 1
    GOTESTSUM_JUNITFILE: /tmp/test-reports/results.xml
  ignore_for_ui_branches: &IGNORE_FOR_UI_BRANCHES
    filters:
      branches:
        ignore: /^.-ui\b.*/


workflows:
  build-test:
    jobs:
      - lint-go:
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-client"
          test_packages: "./client/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-nomad"
          test_packages: "./nomad/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          # API Tests run in a VM rather than container due to the FS tests
          # requiring `mount` priviliges.
          name: "test-api"
          test_packages: "./api/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-container:
          name: "test-devices"
          test_packages: "./devices/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-other"
          exclude_packages: "./api|./client|./drivers/docker|./drivers/exec|./drivers/rkt|./drivers/shared/executor|./nomad|./devices"
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-docker"
          test_packages: "./drivers/docker"
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-exec"
          test_packages: "./drivers/exec"
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-shared-exec"
          test_packages: "./drivers/shared/executor"
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-rkt:
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-ui
      # - build-deps-image:
      #     context: dani-test
      #     filters:
      #       branches:
      #         only: dani/circleci

  website:
    jobs:
      - build-website:
          context: static-sites
          filters:
            branches:
              only: stable-website
executors:
  go:
    working_directory: /go/src/github.com/hashicorp/nomad
    docker:
      - image: circleci/golang:1.12.9
  go-machine:
    working_directory: ~/go/src/github.com/hashicorp/nomad
    machine:
      image: circleci/classic:201808-01
  docker-builder:
    working_directory: ~/go/src/github.com/hashicorp/nomad
    machine: true # TODO: Find latest docker image id

  # uses a more recent image with unattended upgrades disabled properly
  # but seems to break docker builds
  go-machine-recent:
    working_directory: ~/go/src/github.com/hashicorp/nomad
    machine:
      image: ubuntu-1604:201903-01

jobs:
  build-deps-image:
    executor: docker-builder
    steps:
      - checkout
      - run: docker build -t hashicorpnomad/ci-build-image:$CIRCLE_SHA1 . -f ./Dockerfile.ci
      - run: docker push hashicorpnomad/ci-build-image:$CIRCLE_SHA1

  lint-go:
    executor: go
    environment:
      <<: *COMMON_ENVS
      GOPATH: /go
    steps:
      - checkout
      - install-protoc
      - run: make deps lint-deps
      - run: make check

  test-container:
    executor: go
    parameters:
      test_packages:
        type: string
        default: ""
      exclude_packages:
        type: string
        default: ""
    environment:
      <<: *COMMON_ENVS
      GOTEST_PKGS: "<< parameters.test_packages >>"
      GOTEST_PKGS_EXCLUDE: "<< parameters.exclude_packages >>"
      GOPATH: /go
    steps:
      - checkout
      - run: make deps
      - install-protoc
      - install-consul
      - install-vault
      - run-tests
      - store_test_results:
          path: /tmp/test-reports
      - store_artifacts:
          path: /tmp/test-reports

  test-rkt:
    executor: go-machine-recent
    environment:
      <<: *COMMON_ENVS
      GOTEST_PKGS: "./drivers/rkt"
      GOPATH: /home/circleci/go
      RKT_VERSION: 1.29.0
    steps:
      - checkout
      - install-golang
      - install-protoc
      - run:
          name: install rkt
          command: |
            gpg --recv-key 18AD5014C99EF7E3BA5F6CE950BDD3E0FC8A365E
            wget https://github.com/rkt/rkt/releases/download/v$RKT_VERSION/rkt_$RKT_VERSION-1_amd64.deb
            wget https://github.com/rkt/rkt/releases/download/v$RKT_VERSION/rkt_$RKT_VERSION-1_amd64.deb.asc
            gpg --verify rkt_$RKT_VERSION-1_amd64.deb.asc
            sudo dpkg -i rkt_$RKT_VERSION-1_amd64.deb
      - run: PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" make bootstrap
      - run-tests
      - store_test_results:
          path: /tmp/test-reports
      - store_artifacts:
          path: /tmp/test-reports

  test-machine:
    executor: go-machine
    parameters:
      test_packages:
        type: string
        default: ""
      exclude_packages:
        type: string
        default: ""
    environment:
      <<: *COMMON_ENVS
      GOTEST_PKGS_EXCLUDE: "<< parameters.exclude_packages >>"
      GOTEST_PKGS: "<< parameters.test_packages >>"
      GOPATH: /home/circleci/go
    steps:
      - checkout
      - install-golang<commit_msg>upgrade machine image for most jobs<commit_after>version: 2.1

references:
  common_envs: &COMMON_ENVS
    GOMAXPROCS: 1
    NOMAD_SLOW_TEST: 1
    GOTESTSUM_JUNITFILE: /tmp/test-reports/results.xml
  ignore_for_ui_branches: &IGNORE_FOR_UI_BRANCHES
    filters:
      branches:
        ignore: /^.-ui\b.*/


workflows:
  build-test:
    jobs:
      - lint-go:
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-client"
          test_packages: "./client/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-nomad"
          test_packages: "./nomad/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          # API Tests run in a VM rather than container due to the FS tests
          # requiring `mount` priviliges.
          name: "test-api"
          test_packages: "./api/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-container:
          name: "test-devices"
          test_packages: "./devices/..."
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-other"
          exclude_packages: "./api|./client|./drivers/docker|./drivers/exec|./drivers/rkt|./drivers/shared/executor|./nomad|./devices"
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-docker"
          test_packages: "./drivers/docker"
          # docker is misbehaving in docker-machine-recent image
          # and we get unexpected failures
          # e.g. https://circleci.com/gh/hashicorp/nomad/3854
          executor: go-machine
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-exec"
          test_packages: "./drivers/exec"
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-machine:
          name: "test-shared-exec"
          test_packages: "./drivers/shared/executor"
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-rkt:
          <<: *IGNORE_FOR_UI_BRANCHES
      - test-ui
      # - build-deps-image:
      #     context: dani-test
      #     filters:
      #       branches:
      #         only: dani/circleci

  website:
    jobs:
      - build-website:
          context: static-sites
          filters:
            branches:
              only: stable-website
executors:
  go:
    working_directory: /go/src/github.com/hashicorp/nomad
    docker:
      - image: circleci/golang:1.12.9
  go-machine:
    working_directory: ~/go/src/github.com/hashicorp/nomad
    machine:
      image: circleci/classic:201808-01
  docker-builder:
    working_directory: ~/go/src/github.com/hashicorp/nomad
    machine: true # TODO: Find latest docker image id

  # uses a more recent image with unattended upgrades disabled properly
  # but seems to break docker builds
  go-machine-recent:
    working_directory: ~/go/src/github.com/hashicorp/nomad
    machine:
      image: ubuntu-1604:201903-01

jobs:
  build-deps-image:
    executor: docker-builder
    steps:
      - checkout
      - run: docker build -t hashicorpnomad/ci-build-image:$CIRCLE_SHA1 . -f ./Dockerfile.ci
      - run: docker push hashicorpnomad/ci-build-image:$CIRCLE_SHA1

  lint-go:
    executor: go
    environment:
      <<: *COMMON_ENVS
      GOPATH: /go
    steps:
      - checkout
      - install-protoc
      - run: make deps lint-deps
      - run: make check

  test-container:
    executor: go
    parameters:
      test_packages:
        type: string
        default: ""
      exclude_packages:
        type: string
        default: ""
    environment:
      <<: *COMMON_ENVS
      GOTEST_PKGS: "<< parameters.test_packages >>"
      GOTEST_PKGS_EXCLUDE: "<< parameters.exclude_packages >>"
      GOPATH: /go
    steps:
      - checkout
      - run: make deps
      - install-protoc
      - install-consul
      - install-vault
      - run-tests
      - store_test_results:
          path: /tmp/test-reports
      - store_artifacts:
          path: /tmp/test-reports

  test-rkt:
    executor: go-machine-recent
    environment:
      <<: *COMMON_ENVS
      GOTEST_PKGS: "./drivers/rkt"
      GOPATH: /home/circleci/go
      RKT_VERSION: 1.29.0
    steps:
      - checkout
      - install-golang
      - install-protoc
      - run:
          name: install rkt
          command: |
            gpg --recv-key 18AD5014C99EF7E3BA5F6CE950BDD3E0FC8A365E
            wget https://github.com/rkt/rkt/releases/download/v$RKT_VERSION/rkt_$RKT_VERSION-1_amd64.deb
            wget https://github.com/rkt/rkt/releases/download/v$RKT_VERSION/rkt_$RKT_VERSION-1_amd64.deb.asc
            gpg --verify rkt_$RKT_VERSION-1_amd64.deb.asc
            sudo dpkg -i rkt_$RKT_VERSION-1_amd64.deb
      - run: PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" make bootstrap
      - run-tests
      - store_test_results:
          path: /tmp/test-reports
      - store_artifacts:
          path: /tmp/test-reports

  test-machine:
    executor: "<< parameters.executor >>"
    parameters:
      test_packages:
        type: string
        default: ""
      exclude_packages:
        type: string
        default: ""
      executor:
        type: string
        default: "go-machine-recent"
    environment:
      <<: *COMMON_ENVS
      GOTEST_PKGS_EXCLUDE: "<< parameters.exclude_packages >>"
      GOTEST_PKGS: "<< parameters.test_packages >>"
      GOPATH: /home/circleci/go
    steps:
      - checkout
      - install-golang
{'fraction_non_alphanumeric': 0.11355735805330243, 'fraction_numerical': 0.013325608342989572, 'mean_word_length': 1.9215796897038082, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 21, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5789944', 'n_tokens_mistral': 3774, 'n_tokens_neox': 3513, 'n_words': 602}