Skip to content

Commit

Permalink
Merge branch 'master' of github.com:yegor256/cam
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 21, 2025
2 parents 4cca098 + 68ed9d7 commit 212ae02
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 19 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/bashate.yml
Original file line number Diff line number Diff line change
@@ -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[@]}"
8 changes: 6 additions & 2 deletions filters/001-move-gits-to-temp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down
4 changes: 3 additions & 1 deletion filters/050-delete-long-lines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 3 additions & 1 deletion filters/080-delete-symlinks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 3 additions & 1 deletion filters/090-delete-empty-directories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
8 changes: 6 additions & 2 deletions filters/999-move-gits-back.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 3 additions & 1 deletion help/parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand Down
6 changes: 3 additions & 3 deletions metrics/rfvc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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})")
Expand Down
2 changes: 1 addition & 1 deletion metrics/rfvh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
Expand Down
8 changes: 6 additions & 2 deletions steps/clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion steps/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion steps/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion steps/measure-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")"
}
4 changes: 3 additions & 1 deletion steps/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion steps/unregister.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 212ae02

Please sign in to comment.