Skip to content

Commit

Permalink
Optimize script
Browse files Browse the repository at this point in the history
  • Loading branch information
dala318 committed Oct 11, 2024
1 parent b563f2e commit ede189e
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions script/check_icon_use.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

verbose=false
if [ "$1" == "-v" ]
then
verbose=true
fi

checkpath="custom_components/waste_collection_schedule/waste_collection_schedule/source/"

whitelist=(
Expand Down Expand Up @@ -423,47 +429,53 @@ whitelist=(
"york_gov_uk.py"
)

# Build a git-exclude and git-include strings
grep_exclude=""
grep_include=""
for excluded in "${whitelist[@]}"
do
grep_exclude="${grep_exclude} \":(exclude)*${excluded}\""
grep_include="${grep_include} ${checkpath}${excluded}"
done

# Initiate pass-state
failed=false

for full_file in $(git grep --name "mdi:" $checkpath)
do
filename=$(basename $full_file)
skip=false
for excluded in "${whitelist[@]}"
do
if [ "$excluded" == "$filename" ]
then
skip=true
fi
done
if [ "$skip" = "false" ]
# Grep for icon definitions in source folder but excude whitelisted
git grep -q mdi: -- "$checkpath" $grep_exclude
if [ $? -eq "0" ]; then
# Exit code == 0 -> match found -> make exit 1
echo "Found icon definitions direcly in source folder!"
failed=true
if [ $verbose = "true" ]
then
echo "File >> $filename has locally declared icons"
failed=true
echo "The following files are not complying:"
echo $(git grep --name mdi: -- "$checkpath" $grep_exclude)
fi
done
echo ""
fi

for excluded in "${whitelist[@]}"
do
git grep -q "mdi:" ${checkpath}${excluded}
if [ "$?" -eq 1 ]
# Grep for non-icon definitions in whitelisted
git grep -L -q mdi: -- $grep_include
if [ $? -eq "0" ]; then
# Exit code == 0 -> match found -> make exit 1
echo "One or more of the whitelisted sources have no icon definitions, remove from whitelist!"
failed=true
if [ $verbose = "true" ]
then
echo "File << $excluded is whitelisted but has no locally declared icons"
failed=true
echo "The following files are not complying:"
echo $(git grep -L mdi: -- $grep_include)
fi
done
echo ""
fi

# Make exit
if [ "$failed" = "true" ];
then
if [ $verbose = "false" ]
then
echo "Run \"./script/check_icon_use.sh -v\" to get a list of files that don't comply"
fi
exit 1
fi
exit 0

# ## This be used instead once whitelisting is no longer needed
# git grep -q "mdi:" custom_components/waste_collection_schedule/waste_collection_schedule/source/
# if [ $? -eq "0" ]; then
# # Exit code == 0 -> match found -> make exit 1
# exit 1
# fi
# # Exit code != 0 -> no match found -> make exit 0
# exit 0

0 comments on commit ede189e

Please sign in to comment.