diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index b11a517e..b6ce25be 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -19,9 +19,15 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint + source dependency/bash-lint.sh + echo "$(dirname $SHELLCHECK_EXE)" > $GITHUB_PATH - name: Analysing the code with pylint run: | pylint . + - name: Analysing the code with shellchecker + run: | + shellcheck **/*.sh + # TODO: Add more linters here diff --git a/.gitignore b/.gitignore index b3deebb9..75fb1480 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ venv .ci/micromamba/bin/ .ci/micromamba/micromamba/ +# Ignore installed dependencies +dependency/bin/ + # Ignore FOSS project clone dirs /test/foss/*/test-proj/ diff --git a/dependency/bash-lint.sh b/dependency/bash-lint.sh new file mode 100644 index 00000000..a85c21ee --- /dev/null +++ b/dependency/bash-lint.sh @@ -0,0 +1,48 @@ +#!/bin/bash +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + echo "Error: This script must be run using 'source'" + echo "Usage: source $0 [clean|force]" + exit 1 +fi + +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +TARGET_DIR="$THIS_DIR/bin" +TARGET_PATH="$TARGET_DIR/shellcheck" + +VERSION="v0.11.0" +URL="https://github.com/koalaman/shellcheck/releases/download/${VERSION}/shellcheck-${VERSION}.linux.x86_64.tar.xz" + +case "$1" in + clean) + echo "Cleaning shellcheck installation..." + rm -f "$TARGET_PATH" + unalias shellcheck 2>/dev/null + unset SHELLCHECK_EXE + return 0 + ;; + force) + echo "Force flag detected. Removing existing binary..." + rm -f "$TARGET_PATH" + ;; + *) + # Default behavior + ;; +esac + +if [ ! -f "$TARGET_PATH" ]; then + echo "Installing spellcheck to $TARGET_DIR ..." + mkdir -p "$TARGET_DIR" + if wget -qO "$TARGET_PATH.tar.xz" "$URL"; then + tar -xf "$TARGET_PATH.tar.xz" -C "$TARGET_DIR" --strip-components=1 "shellcheck-${VERSION}/shellcheck" + rm "$TARGET_PATH.tar.xz" + echo "spellcheck installed successfully." + else + echo "Error: Failed to download spellcheck." + return 1 + fi +else + echo "spellcheck already installed" +fi + +export SHELLCHECK_EXE="$TARGET_PATH" +alias shellcheck='$SHELLCHECK_EXE' diff --git a/test/test.sh b/test/test.sh index 8b9d4b01..32ed4d49 100755 --- a/test/test.sh +++ b/test/test.sh @@ -1,2 +1,2 @@ #!/bin/bash -python3 -m unittest discover unit $@ +python3 -m unittest discover unit "$@"