From bcc90b006a729061971a2d13e6f4e1a8d1af97ee Mon Sep 17 00:00:00 2001 From: lkrisztian Date: Wed, 30 Aug 2023 08:48:29 +0200 Subject: [PATCH 1/3] fix linting pre commits: exit if any linting step fails --- pre_commit_hooks/linting.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pre_commit_hooks/linting.sh b/pre_commit_hooks/linting.sh index 6928be7..d0c2eb0 100755 --- a/pre_commit_hooks/linting.sh +++ b/pre_commit_hooks/linting.sh @@ -101,11 +101,16 @@ echo "black: `black --version`" cd $CODE_REPO_PATH +RETURNCODE=0 if [ $RUN_FLAKE8 != "FALSE" ] then echo echo "FLAKE8:" flake8 --config=.flake8 --count --statistics --show-source . + if [ $? -ne 0] + then + RETURNCODE=1 + fi else echo echo "FLAKE8 configured to be skipped" @@ -124,6 +129,10 @@ then wget https://raw.githubusercontent.com/mundialis/github-workflows/main/linting-config-examples/.pylintrc fi pylint . + if [ $? -ne 0] + then + RETURNCODE=1 + fi echo echo "PYLINT more strict:" @@ -146,7 +155,13 @@ then echo echo "BLACK:" black --check --diff --line-length 79 . + if [ $? -ne 0] + then + RETURNCODE=1 + fi else echo echo "BLACK configured to be skipped" fi + +return $RETURNCODE From 96fbca40d784bee79b832171b381dc2cb45d1f52 Mon Sep 17 00:00:00 2001 From: lkrisztian Date: Wed, 30 Aug 2023 08:51:45 +0200 Subject: [PATCH 2/3] fix linting.sh --- pre_commit_hooks/linting.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pre_commit_hooks/linting.sh b/pre_commit_hooks/linting.sh index d0c2eb0..90455f8 100755 --- a/pre_commit_hooks/linting.sh +++ b/pre_commit_hooks/linting.sh @@ -107,7 +107,7 @@ then echo echo "FLAKE8:" flake8 --config=.flake8 --count --statistics --show-source . - if [ $? -ne 0] + if [ $? -ne 0 ] then RETURNCODE=1 fi @@ -129,7 +129,7 @@ then wget https://raw.githubusercontent.com/mundialis/github-workflows/main/linting-config-examples/.pylintrc fi pylint . - if [ $? -ne 0] + if [ $? -ne 0 ] then RETURNCODE=1 fi @@ -155,7 +155,7 @@ then echo echo "BLACK:" black --check --diff --line-length 79 . - if [ $? -ne 0] + if [ $? -ne 0 ] then RETURNCODE=1 fi @@ -164,4 +164,4 @@ else echo "BLACK configured to be skipped" fi -return $RETURNCODE +exit $RETURNCODE From 7e7bb9204d3edba94f055b013ad50a14ac8272f2 Mon Sep 17 00:00:00 2001 From: lkrisztian Date: Wed, 30 Aug 2023 08:57:53 +0200 Subject: [PATCH 3/3] added message, which linting steps failed --- pre_commit_hooks/linting.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pre_commit_hooks/linting.sh b/pre_commit_hooks/linting.sh index 90455f8..0fe4f6e 100755 --- a/pre_commit_hooks/linting.sh +++ b/pre_commit_hooks/linting.sh @@ -101,6 +101,7 @@ echo "black: `black --version`" cd $CODE_REPO_PATH +FAILINGSTEP="" RETURNCODE=0 if [ $RUN_FLAKE8 != "FALSE" ] then @@ -110,6 +111,7 @@ then if [ $? -ne 0 ] then RETURNCODE=1 + FAILINGSTEP="FLAKE8" fi else echo @@ -132,6 +134,7 @@ then if [ $? -ne 0 ] then RETURNCODE=1 + FAILINGSTEP="$FAILINGSTEP PYLINT" fi echo @@ -158,10 +161,15 @@ then if [ $? -ne 0 ] then RETURNCODE=1 + FAILINGSTEP="$FAILINGSTEP BLACK" fi else echo echo "BLACK configured to be skipped" fi +if [ $RETURNCODE -ne 0 ] +then + echo "Failing steps: ${FAILINGSTEP}" +fi exit $RETURNCODE