diff --git a/.github/workflows/bashate.yml b/.github/workflows/bashate.yml new file mode 100644 index 00000000..0217c5a1 --- /dev/null +++ b/.github/workflows/bashate.yml @@ -0,0 +1,43 @@ +# The MIT License (MIT) +# +# Copyright (c) 2021-2025 Yegor Bugayenko +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +name: bashate +'on': + push: + branches: + - master + pull_request: + branches: + - master +jobs: + bashate: + timeout-minutes: 15 + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.11 + - run: pip install bashate + - run: | + readarray -t files < <(find . -name '*.sh') + bashate -i E006,E003 "${files[@]}" + diff --git a/filters/001-move-gits-to-temp.sh b/filters/001-move-gits-to-temp.sh index 5c9f2b53..c086021a 100755 --- a/filters/001-move-gits-to-temp.sh +++ b/filters/001-move-gits-to-temp.sh @@ -26,7 +26,9 @@ set -o pipefail temp=$2 -if [ ! -e "${TARGET}/github" ]; then exit; fi +if [ ! -e "${TARGET}/github" ]; then + exit; +fi list=${temp}/git-to-move.txt find "${TARGET}/github" -maxdepth 2 -mindepth 2 -type d -exec bash -c 'realpath --relative-to="${1}" "$2"' _ "${TARGET}/github" {} \; > "${list}" @@ -37,7 +39,9 @@ mkdir -p "${gits}" if [ -s "${list}" ]; then while IFS= read -r repo; do src=${TARGET}/github/${repo}/.git - if [ ! -e "${src}" ]; then continue; fi + if [ ! -e "${src}" ]; then + continue; + fi mkdir -p "$(dirname "${gits}/${repo}")" mv "${src}" "${gits}/${repo}" done < "${list}" diff --git a/filters/050-delete-long-lines.sh b/filters/050-delete-long-lines.sh index 85e27c21..7f867844 100755 --- a/filters/050-delete-long-lines.sh +++ b/filters/050-delete-long-lines.sh @@ -41,7 +41,9 @@ candidates=${temp}/files-to-check-line-lengths.txt find "${home}" -type f -name '*.java' -print > "${candidates}" while IFS= read -r f; do length=$(LC_ALL=C awk '{ print length($0) }' < "${f}" | sort -n | tail -1) - if [ -z "${length}" ]; then continue; fi + if [ -z "${length}" ]; then + continue; + fi if [ "${length}" -gt "${max}" ]; then echo "${f}" >> "${list}" rm "${f}" diff --git a/filters/080-delete-symlinks.sh b/filters/080-delete-symlinks.sh index 2d4577f3..63a49cfa 100755 --- a/filters/080-delete-symlinks.sh +++ b/filters/080-delete-symlinks.sh @@ -34,7 +34,9 @@ touch "${list}" while true; do slice=${temp}/symlinks-to-delete.txt find "${home}" -mindepth 1 -type l -print > "${slice}" - if [ ! -s "${slice}" ]; then break; fi + if [ ! -s "${slice}" ];then + break; + fi while IFS= read -r link; do rm "${link}" echo "${link}" >> "${list}" diff --git a/filters/090-delete-empty-directories.sh b/filters/090-delete-empty-directories.sh index ab036662..f3f97593 100755 --- a/filters/090-delete-empty-directories.sh +++ b/filters/090-delete-empty-directories.sh @@ -34,7 +34,9 @@ touch "${list}" while true; do slice=${temp}/empty-directories-to-delete.txt find "${home}" -mindepth 1 -type d -empty -print > "${slice}" - if [ ! -s "${slice}" ]; then break; fi + if [ ! -s "${slice}" ]; then + break + fi while IFS= read -r dir; do rm -r "${dir}" echo "${dir}" >> "${list}" diff --git a/filters/999-move-gits-back.sh b/filters/999-move-gits-back.sh index 873eb215..cdfd02b7 100755 --- a/filters/999-move-gits-back.sh +++ b/filters/999-move-gits-back.sh @@ -26,7 +26,9 @@ set -o pipefail temp=$2 -if [ ! -e "${temp}/gits" ]; then exit; fi +if [ ! -e "${temp}/gits" ]; then + exit; +fi repos=${temp}/git-repos-moving-back.txt @@ -35,7 +37,9 @@ find "${temp}/gits" -maxdepth 2 -mindepth 2 -type d -exec bash -c 'realpath --re if [ -s "${repos}" ]; then while IFS= read -r repo; do dest=${TARGET}/github/${repo} - if [ ! -e "${dest}" ]; then continue; fi + if [ ! -e "${dest}" ]; then + continue; + fi mv "${temp}/gits/${repo}" "${dest}/.git" done < "${repos}" fi diff --git a/help/parallel.sh b/help/parallel.sh index 30778e79..8defec29 100755 --- a/help/parallel.sh +++ b/help/parallel.sh @@ -25,7 +25,9 @@ set -o pipefail jobs=$1 x=$2 -if [ -z "${x}" ]; then x=1; fi +if [ -z "${x}" ]; then + x=1; +fi cores=$(echo "$(nproc) * ${x}" | bc) args=( diff --git a/metrics/rfvc.sh b/metrics/rfvc.sh index 15397f5a..c4489e06 100755 --- a/metrics/rfvc.sh +++ b/metrics/rfvc.sh @@ -32,7 +32,7 @@ base=$(basename "${java}") # To check that file was added in commit any time if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; then my_rvc=$(git log --pretty=format:"%h" "${java}" | wc -l) - ((my_rvc+=1)) + my_rvc=$((my_rvc+1)) files=$(git ls-tree -r "$(git branch --show-current)" --name-only) all_rvcs=0 @@ -46,8 +46,8 @@ if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; t rest='' # and there is no 'rest' fi rvc=$(git log --pretty=format:"%h" "$first" | wc -l) - ((rvc+=1)) - ((all_rvcs+=rvc)) + rvc=$((rvc+1)) + all_rvcs=$((all_rvcs+rvc)) files=$rest done rfvc=$(python3 -c "print(${my_rvc} / ${all_rvcs})") diff --git a/metrics/rfvh.sh b/metrics/rfvh.sh index 0aa4fdd3..86dda02d 100755 --- a/metrics/rfvh.sh +++ b/metrics/rfvh.sh @@ -45,7 +45,7 @@ if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; t rest='' # and there is no 'rest' fi rvh=$(git log -L:"class\s:${first}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Evc "^\+\+\+\s\S+$") - ((all_rvhs+=rvh)) + all_rvhs=$((all_rvhs+rvh)) files=$rest done rfvh=$(python3 -c "print(${my_rvh} / ${all_rvhs})") diff --git a/steps/clone.sh b/steps/clone.sh index 20eb9d22..2c6081b9 100755 --- a/steps/clone.sh +++ b/steps/clone.sh @@ -41,8 +41,12 @@ declare -i repo=0 sh="$(dirname "$0")/clone-repo.sh" while IFS=',' read -r r tag tail; do repo=$((repo+1)) - if [ -z "${tag}" ]; then tag='master'; fi - if [ "${tag}" = '.' ]; then tag='master'; fi + if [ -z "${tag}" ]; then + tag='master'; + fi + if [ "${tag}" = '.' ]; then + tag='master'; + fi if [ -e "${TARGET}/github/${r}" ]; then echo "${r}: Git repo is already here (${tail})" else diff --git a/steps/install.sh b/steps/install.sh index 6aae16e8..610f12c7 100755 --- a/steps/install.sh +++ b/steps/install.sh @@ -82,7 +82,7 @@ if "${LOCAL}/help/is-linux.sh"; then "${LOCAL}/help/sudo.sh" apt-get install --yes coreutils fi -function install_package() { +install_package() { local PACKAGE=$1 if ! eval "$PACKAGE" --version >/dev/null 2>&1; then if "${LOCAL}/help/is-linux.sh"; then diff --git a/steps/lint.sh b/steps/lint.sh index 25e90e5f..f3b2c0ee 100755 --- a/steps/lint.sh +++ b/steps/lint.sh @@ -70,4 +70,6 @@ for mask in *.sh *.py *.rb *.yml *.java Makefile; do -not -path "$(realpath "${LOCAL}")/test-zone/**" \ -not -path "$(realpath "${LOCAL}")/venv/**") done -if [[ "${failed}" = "true" ]]; then exit; fi +if [[ "${failed}" = "true" ]]; then + exit; +fi diff --git a/steps/measure-file.sh b/steps/measure-file.sh index 9f40a751..27e1043e 100755 --- a/steps/measure-file.sh +++ b/steps/measure-file.sh @@ -51,5 +51,5 @@ echo "${metrics}" | { done echo "$(echo "${metrics}" | wc -w | xargs) scripts \ collected $(find "$(dirname "${javam}")" -type f -name "$(basename "${javam}").*" | wc -l | xargs) metrics (sum=${sum}) \ -for $(basename "${java}") (${pos}/${total})$("${LOCAL}/help/tdiff.sh" "${start}")" +for: $(basename "${java}") (${pos}/${total})$("${LOCAL}/help/tdiff.sh" "${start}")" } diff --git a/steps/report.sh b/steps/report.sh index 095991e9..29aa26f6 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -74,7 +74,9 @@ for idx in "${!groups[@]}"; do else group_metrics=$(grep -oE ".*\b${groups[$idx]}\b.*" "${list}" || :) fi - if [[ $(printf "%s\n" "${group_metrics[@]}" | grep -c "item") -eq 0 ]]; then continue; fi + if [[ $(printf "%s\n" "${group_metrics[@]}" | grep -c "item") -eq 0 ]]; then + continue; + fi printf "\\item %s\n" "${groups[$idx]}" >> "${st_list}" printf "\\\\begin{itemize}\n" >> "${st_list}" while IFS= read -r metric; do diff --git a/steps/unregister.sh b/steps/unregister.sh index 1aa33721..902af6b7 100755 --- a/steps/unregister.sh +++ b/steps/unregister.sh @@ -41,7 +41,9 @@ echo "${head}" > "${csv}" declare -i total=0 declare -i good=0 while IFS=',' read -r r tag tail; do - if [ -z "${r}" ]; then continue; fi + if [ -z "${r}" ]; then + continue; + fi total=$((total+1)) if [ ! -e "${TARGET}/github/${r}" ]; then echo "The clone of ${r} is absent, unregistered"