Makefile: return error if a check fails
authorDarshaka Pathirana <dpat@syn-net.org>
Sat, 24 Apr 2021 22:25:29 +0000 (00:25 +0200)
committerDarshaka Pathirana <dpat@syn-net.org>
Fri, 3 Dec 2021 11:54:54 +0000 (12:54 +0100)
Make target pythoncheck (and codecheck) did not fail if the last tested
file was error-free. Now we set RETURN=1 if only one check fails.

While at it also created separate targets for flake8, black and isort,
but also added --keep-going option when running 'make codecheck' so that all
targets are run.

Added @ in front of each command to hide the command which makes the
output more readable.

Spellcheck SC1117 (Backslash is literal in "\n") is no longer emitted
(with shellcheck after v0.5), thats why it is removed.

Please note, that spellintian does not return an error code if an
incorrect spelling is found, that is why this ugly hack had to be
implemented.

.github/workflows/tests.yml
Makefile

index 9137f2f..b06617b 100644 (file)
@@ -53,4 +53,4 @@ jobs:
       run: black --version
 
     - name: Codecheck execution
-      run: make codecheck
+      run: make --keep-going codecheck
index 3f03867..c122c0f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,22 +3,66 @@
 help:  ## Display this help
        @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[36m\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf "  \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
 
-all: codecheck spellcheck ## Run codecheck and spellcheck
+allcheck: codecheck spellcheck ## Run codecheck and spellcheck
 
 codecheck: shellcheck pythoncheck ## Run shellcheck and pythoncheck
 
+.ONESHELL:
 shellcheck: ## Run shellcheck
-       for shellfile in $$(ls usr_bin/* usr_sbin/* usr_share/* | grep -v "iimage" | grep -v "make_chroot_jail"); do head -1 "$${shellfile}" | grep -q "/bin/bash\|/bin/sh" && shellcheck -e SC1117 -x "$${shellfile}"; done
+       @RETURN=0
+       @for shellfile in $$(ls usr_bin/* usr_sbin/* usr_share/*); do
+       @       [ "$${shellfile}" = "usr_bin/iimage" ] && continue
+       @       [ "$${shellfile}" = "usr_sbin/make_chroot_jail" ] && continue
+       @       file "$${shellfile}" | grep -q shell && (shellcheck -x "$${shellfile}" || RETURN=1)
+       @done
+       @exit $${RETURN}
+
+.ONESHELL:
+pythoncheck: ## Run pythoncheck (flakecheck, isortcheck + blackcheck)
+       @RETURN=0
+       @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do
+       @       if head -1 "$${pythonfile}" | grep -q "python"; then
+       @               flake8 "$${pythonfile}" || RETURN=1
+       @               isort --check "$${pythonfile}" || RETURN=1
+       @               black --check "$${pythonfile}" || RETURN=1
+       @       fi
+       @done
+       @exit $${RETURN}
+
+.ONESHELL:
+flakecheck: ## Run flake8 only
+       @RETURN=0
+       @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do
+       @       if head -1 "$${pythonfile}" | grep -q "python"; then
+       @               flake8 "$${pythonfile}" || RETURN=1
+       @       fi
+       @done
+       @exit $${RETURN}
+
+.ONESHELL:
+isortcheck: ## Run isort --check only
+       @RETURN=0
+       @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do
+       @       if head -1 "$${pythonfile}" | grep -q "python"; then
+       @               isort --check "$${pythonfile}" || RETURN=1
+       @       fi
+       @done
+       @exit $${RETURN}
 
 .ONESHELL:
-pythoncheck: ## Run shellcheck
-       for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do
-               if head -1 "$${pythonfile}" | grep -q "python"; then
-                       flake8 "$${pythonfile}"
-                       isort --check "$${pythonfile}"
-                       black --check "$${pythonfile}"
-               fi
-       done
+blackcheck: ## Run black --check only
+       @RETURN=0
+       @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do
+       @       if head -1 "$${pythonfile}" | grep -q "python"; then
+       @               black --check "$${pythonfile}" || RETURN=1
+       @       fi
+       @done
+       @exit $${RETURN}
 
+.ONESHELL:
 spellcheck: ## Run spellcheck
-       spellintian manpages/*
+       @OUTPUT="$$(spellintian manpages/*)"
+       @echo $$OUTPUT
+       @if [ -n "$$OUTPUT" ]; then
+       @       false
+       @fi