comments + shellcheck

This commit is contained in:
tooomm 2026-07-26 20:55:25 +02:00
parent 4f9bd4338d
commit 163098b0a8
3 changed files with 51 additions and 50 deletions

View file

@ -323,11 +323,11 @@ if [[ $USE_CCACHE == 1 ]]; then
echo "::group::Show ccache configuration" echo "::group::Show ccache configuration"
ccache --version ccache --version
ccache --show-config ccache --show-config
echo "---" echo " -----"
ccache --show-stats ccache --show-stats
echo "---" echo " -----"
ccache --zero-stats ccache --zero-stats
echo "---" echo " -----"
ccache --show-stats ccache --show-stats
echo "::endgroup::" echo "::endgroup::"
fi fi
@ -362,7 +362,6 @@ if [[ $USE_CCACHE == 1 ]]; then
echo "::group::Show ccache statistics" echo "::group::Show ccache statistics"
ccache --show-stats --verbose ccache --show-stats --verbose
echo "---"
ccache --show-compression ccache --show-compression
echo "::endgroup::" echo "::endgroup::"

View file

@ -11,8 +11,8 @@ set -euo pipefail
# Adds output to GITHUB_OUTPUT # Adds output to GITHUB_OUTPUT
# #
# Expected to be run in the repository root where CPack executes from and places its output binary # Expected to be run in the repository root where CPack executes from and places its output binary
# Expects a single binary for package_pattern and picks the first match
# Expects <extension> to be e.g. ".dmg", ".deb" or ".exe" (".tar.gz" etc. with more than one dot will break) # Expects <extension> to be e.g. ".dmg", ".deb" or ".exe" (".tar.gz" etc. with more than one dot will break)
# If multiple packages match <package_pattern>, the first match is used
# Initialize PACKAGE_SUFFIX from positional argument # Initialize PACKAGE_SUFFIX from positional argument
PACKAGE_SUFFIX="${1:-}" PACKAGE_SUFFIX="${1:-}"
@ -34,9 +34,9 @@ if [[ -z "$package_path" ]]; then
fi fi
# <package> = <filename><extension> # <package> = <filename><extension>
package="${package_path##*/}" # remove folder path (keep e.g. "Cockatrice-3.0.0.deb") package="${package_path##*/}" # e.g. "Cockatrice-3.0.0.deb"
filename="${package%.*}" # remove extension (keep e.g. "Cockatrice-3.0.0") filename="${package%.*}" # e.g. "Cockatrice-3.0.0"
extension=".${package##*.}" # remove filename (keep e.g. ".deb") extension=".${package##*.}" # e.g. ".deb"
# Rename package (build artifact) # Rename package (build artifact)
filename_new="$filename$PACKAGE_SUFFIX" filename_new="$filename$PACKAGE_SUFFIX"
@ -47,6 +47,8 @@ echo "Renaming '$package' to '$package_new'"
mv "$package_path" "$package_path_new" mv "$package_path" "$package_path_new"
du -h "$package_path_new" du -h "$package_path_new"
echo "package_path=$package_path_new" >>"$GITHUB_OUTPUT" {
echo "package=$package_new" >>"$GITHUB_OUTPUT" echo "package_path=$package_path_new" >> "$GITHUB_OUTPUT"
echo "filename=$filename_new" >>"$GITHUB_OUTPUT" echo "package=$package_new" >> "$GITHUB_OUTPUT"
echo "filename=$filename_new" >> "$GITHUB_OUTPUT"
} >> "$GITHUB_OUTPUT"

View file

@ -1,30 +1,30 @@
#!/bin/bash #!/bin/bash
# This script will run clang-format on all modified, non-3rd-party C++/Header files. # This script will run Clang-Format on all modified, non-3rd-party C++/Header files.
# Optionally runs cmake-format on all modified cmake files. # Optionally runs cmake-format on all modified cmake files.
# Optionally runs shellcheck on all modified shell files. # Optionally runs ShellCheck on all modified shell files.
# Uses clang-format, cmake-format, git, diff, find and shellcheck # Uses clang-format, cmake-format, git, diff, find and shellcheck
# Never, ever, should this receive a path with a newline in it. Don't bother proofing it for that. # Never, ever, should this receive a path with a newline in it. Don't bother proofing it for that.
set -o pipefail set -o pipefail
# go to the project root directory, this file should be located in the project root directory # Go to the project root directory, this file should be located in the project root directory
olddir="$PWD" olddir="$PWD"
cd "${BASH_SOURCE%/*}/" || exit 2 # could not find path, this could happen with special links etc. cd "${BASH_SOURCE%/*}/" || exit 2 # could not find path, this could happen with special links etc.
# defaults # Defaults
include=("cockatrice/src" \ include=("cockatrice/src" \
libcockatrice_* \ libcockatrice_* \
"oracle/src" \ "oracle/src" \
"servatrice/src" \ "servatrice/src" \
"tests") "tests")
exclude=("libcockatrice_rng/libcockatrice/rng/sfmt/" \ exclude=("libcockatrice_rng/libcockatrice/rng/sfmt/" \
"libcockatrice_utility/libcockatrice/utility/peglib.h" \ "libcockatrice_utility/libcockatrice/utility/peglib.h" \
"oracle/src/lzma/" \ "oracle/src/lzma/" \
"oracle/src/qt-json/" \ "oracle/src/qt-json/" \
"oracle/src/zip/" \ "oracle/src/zip/" \
"servatrice/src/smtp/") "servatrice/src/smtp/")
exts=("cpp" "h" "proto") extensions=("cpp" "h" "proto")
cf_cmd="clang-format" cf_cmd="clang-format"
branch="origin/master" branch="origin/master"
cmakefile="CMakeLists.txt" cmakefile="CMakeLists.txt"
@ -33,9 +33,9 @@ cmakeinclude=("cmake/gtest-CMakeLists.txt.in")
scripts="*.sh" scripts="*.sh"
color="--" color="--"
verbosity=0 verbosity=0
sep="----------" separator="----------"
# parse options # Parse options
while [[ $* ]]; do while [[ $* ]]; do
case "$1" in case "$1" in
'-b'|'--branch') '-b'|'--branch')
@ -58,7 +58,7 @@ while [[ $* ]]; do
;; ;;
'-h'|'--help') '-h'|'--help')
cat <<EOM cat <<EOM
A bash script to automatically format your code using clang-format. A bash script to automatically format your code using Clang-Format.
If no options are given, all dirty source files are edited in place. If no options are given, all dirty source files are edited in place.
If <dir>s are given, all source files in those directories of the project root If <dir>s are given, all source files in those directories of the project root
@ -165,7 +165,7 @@ EOM
;; ;;
*) *)
if [[ ! $dashdash && $1 =~ ^-- ]]; then if [[ ! $dashdash && $1 =~ ^-- ]]; then
echo "error in parsing arguments of $0: $1 is an unrecognized option" >&2 echo "Error in parsing arguments of $0: $1 is an unrecognized option" >&2
exit 2 # input error exit 2 # input error
fi fi
if [[ ! $1 ]] || next_dir=$(cd "$olddir" && cd -- "$1" && pwd); then if [[ ! $1 ]] || next_dir=$(cd "$olddir" && cd -- "$1" && pwd); then
@ -175,13 +175,13 @@ EOM
fi fi
if [[ $1 ]]; then if [[ $1 ]]; then
if [[ $next_dir != $PWD/* ]]; then if [[ $next_dir != $PWD/* ]]; then
echo "error in parsing arguments of $0: $next_dir is not in $PWD" >&2 echo "Error in parsing arguments of $0: $next_dir is not in $PWD" >&2
exit 2 # input error exit 2 # input error
fi fi
include+=("$next_dir") include+=("$next_dir")
fi fi
else else
echo "error in parsing arguments of $0: $1 is not a directory" >&2 echo "Error in parsing arguments of $0: $1 is not a directory" >&2
exit 2 # input error exit 2 # input error
fi fi
if ! [[ $set_branch ]]; then if ! [[ $set_branch ]]; then
@ -192,39 +192,39 @@ EOM
esac esac
done done
# check availability of clang-format # Check availability of Clang-Format
if ! hash $cf_cmd 2>/dev/null; then if ! hash $cf_cmd 2>/dev/null; then
echo "could not find $cf_cmd" >&2 echo "could not find $cf_cmd" >&2
# find any clang-format-x.x in /usr/bin # Find any "clang-format-x.x" in /usr/bin
cf_cmd=$(find /usr/bin -regex '.*/clang-format-[0-9]+\.[0-9]+' -print -quit) cf_cmd=$(find /usr/bin -regex '.*/clang-format-[0-9]+\.[0-9]+' -print -quit)
if [[ $cf_cmd ]]; then if [[ $cf_cmd ]]; then
echo "found $cf_cmd instead" >&2 echo "Found $cf_cmd instead" >&2
else else
exit 3 # special exit code for missing dependency exit 3 # special exit code for missing dependency
fi fi
fi fi
# check availability of cmake-format # Check availability of cmake-format
if [[ $do_cmake ]] && ! hash cmake-format 2>/dev/null; then if [[ $do_cmake ]] && ! hash cmake-format 2>/dev/null; then
echo "could not find cmake-format" >&2 echo "Could not find cmake-format" >&2
exit 3 exit 3
fi fi
# check availability of shellcheck # Check availability of ShellCheck
if [[ $do_shell ]] && ! hash shellcheck 2>/dev/null; then if [[ $do_shell ]] && ! hash shellcheck 2>/dev/null; then
echo "could not find shellcheck" >&2 echo "Could not find shellcheck" >&2
exit 3 exit 3
fi fi
if [[ $branch ]]; then if [[ $branch ]]; then
# get all dirty files through git # Get all dirty files through git
if ! base=$(git merge-base "$branch" HEAD); then if ! base=$(git merge-base "$branch" HEAD); then
echo "could not find git merge base" >&2 echo "Could not find git merge base" >&2
exit 2 # input error exit 2 # input error
fi fi
mapfile -t basenames < <(git diff --diff-filter=d --name-only "$base") mapfile -t basenames < <(git diff --diff-filter=d --name-only "$base")
names=() names=()
for ex in "${exts[@]}"; do for ex in "${extensions[@]}"; do
for path in "${include[@]}"; do for path in "${include[@]}"; do
for name in "${basenames[@]}"; do for name in "${basenames[@]}"; do
rx="^$path/.*\\.$ex$" rx="^$path/.*\\.$ex$"
@ -260,7 +260,7 @@ if [[ $branch ]]; then
fi fi
else else
exts_o=() exts_o=()
for ext in "${exts[@]}"; do for ext in "${extensions[@]}"; do
exts_o+=(-o -name "*\\.$ext") exts_o+=(-o -name "*\\.$ext")
done done
unset "exts_o[0]" # remove first -o unset "exts_o[0]" # remove first -o
@ -274,7 +274,7 @@ else
fi fi
fi fi
# filter excludes # Filter excludes
for path in "${exclude[@]}"; do for path in "${exclude[@]}"; do
for i in "${!names[@]}"; do for i in "${!names[@]}"; do
rx="^$path" rx="^$path"
@ -284,12 +284,12 @@ for path in "${exclude[@]}"; do
done done
done done
# optionally print version # Optionally print version
if [[ $print_version ]]; then if [[ $print_version ]]; then
$cf_cmd -version $cf_cmd -version
[[ $do_cmake ]] && echo "cmake-format version $(cmake-format --version)" [[ $do_cmake ]] && echo "cmake-format version $(cmake-format --version)"
[[ $do_shell ]] && echo "shellcheck $(shellcheck --version | grep "version:")" [[ $do_shell ]] && echo "ShellCheck $(shellcheck --version | grep "version:")"
echo "$sep" echo "$separator"
fi fi
if [[ ! ${cmake_names[*]} ]]; then if [[ ! ${cmake_names[*]} ]]; then
@ -302,7 +302,7 @@ if [[ ! ( ${names[*]} || $do_cmake || $do_shell ) ]]; then
exit 0 # nothing to format means format is successful! exit 0 # nothing to format means format is successful!
fi fi
# format # Format
case $mode in case $mode in
diff) diff)
declare -i code=0 declare -i code=0
@ -326,7 +326,7 @@ case $mode in
fi fi
done done
if (( code>0 )); then if (( code>0 )); then
echo "$sep" echo "$separator"
echo "Affected file(s):" echo "Affected file(s):"
for name in "${files_to_format[@]}"; do for name in "${files_to_format[@]}"; do
echo " $name" echo " $name"
@ -375,15 +375,15 @@ case $mode in
cmake-format -i "${cmake_names[@]}" cmake-format -i "${cmake_names[@]}"
fi fi
if [[ $do_shell ]]; then if [[ $do_shell ]]; then
echo "warning: --shell is not compatible with the current mode but shell files were modified!" >&2 echo "Warning: --shell is not compatible with the current mode but shell files were modified!" >&2
echo "recommendation: try $0 --diff --shell" >&2 echo "Recommendation: try $0 --diff --shell" >&2
fi fi
if (( verbosity>0 )); then if (( verbosity>0 )); then
count="${#names[*]}" count="${#names[*]}"
if [[ $do_cmake ]]; then if [[ $do_cmake ]]; then
(( count+=${#cmake_names[*]} )) (( count+=${#cmake_names[*]} ))
fi fi
echo "parsed $count files that differ from base $branch" echo "Parsed $count files that differ from base $branch"
fi fi
;; ;;
esac esac