Add Code testing workflow
authorDarshaka Pathirana <dpat@syn-net.org>
Fri, 13 Nov 2020 15:43:40 +0000 (16:43 +0100)
committerDarshaka Pathirana <dpat@syn-net.org>
Fri, 3 Dec 2021 11:54:54 +0000 (12:54 +0100)
Implement code testing by running shellcheck against shell scripts,
flake8, isort + black against python scripts and spellintian against
man pages.

Codecheck can be executed via 'make codecheck'.

Spellcheck can be executed via 'make spellcheck'.

The Github Workflow is heavily inspired by the workflow of
sipwise/ngcpcfg make by @mika (Thx!).

'make help' is inspired by
https://www.thapaliya.com/en/writings/well-documented-makefiles/
by @suvash (Thx!)

.github/workflows/tests.yml [new file with mode: 0644]
Makefile [new file with mode: 0644]

diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644 (file)
index 0000000..9137f2f
--- /dev/null
@@ -0,0 +1,56 @@
+name: Code Testing
+
+on:
+  push:
+  pull_request:
+  schedule:
+    - cron: '42 1 * * *'
+
+jobs:
+  spellcheck:
+    runs-on: ubuntu-latest
+    name: Run spellcheck
+
+    steps:
+    - name: Checkout source
+      uses: actions/checkout@v2
+
+    - name: Install lintian
+      run: sudo apt-get -y install lintian
+
+    - name: Spellcheck execution
+      run: make spellcheck
+
+  codecheck:
+    runs-on: ubuntu-latest
+    name: Run codecheck
+
+    steps:
+    - name: Checkout source
+      uses: actions/checkout@v2
+
+    - name: Display original shellcheck version
+      run: shellcheck --version
+
+    - name: Update shellcheck to latest stable version
+      run: |
+        wget -qO- https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz | tar -xJv
+        sudo cp shellcheck-stable/shellcheck /usr/bin/
+
+    - name: pip install flake8, isort + black
+      run: pip3 install -U flake8 isort black
+
+    - name: Display current shellcheck version
+      run: shellcheck --version
+
+    - name: Display current flake8 version
+      run: flake8 --version
+
+    - name: Display current isort version
+      run: isort --version
+
+    - name: Display current black version
+      run: black --version
+
+    - name: Codecheck execution
+      run: make codecheck
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..6e0dc8d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,24 @@
+.DEFAULT_GOAL:=help
+
+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
+
+codecheck: shellcheck pythoncheck ## Run shellcheck and pythoncheck
+
+shellcheck: ## Run shellcheck
+       for shellfile in usr_bin/* usr_sbin/* usr_share/*; do head -1 "$${shellfile}" | grep -q "/bin/bash\|/bin/sh" && shellcheck "$${shellfile}"; done
+
+.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
+
+spellcheck: ## Run spellcheck
+       spellintian manpages/*