<commit_before>version: 2
jobs:
  build:
    docker:
      - image: devdemisto/content-build:3.0.0.3368  # disable-secrets-detection
    resource_class: medium+
    parallelism: 2
    environment:
      CONTENT_VERSION: "19.12.1"
      SERVER_VERSION: "5.0.0"
      GIT_SHA1: "16e3aa92e52bcc0771eaced661f6f077431dddd2" # guardrails-disable-line disable-secrets-detection
    steps:
      - checkout
      - setup_remote_docker
      - restore_cache:
          key: venv-{{ checksum "dev-requirements-py2.txt" }}-{{ checksum "dev-requirements-py3.txt" }}-{{ checksum ".circleci/build-requirements.txt" }}
      - run:
          name: Prepare Environment
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] && [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - instance tests tasks are running only in container number 0"
                exit 0
            fi

            echo 'export CIRCLE_ARTIFACTS="/home/circleci/project/artifacts"' >> $BASH_ENV
            echo 'export PATH="/home/circleci/.local/bin:${PATH}"' >> $BASH_ENV # disable-secrets-detection
            echo 'export PYTHONPATH="/home/circleci/project:${PYTHONPATH}"' >> $BASH_ENV
            echo "=== sourcing $BASH_ENV ==="
            source $BASH_ENV
            sudo mkdir -p -m 777 $CIRCLE_ARTIFACTS
            chmod +x ./Tests/scripts/*
            chmod +x ./Tests/lastest_server_build_scripts/*
            echo "Parameters: NIGHTLY: $NIGHTLY, NON_AMI_RUN: $NON_AMI_RUN, SERVER_BRANCH_NAME: $SERVER_BRANCH_NAME, INSTANCE_TESTS: $INSTANCE_TESTS"
            if [ ! -e "venv" ]; then
              echo "installing venv"
              NO_HOOKS=1 .hooks/bootstrap
              source ./venv/bin/activate
              pip install -r .circleci/build-requirements.txt
              pip3 install -r .circleci/build-requirements.txt
            else
              echo "venv exists (from cache). activating"
              source ./venv/bin/activate
            fi
            # store in bash env so we load our venv in each step
            echo 'source /home/circleci/project/venv/bin/activate' >> $BASH_ENV
            python --version
            python3 --version
      - save_cache:
          paths:
            - venv
          key: venv-{{ checksum "dev-requirements-py2.txt" }}-{{ checksum "dev-requirements-py3.txt" }}-{{ checksum ".circleci/build-requirements.txt" }}

      - add_ssh_keys:
          fingerprints:
              - "02:df:a5:6a:53:9a:f5:5d:bd:a6:fc:b2:db:9b:c9:47" # disable-secrets-detection
              - "f5:25:6a:e5:ac:4b:84:fb:60:54:14:82:f1:e9:6c:f9" # disable-secrets-detection
      - run:
          name: Create ID Set
          when: always
          command: |
            if [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - running only in container number 0"
                exit 0
            fi
            python ./Tests/scripts/update_id_set.py -r
      - run:
          name: Infrastructure testing
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - not running in INSTANCE_TESTS build or unit-tests container"
                exit 0
            fi

            python -m pytest ./Tests/scripts/hook_validations/tests/ -v
            # after moving to all to python3, run the tests by folder
            # python -m pytest ./Tests/scripts/infrastructure_tests/ -v

            python3 -m pytest ./Tests/scripts/infrastructure_tests/constants_regex_test.py -v
            python -m pytest ./Tests/scripts/infrastructure_tests/mock_unit_test.py -v
            python3 -m pytest ./Tests/scripts/infrastructure_tests/release_notes_test.py -v
            python -m pytest ./Tests/scripts/infrastructure_tests/validate_files_test.py -v

            python -m pytest ./Tests/scripts/test_configure_tests.py -v
      - run:
          name: Validate Files and Yaml
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - not running in INSTANCE_TESTS build or unit-tests container"
                exit 0
            fi

            # Run flake8 on all excluding Integraions and Scripts (they will be handled in linting)
            ./Tests/scripts/pyflake.sh *.py
            find . -maxdepth 1 -type d -not \( -path . -o -path ./Integrations -o -path ./Scripts -o -path ./Beta_Integrations -o -path ./venv \) | xargs ./Tests/scripts/pyflake.sh

            [ -n "${BACKWARD_COMPATIBILITY}" ] && CHECK_BACKWARD="false" || CHECK_BACKWARD="true"

            if [ "${CHECK_BACKWARD}" = "true" ] ;
              then
                 demisto-sdk validate -g -c -b

              else
                 demisto-sdk validate -g -c
            fi
      - run:
          name: Secrets
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - not running in INSTANCE_TESTS build or unit-tests container"
                exit 0
            fi

            demisto-sdk secrets -c
      - run:
          name: Configure Test Filter
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then<commit_msg>fix flag when calling the validate hook<commit_after>version: 2
jobs:
  build:
    docker:
      - image: devdemisto/content-build:3.0.0.3368  # disable-secrets-detection
    resource_class: medium+
    parallelism: 2
    environment:
      CONTENT_VERSION: "19.12.1"
      SERVER_VERSION: "5.0.0"
      GIT_SHA1: "16e3aa92e52bcc0771eaced661f6f077431dddd2" # guardrails-disable-line disable-secrets-detection
    steps:
      - checkout
      - setup_remote_docker
      - restore_cache:
          key: venv-{{ checksum "dev-requirements-py2.txt" }}-{{ checksum "dev-requirements-py3.txt" }}-{{ checksum ".circleci/build-requirements.txt" }}
      - run:
          name: Prepare Environment
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] && [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - instance tests tasks are running only in container number 0"
                exit 0
            fi

            echo 'export CIRCLE_ARTIFACTS="/home/circleci/project/artifacts"' >> $BASH_ENV
            echo 'export PATH="/home/circleci/.local/bin:${PATH}"' >> $BASH_ENV # disable-secrets-detection
            echo 'export PYTHONPATH="/home/circleci/project:${PYTHONPATH}"' >> $BASH_ENV
            echo "=== sourcing $BASH_ENV ==="
            source $BASH_ENV
            sudo mkdir -p -m 777 $CIRCLE_ARTIFACTS
            chmod +x ./Tests/scripts/*
            chmod +x ./Tests/lastest_server_build_scripts/*
            echo "Parameters: NIGHTLY: $NIGHTLY, NON_AMI_RUN: $NON_AMI_RUN, SERVER_BRANCH_NAME: $SERVER_BRANCH_NAME, INSTANCE_TESTS: $INSTANCE_TESTS"
            if [ ! -e "venv" ]; then
              echo "installing venv"
              NO_HOOKS=1 .hooks/bootstrap
              source ./venv/bin/activate
              pip install -r .circleci/build-requirements.txt
              pip3 install -r .circleci/build-requirements.txt
            else
              echo "venv exists (from cache). activating"
              source ./venv/bin/activate
            fi
            # store in bash env so we load our venv in each step
            echo 'source /home/circleci/project/venv/bin/activate' >> $BASH_ENV
            python --version
            python3 --version
      - save_cache:
          paths:
            - venv
          key: venv-{{ checksum "dev-requirements-py2.txt" }}-{{ checksum "dev-requirements-py3.txt" }}-{{ checksum ".circleci/build-requirements.txt" }}

      - add_ssh_keys:
          fingerprints:
              - "02:df:a5:6a:53:9a:f5:5d:bd:a6:fc:b2:db:9b:c9:47" # disable-secrets-detection
              - "f5:25:6a:e5:ac:4b:84:fb:60:54:14:82:f1:e9:6c:f9" # disable-secrets-detection
      - run:
          name: Create ID Set
          when: always
          command: |
            if [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - running only in container number 0"
                exit 0
            fi
            python ./Tests/scripts/update_id_set.py -r
      - run:
          name: Infrastructure testing
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - not running in INSTANCE_TESTS build or unit-tests container"
                exit 0
            fi

            python -m pytest ./Tests/scripts/hook_validations/tests/ -v
            # after moving to all to python3, run the tests by folder
            # python -m pytest ./Tests/scripts/infrastructure_tests/ -v

            python3 -m pytest ./Tests/scripts/infrastructure_tests/constants_regex_test.py -v
            python -m pytest ./Tests/scripts/infrastructure_tests/mock_unit_test.py -v
            python3 -m pytest ./Tests/scripts/infrastructure_tests/release_notes_test.py -v
            python -m pytest ./Tests/scripts/infrastructure_tests/validate_files_test.py -v

            python -m pytest ./Tests/scripts/test_configure_tests.py -v
      - run:
          name: Validate Files and Yaml
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - not running in INSTANCE_TESTS build or unit-tests container"
                exit 0
            fi

            # Run flake8 on all excluding Integraions and Scripts (they will be handled in linting)
            ./Tests/scripts/pyflake.sh *.py
            find . -maxdepth 1 -type d -not \( -path . -o -path ./Integrations -o -path ./Scripts -o -path ./Beta_Integrations -o -path ./venv \) | xargs ./Tests/scripts/pyflake.sh

            [ -n "${BACKWARD_COMPATIBILITY}" ] && CHECK_BACKWARD="false" || CHECK_BACKWARD="true"

            if [ "${CHECK_BACKWARD}" = "true" ] ;
              then
                 demisto-sdk validate -g --post-commit -b

              else
                 demisto-sdk validate -g --post-commit
            fi
      - run:
          name: Secrets
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
                echo "Skipping - not running in INSTANCE_TESTS build or unit-tests container"
                exit 0
            fi

            demisto-sdk secrets -c
      - run:
          name: Configure Test Filter
          when: always
          command: |
            if [ -n "${INSTANCE_TESTS}" ] || [ $CIRCLE_NODE_INDEX -ne 0 ] ;
              then
{'fraction_non_alphanumeric': 0.10522456461961503, 'fraction_numerical': 0.018881759853345555, 'mean_word_length': 1.6736094094584661, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6676809', 'n_tokens_mistral': 3459, 'n_tokens_neox': 3304, 'n_words': 799}