Skip to content

Commit

Permalink
Merge branch 'contrib/SEKOIA-IO_Add/SekoiaXDR' into Add/SekoiaXDR
Browse files Browse the repository at this point in the history
  • Loading branch information
TOUFIKIzakarya authored Jun 11, 2024
2 parents 300d50b + 8752de5 commit 0aeb5f8
Show file tree
Hide file tree
Showing 1,362 changed files with 60,059 additions and 12,720 deletions.
14 changes: 14 additions & 0 deletions .circleci/add_pr_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from demisto_sdk.commands.test_content.execute_test_content import _add_pr_comment
from demisto_sdk.commands.test_content.execute_test_content import ParallelLoggingManager


JOB_ID = os.environ.get("CIRCLE_WORKFLOW_JOB_ID")
COVERAGE_LINK = f'https://output.circle-artifacts.com/output/job/{JOB_ID}/artifacts/0/artifacts/coverage_report/html/' \
f'index.html'
COVERAGE_REPORT_COMMENT = f'Link to the unit tests coverage report: \n {COVERAGE_LINK}'


if __name__ == "__main__":
logging_manager = ParallelLoggingManager('UT_coverage_report.log')
_add_pr_comment(COVERAGE_REPORT_COMMENT, logging_manager)
19 changes: 19 additions & 0 deletions .circleci/analyze_non_packs_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash


# Run flake8 pylint and mypy on all non-Packs. Packs are handled in pre-commit.
errors=0
all_dirs=$(find . -type d -not \( -path "*cache*" -o -path "./.*" -o -path "./Templates*" -o -path "./TestPlaybooks*" -o -path "./node_modules*" -o -path "./venv*" -o -path "./Packs*" -o -path "./artifacts*" -o -path "*infrastructure_tests*" -o -path "*scripts/awsinstancetool*" -o -path "./docs*" \))
all_1_depth_dirs=$(find . -maxdepth 1 -type d -not \( -path "*cache*" -o -path . -o -path ./Packs -o -path ./venv -o -path ./Templates -o -path ./TestPlaybooks -o -path ./node_modules -o -path "./artifacts*" -o -path "./.*" -o -path ./docs \))

echo -e "Top level folders to scan (used by ruff):\n${all_1_depth_dirs}\n"
echo -e "Folders to be used for lint scan (used by pylint and mypy):\n${all_dirs}\n"

./.circleci/mypy.sh $all_1_depth_dirs || errors=$?
python3 -m ruff $all_1_depth_dirs --select=E,F,PLC,PLE --ignore=PLC1901 || errors=$?


echo 'analyze non-packs files exit code:' $errors
if [[ $errors -ne 0 ]]; then
exit 1
fi
67 changes: 67 additions & 0 deletions .circleci/circleci_spell_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import re
import sys

from spell_checker import spell_checker
from demisto_sdk.commands.common.tools import run_command, find_type
from demisto_sdk.commands.common.constants import DESCRIPTION_REGEX, FileType


IGNORED_FILES = ['.devcontainer/devcontainer.json', '.vscode/extensions.json']


def get_modified_files(files_string):
"""Get lists of the modified files in your branch according to the files string.
Args:
files_string (string): String that was calculated by git using `git diff` command.
Returns:
(yml_files, md_files). Tuple of sets.
"""
all_files = files_string.split('\n')
yml_files = set([])
md_files = set([])
for f in all_files:
file_data = f.split()
if not file_data:
continue

file_status = file_data[0]
file_path = file_data[1]
if file_path in IGNORED_FILES:
continue
if file_path.endswith('.js') or file_path.endswith('.py'):
continue
if file_status.lower().startswith('r'):
file_path = file_data[2]

if file_status.lower() == 'm' or file_status.lower() == 'a' or file_status.lower().startswith('r'):
if find_type(file_path) in [FileType.INTEGRATION, FileType.BETA_INTEGRATION, FileType.SCRIPT,
FileType.PLAYBOOK]:
yml_files.add(file_path)
elif re.match(DESCRIPTION_REGEX, file_path, re.IGNORECASE):
md_files.add(file_path)

return yml_files, md_files


def check_changed_files():
branch_name = sys.argv[1]

if branch_name != "master":
all_changed_files_string = run_command("git diff --name-status origin/master...{}".format(branch_name))
yml_files, md_files = get_modified_files(all_changed_files_string)
for yml_file in yml_files:
print("Checking the file - {}".format(yml_file))
spell_checker(yml_file)

for md_file in md_files:
print("Checking the file - {}".format(md_file))
spell_checker(md_file, is_md=True)

else:
print("Not checking for spelling errors in master branch")


if __name__ == "__main__":
check_changed_files()
64 changes: 64 additions & 0 deletions .circleci/comment_on_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
import argparse
import os
import sys

import requests


def main():
parser = argparse.ArgumentParser(description='Add a comment to a pull request in the repo.')
parser.add_argument('-p', '--pr_number', help='Pull request number')
parser.add_argument('-c', '--comment', help='The comment to add')
args = parser.parse_args()

pr_number = args.pr_number
comment = args.comment
token = os.environ['CONTENT_GITHUB_TOKEN']

comments_url = get_pr_comments_url(pr_number)

headers = {'Authorization': 'Bearer ' + token}
response = requests.post(comments_url, json={'body': comment}, headers=headers)
response.raise_for_status()

print('Successfully added the comment to the PR.')


def get_pr_comments_url(pr_number: str) -> str:
"""
Get the comments URL for a PR. If the PR contains a comment about an instance test (for contrib PRs),
it will use that comment.
Args:
pr_number: The pull request number
Returns:
The comments URL for the PR.
"""
pr_url = f'https://api.github.com/repos/demisto/content/pulls/{pr_number}'
response = requests.get(pr_url)
response.raise_for_status()
pr = response.json()
if not pr:
print('Could not find the pull request to reply on.')
sys.exit(1)
page = 1
comments_url = pr['comments_url']
while True:
response = requests.get(comments_url, params={'page': str(page)})
response.raise_for_status()
comments = response.json()
if not comments:
break

link_comments = [comment for comment in comments if 'Instance is ready.' in comment.get('body', '')]
if link_comments:
comments_url = link_comments[0]['url']
break
page += 1

return comments_url


if __name__ == '__main__':
main()
125 changes: 25 additions & 100 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,66 +224,26 @@ references:
# poll for neo4j status until available
while ! curl --fail http://127.0.0.1:7474 &> /dev/null; do sleep 1; done
./Tests/scripts/linters_runner.sh
./Tests/scripts/validate.sh
run_unit_testing_and_lint: &run_unit_testing_and_lint
run:
parameters:
dockerimageflag:
type: string
name: Run Unit Testing And Lint - Docker Image:<< parameters.dockerimageflag >>
when: always
no_output_timeout: 5h
command: |
if [[ "$(echo "$GCS_MARKET_BUCKET" | tr '[:upper:]' '[:lower:]')" != "marketplace-dist" ]]; then
echo "Skipping validations when uploading to a test bucket."
exit 0
fi
echo "demisto-sdk version: $(demisto-sdk --version)"
echo "mypy version: $(mypy --version)"
echo "flake8 py3 version: $(python3 -m flake8 --version)"
echo "bandit py3 version: $(python3 -m bandit --version 2>&1)"
echo "vulture py3 version: $(python3 -m vulture --version 2>&1)"
mkdir ./unit-tests
neo4j start
# poll for neo4j status until available
while ! curl --fail http://127.0.0.1:7474 &> /dev/null; do sleep 1; done
demisto-sdk lint -p 8 -g --test-xml ./unit-tests --log-path ./artifacts --failure-report ./artifacts --coverage-report $ARTIFACTS_FOLDER/coverage_report --docker-image << parameters.dockerimageflag >> --check-dependent-api-module
generate_coverage_reports: &generate_coverage_reports
run:
name: Generate coverage reports
when: always
no_output_timeout: 1h
command: |
EXIT_CODE=0
if [[ -f $ARTIFACTS_FOLDER/coverage_report/.coverage ]]; then
demisto-sdk coverage-analyze -i $ARTIFACTS_FOLDER/coverage_report/.coverage --report-dir $ARTIFACTS_FOLDER/coverage_report --report-type all --previous-coverage-report-url https://storage.googleapis.com/marketplace-dist-dev/code-coverage-reports/coverage-min.json || EXIT_CODE=1
# Checks if the $XSOAR_BOT_TEST_CONTENT exist. for security reasons only non forked pr's have access to it.
if [[ -n $XSOAR_BOT_TEST_CONTENT && -e $ARTIFACTS_FOLDER/coverage_report/html/index.html ]]; then
echo "Adding unit tests coverage comment to the pr"
python3 ./Tests/scripts/add_pr_comment.py
fi
exit $EXIT_CODE
fi
infrastructure_testing: &infrastructure_testing
run:
name: Infrastructure testing
when: always
command: |
python3 -m pytest ./Tests/scripts/infrastructure_tests/ -v
python3 -m pytest ./Tests/Marketplace/Tests/ -v
python3 -m pytest ./Tests/tests -v
python3 -m pytest Utils -v
if [ -n "${DEMISTO_SDK_NIGHTLY}" ] ; then
./Tests/scripts/sdk_pylint_check.sh
fi
./.circleci/analyze_non_packs_files.sh
./.circleci/validate.sh
# generate_coverage_reports: &generate_coverage_reports
# run:
# name: Generate coverage reports
# when: always
# no_output_timeout: 1h
# command: |
# EXIT_CODE=0
# if [[ -f $ARTIFACTS_FOLDER/coverage_report/.coverage ]]; then
# demisto-sdk coverage-analyze -i $ARTIFACTS_FOLDER/coverage_report/.coverage --report-dir $ARTIFACTS_FOLDER/coverage_report --report-type all --previous-coverage-report-url https://storage.googleapis.com/marketplace-dist-dev/code-coverage-reports/coverage-min.json || EXIT_CODE=1
# # Checks if the $XSOAR_BOT_TEST_CONTENT exist. for security reasons only non forked pr's have access to it.
# if [[ -n $XSOAR_BOT_TEST_CONTENT && -e $ARTIFACTS_FOLDER/coverage_report/html/index.html ]]; then
# echo "Adding unit tests coverage comment to the pr"
# python3 ./.circleci/add_pr_comment.py
# fi
# exit $EXIT_CODE
# fi

get_contribution_pack: &get_contribution_pack
when:
Expand All @@ -296,7 +256,7 @@ references:
USERNAME=$(echo $CONTRIB_BRANCH | cut -d ":" -f 1)
BRANCH=$(echo $CONTRIB_BRANCH | cut -d ":" -f 2)
$CONTRIB_REPO="content"
python3 ./Utils/update_contribution_pack_in_base_branch.py -p $PULL_REQUEST_NUMBER -b $BRANCH -u $USERNAME -c $CONTRIB_REPO -gt $GITHUB_TOKEN
python3 ./.circleci/update_contribution_pack_in_base_branch.py -p $PULL_REQUEST_NUMBER -b $BRANCH -u $USERNAME -c $CONTRIB_REPO -gt $GITHUB_TOKEN
comment_on_contrib_pr: &comment_on_contrib_pr
when:
Expand All @@ -307,19 +267,11 @@ references:
when: always
command: |
SERVER_URL=$(jq -r 'select(.[].Role == "Server Master") | .[].InstanceDNS' $ENV_RESULTS_PATH)
python3 ./Utils/comment_on_pr.py -p $PULL_REQUEST_NUMBER -c "Instance is ready. Server link: https://$SERVER_URL, Build link: $CIRCLE_BUILD_URL"
python3 ./.circleci/comment_on_pr.py -p $PULL_REQUEST_NUMBER -c "Instance is ready. Server link: https://$SERVER_URL, Build link: $CIRCLE_BUILD_URL"
nightly_jobs: &nightly_jobs
- Setup Environment:
context: nightly_env
- Run Unit Testing And Lint:
context: nightly_env
requires:
- Setup Environment
matrix:
parameters:
dockerimageflag: [ "native:ga", "native:maintenance", "native:dev", "from-yml" ]
name: Run Unit Testing And Lint - Docker Image:<< matrix.dockerimageflag >>
- Run Validations:
requires:
- Setup Environment
Expand All @@ -338,26 +290,6 @@ jobs:
- *get_contribution_pack
- *persist_to_workspace

Run Unit Testing And Lint:
<<: *container_config
resource_class: large
<<: *environment
parameters:
dockerimageflag:
type: string
steps:
- *attach_workspace
- *remote_docker
- *install_build_dependencies
- *install_node_ci
- *install_neo4j
- *prepare_environment
- *infrastructure_testing
- *run_unit_testing_and_lint
- *generate_coverage_reports
- store_test_results:
path: ./unit-tests
- *store_artifacts

Run Validations:
<<: *container_config
Expand All @@ -374,14 +306,14 @@ jobs:
- run:
name: Spell Checks
command: |
python3 ./Tests/scripts/circleci_spell_checker.py $CIRCLE_BRANCH
python3 ./.circleci/circleci_spell_checker.py $CIRCLE_BRANCH
- run:
name: Verify Base Branch for Contribution
when: always
command: |
if [[ $CIRCLE_BRANCH =~ pull/[0-9]+ ]] ;
then
python3 ./Tests/scripts/verify_base_branch_for_contribution.py $CIRCLE_BRANCH
python3 ./.circleci/verify_base_branch_for_contribution.py $CIRCLE_BRANCH
fi
- run:
name: Validate landingPageSections.json
Expand All @@ -395,7 +327,7 @@ jobs:
UNZIP_PATH=$(mktemp -d)
unzip $INDEX_PATH -d $UNZIP_PATH
python3 Tests/Marketplace/validate_landing_page_sections.py -i $UNZIP_PATH
python3 ./.circleci/validate_landing_page_sections.py -i $UNZIP_PATH
- *store_artifacts
- store_artifacts:
path: $ARTIFACTS_FOLDER
Expand All @@ -412,13 +344,6 @@ workflows:
value: << pipeline.git.branch >>
jobs:
- Setup Environment
- Run Unit Testing And Lint:
requires:
- Setup Environment
matrix:
parameters:
dockerimageflag: [ "native:ga", "native:maintenance", "native:dev", "native:candidate", "from-yml" ]
name: Run Unit Testing And Lint - Docker Image:<< matrix.dockerimageflag >>
- Run Validations:
requires:
- Setup Environment
Expand Down
26 changes: 26 additions & 0 deletions .circleci/git_pull_master_into_fork.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# this file has been deprecated and relocated to the contribution/utils directory
#Be aware, only contributors should run this script.

echo "This file has been deprecated and relocated to the contribution/utils directory"

CONTENT_URL='https://github.com/demisto/content.git'

if [ -z "$1" ]
then
CURRENT=$(git branch --show-current)
else
CURRENT=$1
fi

(
git remote add upstream_content $CONTENT_URL ||
git remote set-url upstream_content $CONTENT_URL
) &&
git fetch upstream_content &&
git checkout master &&
git rebase upstream_content/master &&
git push -f origin master &&
git checkout $CURRENT &&
git pull origin master

2 changes: 1 addition & 1 deletion .circleci/is_file_up_to_date.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [[ $(git diff origin/master -G"." -- ${FILE_TO_CHECK}) ]]; then
fi

if [[ $BRANCH =~ pull/[0-9]+ ]]; then
echo "Run ./Utils/git_pull_master_into_fork.sh or merge manually from upstream demisto content"
echo "Run ./contribution/utils/git_pull_master_into_fork.sh or merge manually from upstream demisto content"
fi

exit 1
Expand Down
Loading

0 comments on commit 0aeb5f8

Please sign in to comment.