guardicore / monkey

Infection Monkey - An open-source adversary emulation platform
https://www.guardicore.com/infectionmonkey/
GNU General Public License v3.0
6.58k stars 767 forks source link

Code validation script #789

Closed VakarisZ closed 3 years ago

VakarisZ commented 3 years ago

Is your feature request related to a problem? Please describe. We should have an interactive validation script, that checks current codebase, shows warnings/errors and helps developer to fix them.

Describe the solution you'd like The interactive script should run the same validators travis runs:

  1. It should update/install eslint, flake8, isort, coverage, pipdeptree based on a dedicated requirements.txt file.
  2. It should show pipdeptree warnings
  3. It should show eslint warnings. It should separately show all warnings in files, modified on current branch.
  4. It should show flake8 warnings. It should separately show all warnings in files, modified on current branch.
  5. It should show isort warnings and automatically prompt you to sort imports on files with warnings.
  6. It should run all UT's.
VakarisZ commented 3 years ago

Powershell script which could be a good start:

Push-Location -Path C:\Users\Vakaris\Desktop\infection_monkey
flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics --exclude=monkey/common/cloud/scoutsuite
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=monkey/common/cloud/scoutsuite >> .\flake8_warnings.txt
Get-Content -Path .\flake8_warnings.txt
$PYTHON_WARNINGS_AMOUNT_UPPER_LIMIT = 80
if ((Get-Item -Path .\flake8_warnings.txt | Get-Content -Tail 1) -gt $PYTHON_WARNINGS_AMOUNT_UPPER_LIMIT){
    "Too many python linter warnings! Failing this build. Lower the amount of linter errors in this and try again. "
    exit
}
python -m isort . -c -p common -p infection_monkey -p monkey_island --skip ./monkey/common/cloud/scoutsuite --skip ./monkey/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/rule_path_building/rule_path_creators_list.py --skip ./monkey/monkey_island/cc/ui -l 120 --wl 120
python -m isort . -p common -p infection_monkey -p monkey_island --skip ./monkey/common/cloud/scoutsuite --skip ./monkey/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/rule_path_building/rule_path_creators_list.py --skip ./monkey/monkey_island/cc/ui -l 120 --wl 120
python monkey_island/cc/environment/set_server_config.py testing
python -m pytest
Push-Location -Path .\monkey_island\cc\ui
eslint ./src -c ./.eslintrc

Pop-Location
Pop-Location
itaymmguardicore commented 3 years ago

After we have the script working nicely, we should consider using git hooks to run the script automatically

mssalvatore commented 3 years ago

After we have the script working nicely, we should consider using git hooks to run the script automatically

Have we considered using pre-commit?