Skip to content

Commit

Permalink
Add: Shell Script linter test
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Sep 3, 2022
1 parent e6af142 commit 4176f78
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 30 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ jobs:
with:
python-version: "3.7"

- name: Get required packages for Blender
- name: Install required packages
run: |
sudo apt-get update -qq
sudo apt-get install -y python3 python3-pip
- name: Get required pip packages
- name: Install required pip packages
run: pip3 install -r requirements.txt

- name: pylint test
Expand Down Expand Up @@ -79,13 +79,28 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v2

- name: Get required packages for Blender
- name: Install required packages
run: |
sudo apt-get update -qq
sudo apt-get install -y python3 python3-pip
- name: Get required pip packages
- name: Install required pip packages
run: pip3 install -r requirements.txt

- name: yamllint test
run: bash tests/lint/yamllint/run.sh .

shellcheck:
name: shellcheck
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Install required packages
run: |
sudo apt-get update -qq
sudo apt-get install -y shellcheck
- name: shellcheck test
run: bash tests/lint/shellcheck/run.sh .
20 changes: 11 additions & 9 deletions tests/lint/markdownlint/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ if [ $# -ne 1 ]; then
exit 1
fi

readonly SCRIPT_DIR=$(cd $(dirname $0); pwd)
readonly MARKDOWN_DIRECTORY=${1}
# shellcheck disable=SC2155
{
readonly TMP_DIR=$(mktemp -d)
}
readonly MARKDOWN_CMD="markdownlint"

error=0
for file in `find ${MARKDOWN_DIRECTORY} -name "*.md" | sort`; do
for file in $(find "${MARKDOWN_DIRECTORY}" -name "*.md" | sort); do
MARKDOWN_INPUT_FILE="${TMP_DIR}/${file}"
mkdir -p $(dirname ${MARKDOWN_INPUT_FILE})
dir_name=$(dirname "${MARKDOWN_INPUT_FILE}")
mkdir -p "${dir_name}"

SKIP_FILES=()

skip=0
for f in "${SKIP_FILES[@]}"; do
if [[ ${file} =~ "${f}" ]]; then
if [[ ${file} =~ ${f} ]]; then
skip=1
fi
done
Expand All @@ -28,16 +31,15 @@ for file in `find ${MARKDOWN_DIRECTORY} -name "*.md" | sort`; do
continue
fi

cat ${file} > ${MARKDOWN_INPUT_FILE}
cat "${file}" > "${MARKDOWN_INPUT_FILE}"

echo "======= markdownlint "${file}" ======="
echo "======= markdownlint ${file} ======="

${MARKDOWN_CMD} ${MARKDOWN_INPUT_FILE}
if [ $? -ne 0 ]; then
if ! ${MARKDOWN_CMD} "${MARKDOWN_INPUT_FILE}"; then
((error+=1))
fi

rm -rf ${TMP_DIR}
rm -rf "${TMP_DIR}"
done

if ((error > 0)); then
Expand Down
12 changes: 7 additions & 5 deletions tests/lint/pycodestyle/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ if [ $# -ne 1 ]; then
exit 1
fi

readonly SCRIPT_DIR=$(cd $(dirname $0); pwd)
# shellcheck disable=SC2046,SC2155,SC2164
{
readonly SCRIPT_DIR=$(cd $(dirname "$0"); pwd)
}
readonly PYTHON_SCRIPT_DIRECTORY=${1}
readonly PYCODESTYLE_CMD="pycodestyle"

# pycodestyle
error=0
for file in `find ${PYTHON_SCRIPT_DIRECTORY} -name "*.py" | sort`; do
echo "======= pycodestyle "${file}" ======="
for file in $(find "${PYTHON_SCRIPT_DIRECTORY}" -name "*.py" | sort); do
echo "======= pycodestyle ${file} ======="

${PYCODESTYLE_CMD} --config="${SCRIPT_DIR}/.pycodestyle" ${file}
if [ $? -ne 0 ]; then
if ! ${PYCODESTYLE_CMD} --config="${SCRIPT_DIR}/.pycodestyle" "${file}"; then
((error+=1))
fi
done
Expand Down
12 changes: 7 additions & 5 deletions tests/lint/pylint/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ if [ $# -ne 1 ]; then
exit 1
fi

readonly SCRIPT_DIR=$(cd $(dirname $0); pwd)
# shellcheck disable=SC2046,SC2155,SC2164
{
readonly SCRIPT_DIR=$(cd $(dirname "$0"); pwd)
}
readonly PYTHON_SCRIPT_DIRECTORY=${1}
readonly PYLINT_CMD="pylint"

# pylint
error=0
for file in `find ${PYTHON_SCRIPT_DIRECTORY} -name "*.py" | sort`; do
echo "======= pylint "${file}" ======="
for file in $(find "${PYTHON_SCRIPT_DIRECTORY}" -name "*.py" | sort); do
echo "======= pylint ${file} ======="

${PYLINT_CMD} --rcfile="${SCRIPT_DIR}/.pylintrc" ${file}
if [ $? -ne 0 ]; then
if ! ${PYLINT_CMD} --rcfile="${SCRIPT_DIR}/.pylintrc" "${file}"; then
((error+=1))
fi
done
Expand Down
25 changes: 25 additions & 0 deletions tests/lint/shellcheck/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if [ $# -ne 1 ]; then
echo "Usage: run.sh <target>"
exit 1
fi

readonly PYTHON_SCRIPT_DIRECTORY=${1}
readonly SHELLCHECK_CMD="shellcheck"

error=0
for file in $(find "${PYTHON_SCRIPT_DIRECTORY}" -name "*.sh" | sort); do
echo "======= shellcheck ${file} ======="

if ! ${SHELLCHECK_CMD} "${file}"; then
((error+=1))
fi
done

if ((error > 0)); then
echo "Error: ${error} files have errors."
exit 1
fi

exit 0
8 changes: 3 additions & 5 deletions tests/lint/yamllint/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ if [ $# -ne 1 ]; then
exit 1
fi

readonly SCRIPT_DIR=$(cd $(dirname $0); pwd)
readonly PYTHON_SCRIPT_DIRECTORY=${1}
readonly YAMLLINT_CMD="yamllint"

# yamllint
error=0
for file in `find ${PYTHON_SCRIPT_DIRECTORY} -name "*.yml" | sort`; do
echo "======= yamllint "${file}" ======="
for file in $(find "${PYTHON_SCRIPT_DIRECTORY}" -name "*.yml" | sort); do
echo "======= yamllint ${file} ======="

${YAMLLINT_CMD} --strict ${file}
if [ $? -ne 0 ]; then
if ! ${YAMLLINT_CMD} --strict "${file}"; then
((error+=1))
fi
done
Expand Down
4 changes: 2 additions & 2 deletions tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ os=${1}
version=${2}
target=""

if [ ${os} = "mac" ]; then
if [ "${os}" = "mac" ]; then
target="${HOME}/Library/Application Support/Blender/${version}/scripts/addons/screencast_keys"
elif [ ${os} = "linux" ]; then
elif [ "${os}" = "linux" ]; then
target="${HOME}/.config/blender/${version}/scripts/addons/screencast_keys"
else
echo "Invalid operating system."
Expand Down

0 comments on commit 4176f78

Please sign in to comment.