Skip to content

Commit 6cf93e4

Browse files
committed
ci(workflow): add lint-image-size job
1 parent a7a1301 commit 6cf93e4

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

.github/workflows/lint.yml

+26-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
if [[ $type =~ ^(WEBP|SVG|ICO)$ ]]; then
8585
echo "✅ $file"
8686
else
87-
>&2 echo "❌ $file incorrect. Please use only webp or svg format 🙏"
87+
>&2 echo "❌ $file incorrect. Please use only webp or svg format. 🙏"
8888
FAILED=1
8989
fi
9090
done
@@ -94,6 +94,31 @@ jobs:
9494
env:
9595
FOLDER: ./static
9696

97+
lint-image-size:
98+
runs-on: ubuntu-22.04
99+
steps:
100+
- name: Check out repository
101+
uses: actions/checkout@v4
102+
103+
- name: Lint image files
104+
run: |
105+
MAX_SIZE=200000
106+
FAILED=0
107+
for file in $(find "$FOLDER" -regextype posix-egrep -regex '.+\.(bmp|ico|jpg|jpeg|png|svg|webp)'); do
108+
size=$(wc -c "$file" | awk '{print $1}')
109+
if [ "$size" -gt "$MAX_SIZE" ]; then
110+
>&2 echo "❌ $file is $size. Please reduce its size to a maximum of $MAX_SIZE. 🙏"
111+
FAILED=1
112+
else
113+
echo "✅ $file"
114+
fi
115+
done
116+
if [ "${FAILED}" = "1" ]; then
117+
exit 1
118+
fi
119+
env:
120+
FOLDER: ./static
121+
97122
report-new-dependencies:
98123
runs-on: ubuntu-22.04
99124
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'

0 commit comments

Comments
 (0)