From 1f1682fad8be3934d2893c22a48ca74ed3af3918 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 6 Nov 2020 11:48:52 +0200 Subject: [PATCH] Exported multiple configurations of CI tools to separate configurations, improved script --- .travis.yml | 2 +- ci_scripts/README.md | 1 + ci_scripts/isort.cfg | 11 ++++++----- ci_scripts/validate.ps1 | 29 ++++++++++++++++++++++++----- monkey/pytest.ini | 2 +- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 35f6210cb..3e4d3104a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,7 +73,7 @@ script: - if [ $(tail -n 1 ./ci_scripts/flake8_warnings.txt) -gt $PYTHON_WARNINGS_AMOUNT_UPPER_LIMIT ]; then echo "Too many python linter warnings! Failing this build. Lower the amount of linter errors in this and try again. " && exit 1; fi ## Check import order -- python -m isort . -c -p common -p infection_monkey -p monkey_island +- python -m isort ./monkey --settings-file ./ci_scripts/isort.cfg ## Run unit tests - cd monkey # This is our source dir diff --git a/ci_scripts/README.md b/ci_scripts/README.md index af555a7dd..09330d298 100644 --- a/ci_scripts/README.md +++ b/ci_scripts/README.md @@ -4,4 +4,5 @@ Run this script to validate your code locally and auto fix/format the problems b # Usage +You've got to manually download swimm for swimm validation. run from `infection_monkey` directory: `powershell .\ci_scripts\validate.ps1` diff --git a/ci_scripts/isort.cfg b/ci_scripts/isort.cfg index f9a62b0ed..d8651febd 100644 --- a/ci_scripts/isort.cfg +++ b/ci_scripts/isort.cfg @@ -1,5 +1,6 @@ -[settings] -project=common,infection_monkey,monkey_island -skip=./monkey/common/cloud/scoutsuite,./monkey/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/rule_path_building/rule_path_creators_list.py,./monkey/monkey_island/cc/ui -line-length=120 -wrap-length=120 +[isort] + +# Possible options: https://pycqa.github.io/isort/docs/configuration/options/ + +known_first_party=common,infection_monkey,monkey_island +skip=monkey/common/cloud/scoutsuite,monkey/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/rule_path_building/rule_path_creators_list.py,monkey/monkey_island/cc/ui,monkey/common/cloud/scoutsuite diff --git a/ci_scripts/validate.ps1 b/ci_scripts/validate.ps1 index 98a0ab4dd..d85da6a2a 100644 --- a/ci_scripts/validate.ps1 +++ b/ci_scripts/validate.ps1 @@ -1,4 +1,7 @@ .\ci_scripts\validation-env\Scripts\activate.ps1 +$ErrorActionPreference = "Stop" +python -m pip install -r monkey/monkey_island/requirements.txt +python -m pip install -r monkey/infection_monkey/requirements.txt flake8 ./monkey --config ./ci_scripts/flake8_syntax_check.cfg flake8 ./monkey --exit-zero --config ./ci_scripts/flake8_linter_check.cfg | Out-File -FilePath .\ci_scripts\flake8_warnings.txt Get-Content -Path .\ci_scripts\flake8_warnings.txt @@ -8,13 +11,29 @@ if ((Get-Item -Path .\ci_scripts\flake8_warnings.txt | Get-Content -Tail 1) -gt exit } python -m isort ./monkey -c --settings-file ./ci_scripts/isort.cfg -# python -m isort ./monkey --settings-file ./ci_scripts/isort.cfg -python monkey_island/cc/environment/set_server_config.py testing +if (!$?) { + $confirmation = Read-Host "Isort found errors. Do you want to attmpt to fix them automatically? (y/n)" + if ($confirmation -eq 'y') { + python -m isort ./monkey --settings-file ./ci_scripts/isort.cfg + } +} +Push-Location -Path ./monkey +python ./monkey_island/cc/environment/set_server_config.py testing python -m pytest -Push-Location -Path .\monkey_island\cc\ui -eslint ./src -c ./.eslintrc +$lastCommandSucceeded = $? +python ./monkey_island/cc/environment/set_server_config.py restore +Pop-Location +if (!$lastCommandSucceeded) { + exit +} + +Push-Location -Path .\monkey\monkey_island\cc\ui +eslint ./src -c ./.eslintrc Pop-Location -Pop-Location + +swimm verify + +Write-Host "Script finished. Press any key to continue" $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); deactivate diff --git a/monkey/pytest.ini b/monkey/pytest.ini index 3596bf5f6..9b1766fc2 100644 --- a/monkey/pytest.ini +++ b/monkey/pytest.ini @@ -3,5 +3,5 @@ log_cli = 1 log_cli_level = DEBUG log_cli_format = %(asctime)s [%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s log_cli_date_format=%H:%M:%S -addopts = -v --capture=sys +addopts = -v --capture=sys --ignore=common/cloud/scoutsuite norecursedirs = node_modules dist