<commit_before>version: 2.1

commands:
  init-tests:
    description: "Setup dokku for testing"
    steps:
      - checkout
      - attach_workspace:
          at: /home/circleci/project
      - run:
          name: resolve dokku.me
          command: |
            # dokku.me now resolves to 10.0.0.2. add 10.0.0.2/24 to ens4
            # this is maybe eth0 on github
            ifconfig
            sudo ip addr add 10.0.0.2/24 broadcast 10.0.0.255 dev ens4
      - run:
          name:  install ci-dependencies
          command: make ci-dependencies
      - run:
          name:  setup tests
          command: ./tests/ci/setup.sh
      - run:
          name:  dokku cleanup:skip
          command: echo 'export DOKKU_SKIP_CLEANUP=true' | sudo tee /home/dokku/.dokkurc/dokku_skip_cleanup
      - run:
          name:  dokku report
          command: dokku report

executors:
  default:
    machine:
      image: ubuntu-1604:201903-01
    working_directory: /home/circleci/project

jobs:
  build:
    executor: default
    steps:
      - checkout
      - run:
          name: build package
          command: ./tests/ci/setup.sh build
      - persist_to_workspace:
          root: /home/circleci/project
          paths:
            - build
  docker-deploy-tests:
    executor: default
    steps:
      - init-tests
      - run:
          name: test docker deploys
          shell: /bin/bash
          no_output_timeout: 20
          command: |
            ./tests/ci/setup.sh docker
            DOKKU_SSH_PORT=3022 sudo -E make -e test-ci-docker
  go-tests:
    executor: default
    parameters:
      index:
        type: integer
    steps:
      - init-tests
      - run:
          name: run pre-tests
          command: |
            case << parameters.index >> in
              0) sudo -E make -e lint-ci go-tests ci-go-coverage ;;
              1) sudo -E make -e deploy-test-checks-root deploy-test-config ;;
              2) sudo -E make -e deploy-test-multi ;;
              3) sudo -E make -e deploy-test-go-fail-predeploy deploy-test-go-fail-postdeploy ;;
            esac
      - store_artifacts:
          path: ./coverage.out
  test:
    executor: default
    parameters:
      index:
        type: string
    steps:
      - init-tests
      - run:
          shell: /bin/bash
          command: |
            mkdir -p test-results/bats
            cd tests/unit
            echo "executing tests: $(ls << parameters.index >>*.bats | xargs)"
            sudo -E bats --formatter bats-format-junit -e -T -o ../../test-results/bats $(ls << parameters.index >>*.bats | xargs)
          no_output_timeout: 60m
      - store_artifacts:
          path: ./test-results
          destination: test-results
      - store_test_results:
          path: test-results

workflows:
  workflow:
    jobs:
      - build
      - docker-deploy-tests:
          requires:
            - build
            - test
      - go-tests:
          matrix:
            parameters:
              index: [0, 1, 2, 3]
          requires:
            - build
            - test
      - test:
          matrix:
            parameters:
              index:
                - app-json
                - apps
                - build-env
                - buildpacks
                - certs
                - checks
                - client
                - config-oddities
                - config
                - core_1
                - core_2
                - docker-options
                - domains
                - events
                - git
                - init
                - network
                - nginx-vhosts_1
                - nginx-vhosts_2
                - nginx-vhosts_3
                - plugin
                - proxy
                - ps-dockerfile
                - ps-general
                - ps-herokuish
                - repo
                - report
                - resource
                - scheduler-docker-local
                - ssh_keys
                - storage
                - tags
                - tar
                - trace
                - version
          requires:
            - build<commit_msg>chore: group tests and adjust parallelism<commit_after>version: 2.1

commands:
  init-tests:
    description: "Setup dokku for testing"
    steps:
      - checkout
      - attach_workspace:
          at: /home/circleci/project
      - run:
          name: resolve dokku.me
          command: |
            # dokku.me now resolves to 10.0.0.2. add 10.0.0.2/24 to ens4
            # this is maybe eth0 on github
            ifconfig
            sudo ip addr add 10.0.0.2/24 broadcast 10.0.0.255 dev ens4
      - run:
          name:  install ci-dependencies
          command: make ci-dependencies
      - run:
          name:  setup tests
          command: ./tests/ci/setup.sh
      - run:
          name:  dokku cleanup:skip
          command: echo 'export DOKKU_SKIP_CLEANUP=true' | sudo tee /home/dokku/.dokkurc/dokku_skip_cleanup
      - run:
          name:  dokku report
          command: dokku report
  run-bats:
    description: "Run bats tests"
    parameters:
      index:
        type: string
    steps:
      - run:
          shell: /bin/bash
          command: |
            mkdir -p test-results/bats
            cd tests/unit
            echo "executing tests: $(ls << parameters.index >>*.bats | xargs)"
            sudo -E bats --formatter bats-format-junit -e -T -o ../../test-results/bats $(ls << parameters.index >>*.bats | xargs)
          no_output_timeout: 60m
      - store_artifacts:
          path: ./test-results
          destination: test-results
      - store_test_results:
          path: test-results


executors:
  default:
    machine:
      image: ubuntu-1604:201903-01
    working_directory: /home/circleci/project

jobs:
  build:
    executor: default
    steps:
      - checkout
      - run:
          name: build package
          command: ./tests/ci/setup.sh build
      - persist_to_workspace:
          root: /home/circleci/project
          paths:
            - build
  docker-deploy-tests:
    executor: default
    steps:
      - init-tests
      - run:
          name: test docker deploys
          shell: /bin/bash
          no_output_timeout: 20
          command: |
            ./tests/ci/setup.sh docker
            DOKKU_SSH_PORT=3022 sudo -E make -e test-ci-docker
  go-tests:
    executor: default
    parameters:
      index:
        type: integer
    steps:
      - init-tests
      - run:
          name: run pre-tests
          command: |
            case << parameters.index >> in
              0) sudo -E make -e lint-ci go-tests ci-go-coverage ;;
              1) sudo -E make -e deploy-test-checks-root deploy-test-config ;;
              2) sudo -E make -e deploy-test-multi ;;
              3) sudo -E make -e deploy-test-go-fail-predeploy deploy-test-go-fail-postdeploy ;;
            esac
      - store_artifacts:
          path: ./coverage.out
  quick-test:
    executor: default
    parameters:
      index:
        type: string
    steps:
      - init-tests
      - run-bats:
          index: << parameters.index >>
  medium-test:
    executor: default
    parallelism: 1
    parameters:
      index:
        type: string
    steps:
      - init-tests
      - run-bats:
          index: << parameters.index >>
  slow-test:
    executor: default
    parallelism: 1
    parameters:
      index:
        type: string
    steps:
      - init-tests
      - run-bats:
          index: << parameters.index >>

workflows:
  workflow:
    jobs:
      - build
      - docker-deploy-tests:
          requires:
            - build
            - quick-test
            - medium-test
            - slow-test
      - go-tests:
          matrix:
            parameters:
              index: [0, 1, 2, 3]
          requires:
            - build
            - quick-test
            - medium-test
            - slow-test
      - quick-test:
          matrix:
            parameters:
              index:
                - app-json
                - buildpacks
                - certs
                - config
                - config-oddities
                - docker-options
                - domains
                - events
                - init
                - nginx-vhosts_3
                - plugin
                - proxy
                - ps-general
                - report
                - scheduler-docker-local
                - ssh_keys
                - storage
                - tar
                - trace
                - version
          requires:
            - build
      - medium-test:
          matrix:
            parameters:
              index:
                - build-env
                - checks
                - client
                - core_2
                - network
                - nginx-vhosts_1
                - ps-herokuish
                - repo
                - tags
          requires:
            - build
      - slow-test:
          matrix:
            parameters:
              index:
                - apps
                - core_1
                - git
                - nginx-vhosts_2
                - ps-dockerfile
                - resource
          requires:
            - build
{'fraction_non_alphanumeric': 0.08550065019505852, 'fraction_numerical': 0.014087559601213698, 'mean_word_length': 1.0449811655218257, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2599757', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2544, 'n_words': 621}