]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3287] add bandit, pycodestyle and pylint CI jobs
authorAndrei Pavel <andrei@isc.org>
Tue, 30 Apr 2024 10:25:29 +0000 (13:25 +0300)
committerAndrei Pavel <andrei@isc.org>
Thu, 20 Jun 2024 15:52:08 +0000 (18:52 +0300)
.gitlab-ci.yml
.gitlab/ci/pycodestyle.cfg [new file with mode: 0644]
.gitlab/ci/pylint.rc [new file with mode: 0644]

index e372517deae4d8181d56bac947e81ba42f47001d..77374a92454f7a14380c218f87fa454443ef4d7a 100644 (file)
@@ -72,6 +72,37 @@ shellcheck:
   script:
     - ./tools/shellcheck-all.sh
 
+.base_get_list_of_modified_files: &get_modified_files
+  - MODIFIED_FILES=$(git diff --name-only $(git merge-base origin/master HEAD))
+  - echo "${MODIFIED_FILES}"
+
+.base_get_list_of_python_scripts: &get_python_scripts
+  - PYTHON_SCRIPTS=$(find ${INPUT-.} -type f -not -path './.git/*' -and \( -name '*.py' -or -name '*.py.in' \) | sort)
+  - echo "${PYTHON_SCRIPTS}"
+  - if test -z "${PYTHON_SCRIPTS}"; then echo "No python scripts to check. Exiting early."; exit 0; fi
+
+bandit:
+  script:
+    - bandit -r ./
+
+pycodestyle:
+  stage: test
+  script:
+    # - *get_modified_files
+    # - INPUT="${MODIFIED_FILES}"
+    - *get_python_scripts
+    - pycodestyle --config=.gitlab/ci/pycodestyle.cfg ${PYTHON_SCRIPTS}
+
+pylint:
+  stage: test
+  script:
+    # - *get_modified_files
+    # - INPUT="${MODIFIED_FILES}"
+    - *get_python_scripts
+    - pylint --jobs "$(nproc || gnproc || echo 1)" --rcfile ./.gitlab/ci/pylint.rc ${PYTHON_SCRIPTS}
+    # If we reached this point, it means pylint passed. Run again with all warnings enabled, but ignore the return code to show a list of improvements that the developer could do, even when CI is passing.
+    - pylint --jobs "$(nproc || gnproc || echo 1)" --rcfile ./.gitlab/ci/pylint.rc --enable all ${PYTHON_SCRIPTS} || true
+
 ############################### SAST ################################
 # Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/sast/
 #
diff --git a/.gitlab/ci/pycodestyle.cfg b/.gitlab/ci/pycodestyle.cfg
new file mode 100644 (file)
index 0000000..b00efd8
--- /dev/null
@@ -0,0 +1,2 @@
+[pycodestyle]
+  max-line-length = 120
diff --git a/.gitlab/ci/pylint.rc b/.gitlab/ci/pylint.rc
new file mode 100644 (file)
index 0000000..b605350
--- /dev/null
@@ -0,0 +1,17 @@
+[MASTER]
+disable=,
+    consider-using-f-string,  # TODO: This one is decent. There are too many to fix. Enable later.
+    fixme,
+    invalid-name,
+    missing-class-docstring,
+    missing-function-docstring,
+    missing-module-docstring,
+    too-few-public-methods,
+    too-many-arguments,
+    too-many-boolean-expressions,
+    too-many-branches,
+    too-many-instance-attributes,
+    too-many-lines,
+    too-many-locals,
+    too-many-statements,
+max-line-length=120