[COMMON] Add and run pre-commit linters via tox
[oom.git] / tox.ini
diff --git a/tox.ini b/tox.ini
index 5136a3b..efe3b38 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -5,6 +5,7 @@ envlist =
  docs-linkcheck,
  gitlint,
  checkbashisms,
+ pre-commit,
 skipsdist=true
 
 [doc8]
@@ -67,3 +68,29 @@ whitelist_externals = find
 commands =
     find kubernetes/ TOSCA/ docs/ -name *.py -exec pylint --max-line-length=120 --disable=missing-docstring --method-rgx="(([a-z_][a-zA-Z0-9_]{2,})|(_[a-z0-9_]*)|(__[a-zA-Z][a-zA-Z0-9_]+__))$" --variable-rgx="[a-zA-Z_][a-zA-Z0-9_]{1,30}$" --reports=y --score=y  --output-format=colorized  \{\} +
 
+[testenv:pre-commit-install]
+basepython = python3
+deps = pre-commit
+commands =
+    pre-commit install
+    pre-commit install --hook-type commit-msg
+
+[testenv:pre-commit-uninstall]
+basepython = python3
+deps = pre-commit
+commands =
+    pre-commit uninstall
+    pre-commit uninstall --hook-type commit-msg
+
+[testenv:pre-commit]
+basepython = python3
+deps = pre-commit
+passenv = HOME
+commands =
+    pre-commit run --all-files --show-diff-on-failure
+    pre-commit run gitlint --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG
+    # Gitlint only proposes a pre-commit configuration for the commit-msg stage but none for the commit stage.
+    # Its default arguments --passed and --msg-filename are different from CI recommandations.
+    # As a result, the line above is always skipped in jenkins CI since there cannot be a .git/COMMIT_EDITMSG file.
+    # A dedicated gitlint profile for CI is proposed above. Also to behave fine locally, this profile must have access
+    # to the HOME variable so that Gitlint can retrieve Git user settings.