@@ -12,76 +12,6 @@ concurrency:
1212 cancel-in-progress : true
1313
1414jobs :
15- image-size-check :
16- name : Image Size Check
17- runs-on : ubuntu-latest
18- steps :
19- - name : Checkout Repository
20- uses : actions/checkout@v4
21-
22- - name : Get changed files
23- id : changed-files
24- uses : tj-actions/changed-files@v44
25- with :
26- separator : ' \n'
27-
28- - name : Enforce Image Size Limits on Changed Files
29- if : steps.changed-files.outputs.all_changed_files
30- run : |
31- #!/bin/bash
32- set -e
33-
34- IMAGE_LIMIT_MB=2
35- GIF_LIMIT_MB=10
36-
37- OVERSIZED_IMAGES=""
38- OVERSIZED_GIFS=""
39-
40- while IFS= read -r file; do
41- if [ -z "$file" ]; then continue; fi
42- if [ ! -f "$file" ]; then
43- echo "Warning: Changed file not found, skipping: $file"
44- continue
45- fi
46-
47- if [[ "$file" == *.png || "$file" == *.jpg || "$file" == *.jpeg || "$file" == *.svg ]]; then
48- size_in_bytes=$(stat -c%s "$file")
49- limit_in_bytes=$((IMAGE_LIMIT_MB * 1024 * 1024))
50- if [ "$size_in_bytes" -gt "$limit_in_bytes" ]; then
51- size_human=$(ls -lh "$file" | awk '{print $5}')
52- OVERSIZED_IMAGES+=" - $file ($size_human)\n"
53- fi
54- elif [[ "$file" == *.gif ]]; then
55- size_in_bytes=$(stat -c%s "$file")
56- limit_in_bytes=$((GIF_LIMIT_MB * 1024 * 1024))
57- if [ "$size_in_bytes" -gt "$limit_in_bytes" ]; then
58- size_human=$(ls -lh "$file" | awk '{print $5}')
59- OVERSIZED_GIFS+=" - $file ($size_human)\n"
60- fi
61- fi
62- done <<< "${{ steps.changed-files.outputs.all_changed_files }}"
63-
64- # --- Report errors if any oversized files are found ---
65- ERROR_MESSAGE=""
66- if [ -n "$OVERSIZED_IMAGES" ]; then
67- ERROR_MESSAGE+="Found images exceeding the ${IMAGE_LIMIT_MB}MB limit:\n"
68- ERROR_MESSAGE+="${OVERSIZED_IMAGES}"
69- fi
70-
71- if [ -n "$OVERSIZED_GIFS" ]; then
72- ERROR_MESSAGE+="Found GIFs exceeding the ${GIF_LIMIT_MB}MB limit:\n"
73- ERROR_MESSAGE+="${OVERSIZED_GIFS}"
74- fi
75-
76- if [ -n "$ERROR_MESSAGE" ]; then
77- echo -e "::error::Oversized images found in this PR. Please optimize or remove them.\n"
78- echo -e "--------------------------------------------------"
79- echo -e "$ERROR_MESSAGE"
80- echo -e "--------------------------------------------------"
81- exit 1
82- else
83- echo "All changed images are within their size limits. Check passed."
84- fi
8515 # This job is used to render datasheets, but only if they have changed.
8616 # It's a separate job so we don't have to cleanup the machine afterwards.
8717 render-datasheets :
0 commit comments