Skip to content

Commit

Permalink
Validate refactor phase 1 (#3718)
Browse files Browse the repository at this point in the history
* In progress

* pre-commit fixes

* In progress

* In progress

* In progress

* In progress

* In progress

* In progress

* In progress

* In progress

* In progress

* In progress

* In progress

* pre commit fixes

* Working POC

* update mappings

* pre commit fixes

* testing

* testing

* reverts

* working

* adding support for BC validations

* added BC100 validation

* added files

* working BC validation

* adding tests

* generic

* small fixes

* dynamic init

* adding tests

* adding tests

* in progress

* added GR106

* fixes

* changes

* fixes

* fix graph validation

* move passed validation dynamic

* fix

* fix typo

* fix typo

* support graph

* fix tests

* adding tests

* test fixes

* test fixes

* added classifier

* tests

* tests

* tests

* fixes

* updated infra to match the requests for the new validator

* reverts

* testing update mapping

* testing

* testing

* fix tests

* fixes

* added skip validate flags

* pre commit fixes

* test fixes

* test fixes

* test and pre-commit fixes

* test fixes

* test fixes

* types fix

* pre commit fixes

* mid save

* add packmetadata save

* remove auto fixable

* fixes in progress

* cr fixes

* renamed validate manager to old validate manager

* Dependency inversion principal addaption

* pre commit fixes

* fixes

* fixes

* pre commit fixes

* adding Graph tests

* added generate validation script

* added BA 116 validation

* in progress

* update

* merge addaptions

* add tests for GR106

* adjusments

* changes

* pre commit fixes

* working tests

* added files

* fixed ignorable_errors_loading issue

* ignore tpbs

* added DO108 validation

* fixes

* test fix

* doc updates

* added IN108 valdiation

* added IN130 validation

* revert playbook test

* push

* updates

* updates

* fixes

* updates

* pre commit fixes

* updates

* updates

* updates

* updates

* updates

* fix

* update

* updates

* updates

* fixes

* fixes

* better solution

* fixes

* fix

* Tests

* fix

* fix tests filtering

* fixes

* fix tests filtering

* test fix

* test fix

* fix fieldinfo

* fixes

* fixes

* test fixes

* test fixes

* pre commit fixes

* fixes

* test new validate workflow

* tests

* fix yuval bugs

* added test for ignored_errors

* update changelog

* revert changelog

* revert readme

* name changes

* pre commit fixes

* tests fix

---------

Co-authored-by: ilan <ierukhimovic@paloaltonetworks.com>
  • Loading branch information
YuvHayun and ilan committed Nov 21, 2023
1 parent 7acaf0f commit 4b7af85
Show file tree
Hide file tree
Showing 50 changed files with 9,035 additions and 6,467 deletions.
43 changes: 43 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ references:
requires:
- precommit-checks
- validate-files
- validate-files-new-validate
- create-content-artifacts
- test-lint
- run-integration-tests
Expand Down Expand Up @@ -324,6 +325,45 @@ jobs:
- store_artifacts:
path: /home/circleci/project/artifacts
validate-files-new-validate:
docker:
- image: << pipeline.parameters.global-docker-image >>
resource_class: large
<<: *environment
steps:
- checkout
- <<: *install_poetry
- <<: *install_neo4j
- attach_workspace:
at: ~/project
- <<: *install_build_dependencies
- node/install-packages:
cache-version: << pipeline.parameters.cache-version >>
app-dir: content
- run:
name: Test validate files and yaml - new validate
when: always
no_output_timeout: 20m
environment:
CI_COMMIT_BRANCH: "master"
command: |
source $(poetry env info --path)/bin/activate
export ARTIFACTS_FOLDER="/home/circleci/project/artifacts"
mkdir -p $ARTIFACTS_FOLDER
export DEMISTO_SDK_LOG_FILE_PATH=$ARTIFACTS_FOLDER/demisto_sdk_debug.log
cd content
demisto-sdk -v
echo $(echo '{"node_version": "'$(node --version)'","npm_list":'$(npm list --json)'}')
neo4j start
# poll for neo4j status until available
while ! curl --fail http://127.0.0.1:7474 &> /dev/null; do sleep 1; done
./Tests/scripts/new_validate.sh
- store_artifacts:
path: /home/circleci/project/artifacts



test-lint:
Expand Down Expand Up @@ -514,6 +554,9 @@ workflows:
- validate-files:
<<: *tag_filter
<<: *reqs_content_checkout
- validate-files-new-validate:
<<: *tag_filter
<<: *reqs_content_checkout
- test-lint:
<<: *reqs_content_checkout
- create-content-artifacts:
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ repos:
- types-setuptools==67.7.0.1 ; python_version >= "3.8" and python_version < "3.11"
- types-six==1.16.21.8 ; python_version >= "3.8" and python_version < "3.11"
- types-tabulate==0.9.0.2 ; python_version >= "3.8" and python_version < "3.11"
- types-toml==0.10.8.7 ; python_version >= "3.8" and python_version < "3.11"
- types-ujson==5.7.0.5 ; python_version >= "3.8" and python_version < "3.11"
- types-urllib3==1.26.25.12 ; python_version >= "3.8" and python_version < "3.11"
- typing-extensions==4.5.0 ; python_version >= "3.8" and python_version < "3.11"
Expand Down
184 changes: 134 additions & 50 deletions demisto_sdk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import click

from demisto_sdk.commands.validate.config_reader import ConfigReader
from demisto_sdk.commands.validate.initializer import Initializer
from demisto_sdk.commands.validate.validation_results import ResultWriter

try:
import git
except ImportError:
Expand Down Expand Up @@ -575,20 +579,20 @@ def zip_packs(ctx, **kwargs) -> int:
is_flag=True,
default=False,
show_default=True,
help="Skip conf.json validation.",
help="Relevant only for the old validate flow and will be removed in a future release. Skip conf.json validation.",
)
@click.option(
"-s",
"--id-set",
is_flag=True,
default=False,
show_default=True,
help="Perform validations using the id_set file.",
help="Relevant only for the old validate flow and will be removed in a future release. Perform validations using the id_set file.",
)
@click.option(
"-idp",
"--id-set-path",
help="The path of the id-set.json used for validations.",
help="Relevant only for the old validate flow and will be removed in a future release. The path of the id-set.json used for validations.",
type=click.Path(resolve_path=True),
)
@click.option(
Expand All @@ -597,7 +601,7 @@ def zip_packs(ctx, **kwargs) -> int:
is_flag=True,
default=False,
show_default=True,
help="Perform validations on content graph.",
help="Relevant only for the old validate flow and will be removed in a future release. Perform validations on content graph.",
)
@click.option(
"--prev-ver", help="Previous branch or SHA1 commit to run checks against."
Expand All @@ -606,7 +610,7 @@ def zip_packs(ctx, **kwargs) -> int:
"--no-backward-comp",
is_flag=True,
show_default=True,
help="Whether to check backward compatibility or not.",
help="Relevant only for the old validate flow and will be removed in a future release. Whether to check backward compatibility or not.",
)
@click.option(
"-g",
Expand Down Expand Up @@ -638,7 +642,7 @@ def zip_packs(ctx, **kwargs) -> int:
"-iu",
"--include-untracked",
is_flag=True,
help="Whether to include untracked files in the validation. "
help="Relevant only for the old validate flow and will be removed in a future release. Whether to include untracked files in the validation. "
"This applies only when the -g flag is supplied.",
)
@click.option(
Expand All @@ -660,74 +664,125 @@ def zip_packs(ctx, **kwargs) -> int:
@click.option(
"--skip-pack-release-notes",
is_flag=True,
help="Skip validation of pack release notes.",
help="Relevant only for the old validate flow and will be removed in a future release. Skip validation of pack release notes.",
)
@click.option(
"--print-ignored-errors", is_flag=True, help="Print ignored errors as warnings."
"--print-ignored-errors",
is_flag=True,
help="Relevant only for the old validate flow and will be removed in a future release. Print ignored errors as warnings.",
)
@click.option(
"--print-ignored-files",
is_flag=True,
help="Print which files were ignored by the command.",
help="Relevant only for the old validate flow and will be removed in a future release. Print which files were ignored by the command.",
)
@click.option(
"--no-docker-checks", is_flag=True, help="Whether to run docker image validation."
"--no-docker-checks",
is_flag=True,
help="Relevant only for the old validate flow and will be removed in a future release. Whether to run docker image validation.",
)
@click.option(
"--silence-init-prints",
is_flag=True,
help="Whether to skip the initialization prints.",
help="Relevant only for the old validate flow and will be removed in a future release. Whether to skip the initialization prints.",
)
@click.option(
"--skip-pack-dependencies",
is_flag=True,
help="Skip validation of pack dependencies.",
help="Relevant only for the old validate flow and will be removed in a future release. Skip validation of pack dependencies.",
)
@click.option(
"--create-id-set", is_flag=True, help="Whether to create the id_set.json file."
"--create-id-set",
is_flag=True,
help="Relevant only for the old validate flow and will be removed in a future release. Whether to create the id_set.json file.",
)
@click.option(
"-j",
"--json-file",
help="The JSON file path to which to output the command results.",
)
@click.option(
"--skip-schema-check", is_flag=True, help="Whether to skip the file schema check."
"--skip-schema-check",
is_flag=True,
help="Relevant only for the old validate flow and will be removed in a future release. Whether to skip the file schema check.",
)
@click.option(
"--debug-git", is_flag=True, help="Whether to print debug logs for git statuses."
"--debug-git",
is_flag=True,
help="Relevant only for the old validate flow and will be removed in a future release. Whether to print debug logs for git statuses.",
)
@click.option(
"--print-pykwalify", is_flag=True, help="Whether to print the pykwalify log errors."
"--print-pykwalify",
is_flag=True,
help="Relevant only for the old validate flow and will be removed in a future release. Whether to print the pykwalify log errors.",
)
@click.option(
"--quiet-bc-validation",
help="Set backwards compatibility validation's errors as warnings.",
help="Relevant only for the old validate flow and will be removed in a future release. Set backwards compatibility validation's errors as warnings.",
is_flag=True,
)
@click.option(
"--allow-skipped",
help="Don't fail on skipped integrations or when all test playbooks are skipped.",
help="Relevant only for the old validate flow and will be removed in a future release. Don't fail on skipped integrations or when all test playbooks are skipped.",
is_flag=True,
)
@click.option(
"--no-multiprocessing",
help="run validate all without multiprocessing, for debugging purposes.",
help="Relevant only for the old validate flow and will be removed in a future release. run validate all without multiprocessing, for debugging purposes.",
is_flag=True,
default=False,
)
@click.option(
"-sv",
"--run-specific-validations",
help="Run specific validations by stating the error codes.",
help="Relevant only for the old validate flow and will be removed in a future release. Run specific validations by stating the error codes.",
is_flag=False,
)
@click.option(
"--category-to-run",
help="Run specific validations by stating category they're listed under in the config file.",
is_flag=False,
)
@click.option(
"-f",
"--fix",
help="Wether to autofix failing validations with an available auto fix or not.",
is_flag=True,
default=False,
)
@click.option(
"--config-path",
help="Path for a config file to run, if not given - will run the default config at https://github.com/demisto/demisto-sdk/blob/master/demisto_sdk/commands/validate/default_config.toml",
is_flag=False,
)
@click.option(
"--ignore-support-level",
is_flag=True,
show_default=True,
default=False,
help="Wether to skip validations based on their support level or not.",
)
@click.option(
"--skip-old-validate",
is_flag=True,
show_default=True,
default=False,
help="Wether to skip the old validate flow.",
)
@click.option(
"--run-new-validate",
is_flag=True,
show_default=True,
default=False,
help="Wether to run the new validate flow.",
)
@click.argument("file_paths", nargs=-1, type=click.Path(exists=True, resolve_path=True))
@pass_config
@click.pass_context
@logging_setup_decorator
def validate(ctx, config, file_paths: str, **kwargs):
"""Validate your content files. If no additional flags are given, will validated only committed files."""
from demisto_sdk.commands.validate.old_validate_manager import OldValidateManager
from demisto_sdk.commands.validate.validate_manager import ValidateManager

if is_sdk_defined_working_offline():
Expand All @@ -754,36 +809,65 @@ def validate(ctx, config, file_paths: str, **kwargs):
if not kwargs.get("validate_all") and not kwargs["use_git"] and not file_path:
kwargs["use_git"] = True
kwargs["post_commit"] = True
validator = ValidateManager(
is_backward_check=not kwargs["no_backward_comp"],
only_committed_files=kwargs["post_commit"],
prev_ver=kwargs["prev_ver"],
skip_conf_json=kwargs["no_conf_json"],
use_git=kwargs["use_git"],
file_path=file_path,
validate_all=kwargs.get("validate_all"),
validate_id_set=kwargs["id_set"],
validate_graph=kwargs.get("graph"),
skip_pack_rn_validation=kwargs["skip_pack_release_notes"],
print_ignored_errors=kwargs["print_ignored_errors"],
is_external_repo=is_external_repo,
print_ignored_files=kwargs["print_ignored_files"],
no_docker_checks=kwargs["no_docker_checks"],
silence_init_prints=kwargs["silence_init_prints"],
skip_dependencies=kwargs["skip_pack_dependencies"],
id_set_path=kwargs.get("id_set_path"),
staged=kwargs["staged"],
create_id_set=kwargs.get("create_id_set"),
json_file_path=kwargs.get("json_file"),
skip_schema_check=kwargs.get("skip_schema_check"),
debug_git=kwargs.get("debug_git"),
include_untracked=kwargs.get("include_untracked"),
quiet_bc=kwargs.get("quiet_bc_validation"),
multiprocessing=run_with_mp,
check_is_unskipped=not kwargs.get("allow_skipped", False),
specific_validations=kwargs.get("run_specific_validations"),
)
return validator.run_validation()
exit_code = 0
if not kwargs["skip_old_validate"]:
validator = OldValidateManager(
is_backward_check=not kwargs["no_backward_comp"],
only_committed_files=kwargs["post_commit"],
prev_ver=kwargs["prev_ver"],
skip_conf_json=kwargs["no_conf_json"],
use_git=kwargs["use_git"],
file_path=file_path,
validate_all=kwargs.get("validate_all"),
validate_id_set=kwargs["id_set"],
validate_graph=kwargs.get("graph"),
skip_pack_rn_validation=kwargs["skip_pack_release_notes"],
print_ignored_errors=kwargs["print_ignored_errors"],
is_external_repo=is_external_repo,
print_ignored_files=kwargs["print_ignored_files"],
no_docker_checks=kwargs["no_docker_checks"],
silence_init_prints=kwargs["silence_init_prints"],
skip_dependencies=kwargs["skip_pack_dependencies"],
id_set_path=kwargs.get("id_set_path"),
staged=kwargs["staged"],
create_id_set=kwargs.get("create_id_set"),
json_file_path=kwargs.get("json_file"),
skip_schema_check=kwargs.get("skip_schema_check"),
debug_git=kwargs.get("debug_git"),
include_untracked=kwargs.get("include_untracked"),
quiet_bc=kwargs.get("quiet_bc_validation"),
multiprocessing=run_with_mp,
check_is_unskipped=not kwargs.get("allow_skipped", False),
specific_validations=kwargs.get("run_specific_validations"),
)
exit_code += validator.run_validation()
if kwargs["run_new_validate"]:
validation_results = ResultWriter(
json_file_path=kwargs.get("json_file"),
)
config_reader = ConfigReader(
config_file_path=kwargs.get("config_path"),
category_to_run=kwargs.get("category_to_run"),
)
initializer = Initializer(
use_git=kwargs["use_git"],
staged=kwargs["staged"],
committed_only=kwargs["post_commit"],
prev_ver=kwargs["prev_ver"],
file_path=file_path,
all_files=kwargs.get("validate_all"),
)
validator_v2 = ValidateManager(
file_path=file_path,
validate_all=kwargs.get("validate_all"),
initializer=initializer,
validation_results=validation_results,
config_reader=config_reader,
allow_autofix=kwargs.get("fix"),
ignore_support_level=kwargs.get("ignore_support_level"),
)
exit_code += validator_v2.run_validations()
return exit_code
except (git.InvalidGitRepositoryError, git.NoSuchPathError, FileNotFoundError) as e:
logger.info(f"[red]{e}[/red]")
logger.info(
Expand Down
4 changes: 2 additions & 2 deletions demisto_sdk/commands/common/legacy_git_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
is_origin_content_repo,
run_command,
)
from demisto_sdk.commands.validate.validate_manager import ValidateManager
from demisto_sdk.commands.validate.old_validate_manager import OldValidateManager


@functools.lru_cache()
Expand Down Expand Up @@ -371,7 +371,7 @@ def filter_changed_files(
elif (
file_status.lower() in ["m", "a", "r"]
and file_type in [FileType.INTEGRATION, FileType.SCRIPT]
and ValidateManager.is_old_file_format(file_path, file_type)
and OldValidateManager.is_old_file_format(file_path, file_type)
):
old_format_files.add(file_path)
# identify modified files
Expand Down
2 changes: 1 addition & 1 deletion demisto_sdk/commands/common/tests/legacy_git_tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def run_command_effect(arg):
return_value=FileType.INTEGRATION,
)
mocker.patch(
"demisto_sdk.commands.validate.validate_manager.ValidateManager.is_old_file_format",
"demisto_sdk.commands.validate.old_validate_manager.OldValidateManager.is_old_file_format",
return_value=False,
)

Expand Down
Loading

0 comments on commit 4b7af85

Please sign in to comment.