Skip to content

Commit 6feb39c

Browse files
authored
Add a check for the image sizes (#203)
* Add a file-size checker in a GitHubCI * Add coloring for failed image sizes * Remove verbosity of passing images * Increase limit for gifs to 2000kb * Increase gif limit to 2200 kb
1 parent 45fe93e commit 6feb39c

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

.github/workflows/checks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ jobs:
77
- name: Check out repository
88
uses: actions/checkout@v2
99
- run: bash tools/check.sh
10+
- run: bash tools/check-size.sh

tools/check-size.sh

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

0 commit comments

Comments
 (0)