forked from precice/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-size.sh
executable file
·42 lines (37 loc) · 1.22 KB
/
check-size.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Run this script at the root of the repository to check the size of images
CODE=0
MAXIMUMSIZE=750
MAXIMUMGIFSIZE=2200
RED='\033[0;31m'
NOCOLOR='\033[0m'
# Check tutorials
IGNORE="tools"
tutorials=$(find . -maxdepth 1 -type d -not -name ".*" | grep -vE $IGNORE | sed "s/^.\///")
echo "Limit for regular images: ${MAXIMUMSIZE} kb"
echo "Limit for gifs: ${MAXIMUMGIFSIZE} kb"
# For all tutorials do
for tutorial in $tutorials; do
images=$(find ./"${tutorial}"/images -type f 2> /dev/null | sed "s/^.\///")
for img in $images; do
actualsize=$(du -k "$img" | cut -f 1)
# Check gifs
if [[ "${img}" == *.gif || "${img}" == *.webp || "${img}" == *.webm ]]; then
if [ "${actualsize}" -ge "${MAXIMUMGIFSIZE}" ]; then
echo -e "$img:$RED $actualsize kb exceeds the limit of $MAXIMUMGIFSIZE kb. $NOCOLOR"
CODE=1
else
echo -e "$img: $actualsize kb (Ok)."
fi
else
if [ "${actualsize}" -ge "${MAXIMUMSIZE}" ]; then
echo -e "$img:$RED $actualsize kb exceeds the limit of $MAXIMUMSIZE kb. $NOCOLOR"
CODE=1
else
echo -e "$img: $actualsize kb (Ok)."
fi
fi
done
done
[ ! "$CODE" -eq "0" ] && echo "There have been errors"
exit $CODE