This repository has been archived by the owner on Oct 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bashate and shellcheck scripts and targets
- Loading branch information
Showing
4 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SC2046: Quote this to prevent word splitting. | ||
# SC2086: Double quote to prevent globbing and word splitting. | ||
# SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. | ||
disable=SC2046,SC2086,SC2181 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
|
||
# Create a temporary directory for the virtual environment | ||
VENVDIR=$(mktemp --tmpdir -d venv.XXXXXX) || { | ||
echo "Failed to create working directory" >&2 | ||
exit 1 | ||
} | ||
|
||
function cleanup { | ||
# Clean up the temporary directory | ||
rm -rf "${VENVDIR}" | ||
} | ||
trap cleanup EXIT | ||
|
||
function fatal { | ||
# Log an error message and exit with a non-zero status | ||
echo "ERROR: $*" >&2 | ||
exit 1 | ||
} | ||
|
||
# Create a Python virtual environment | ||
python3 -m venv "${VENVDIR}" || fatal "Could not set up virtualenv" | ||
|
||
# Activate the virtual environment | ||
# shellcheck disable=SC1091 | ||
source "${VENVDIR}/bin/activate" || fatal "Could not activate virtualenv" | ||
|
||
# Install bashate in the virtual environment | ||
pip install bashate==2.1.0 || fatal "Installation of bashate failed" | ||
|
||
# Run bashate on all Bash script files, excluding specified directories | ||
find . -name '*.sh' -not -path './vendor/*' -not -path './git/*' \ | ||
-not -path './bin/*' -not -path './testbin/*' -print0 | | ||
xargs -0 --no-run-if-empty bashate -v -e 'E*' -i E006 | ||
|
||
# Check the exit status of bashate and exit with an appropriate status | ||
if [ $? -eq 0 ]; then | ||
echo "All checks passed successfully" | ||
exit 0 | ||
else | ||
echo "Some checks failed. See error messages above." | ||
exit 2 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# Set the ShellCheck version and binary path | ||
shellcheck_version="v0.7.2" | ||
shellcheck_binary="$(go env GOPATH)/bin/shellcheck" | ||
|
||
|
||
function cleanup { | ||
# Clean up the temporary directory | ||
[ -n "$temp_dir" ] && rm -rf "$temp_dir" | ||
} | ||
trap cleanup EXIT | ||
|
||
function fatal { | ||
# Log an error message and exit with a non-zero status | ||
echo "ERROR: $*" >&2 | ||
exit 1 | ||
} | ||
|
||
# Check if ShellCheck binary is not found | ||
if [ ! -f "${shellcheck_binary}" ]; then | ||
echo "Downloading shellcheck tool..." | ||
echo "Downloading ShellCheck tool..." | ||
download_url="https://github.com/koalaman/shellcheck/releases/download/$shellcheck_version/shellcheck-$shellcheck_version.linux.x86_64.tar.xz" | ||
|
||
# Create a temporary directory for extraction | ||
temp_dir="$(mktemp -d)" | ||
temp_dir="$(mktemp -d)" || fatal "Failed to create a temporary directory" | ||
|
||
# Download and extract ShellCheck | ||
wget -qO- "$download_url" | tar -xJ -C "$temp_dir" --strip=1 "shellcheck-$shellcheck_version/shellcheck" | ||
wget -qO- "$download_url" | tar -xJ -C "$temp_dir" --strip=1 "shellcheck-$shellcheck_version/shellcheck" || fatal "Failed to download and extract ShellCheck" | ||
|
||
# Move shellcheck binary to the desired location | ||
mv "$temp_dir/shellcheck" "$shellcheck_binary" | ||
# Move the ShellCheck binary to the desired location | ||
mv "$temp_dir/shellcheck" "$shellcheck_binary" || fatal "Failed to move ShellCheck binary" | ||
|
||
# Clean up temporary directory | ||
rm -r "$temp_dir" | ||
echo "ShellCheck has been installed" | ||
fi | ||
|
||
|
||
# Find and check shell script files with ShellCheck | ||
find . -name '*.sh' -not -path './vendor/*' -not -path './git/*' \ | ||
-not -path './bin/*' -not -path './testbin/*' -print0 \ | ||
| xargs -0 --no-run-if-empty "${shellcheck_binary}" -x | ||
-not -path './bin/*' -not -path './testbin/*' -print0 | | ||
xargs -0 --no-run-if-empty "${shellcheck_binary}" -x || fatal "ShellCheck encountered errors" | ||
|
||
# All checks passed successfully | ||
echo "All checks passed successfully" | ||
exit 0 |