-
Notifications
You must be signed in to change notification settings - Fork 527
265 lines (217 loc) · 9.69 KB
/
Copy pathimage-check.yml
File metadata and controls
265 lines (217 loc) · 9.69 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Image Format & Resolution Check
on:
push:
paths:
- "website/versioned_docs/version-acs_cc/project/**"
- "website/versioned_docs/version-fils_en/project/**"
pull_request:
jobs:
check-images:
name: Validate Images in versioned_docs project folders
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install image tools
run: |
sudo apt-get update -qq
sudo apt-get install -y imagemagick webp file
- name: Get changed files in versioned_docs project folders
id: changed-files
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
FILES=$(git diff --name-only --diff-filter=ACM FETCH_HEAD HEAD -- \
'website/versioned_docs/version-acs_cc/project/' \
'website/versioned_docs/version-fils_en/project/')
else
BASE=${{ github.event.before }}
if [ "$BASE" = "0000000000000000000000000000000000000000" ]; then
BASE=$(git rev-parse HEAD~1 2>/dev/null || echo "")
fi
if [ -z "$BASE" ]; then
FILES=$(git ls-files \
'website/versioned_docs/version-acs_cc/project/' \
'website/versioned_docs/version-fils_en/project/')
else
FILES=$(git diff --name-only --diff-filter=ACM "$BASE" HEAD -- \
'website/versioned_docs/version-acs_cc/project/' \
'website/versioned_docs/version-fils_en/project/')
fi
fi
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# ── Check for both case-sensitive and case-insensitive duplicates ──
- name: Check for filename duplicates (case-sensitive and case-insensitive)
id: check-duplicates
run: |
ERRORS=0
FILES="${{ steps.changed-files.outputs.files }}"
if [ -z "$FILES" ]; then
echo "No files to check for duplicates."
exit 0
fi
declare -A EXACT_MAP
declare -A LOWERCASE_MAP
echo "══════════════════════════════"
echo "Checking for filename duplicates..."
echo "══════════════════════════════"
while IFS= read -r FILE; do
[ -z "$FILE" ] && continue
[ ! -f "$FILE" ] && continue
FILE_LOWER=$(echo "$FILE" | tr '[:upper:]' '[:lower:]')
# ── Check 1: Case-sensitive duplicate (exact same path) ──
if [ -n "${EXACT_MAP[$FILE]}" ]; then
echo "❌ DUPLICATE DETECTED (case-sensitive / exact match):"
echo " - ${EXACT_MAP[$FILE]}"
echo " - $FILE"
echo " → Same file path appears multiple times in changes"
ERRORS=$((ERRORS + 1))
continue
fi
EXACT_MAP[$FILE]="$FILE"
# ── Check 2: Case-insensitive duplicate (differs only by case) ──
if [ -n "${LOWERCASE_MAP[$FILE_LOWER]}" ]; then
echo "❌ DUPLICATE DETECTED (case-insensitive conflict):"
echo " - ${LOWERCASE_MAP[$FILE_LOWER]}"
echo " - $FILE"
echo " → These files differ only by case and will conflict on Windows/macOS"
ERRORS=$((ERRORS + 1))
continue
fi
LOWERCASE_MAP[$FILE_LOWER]="$FILE"
done <<< "$FILES"
echo "══════════════════════════════"
if [ "$ERRORS" -gt 0 ]; then
echo "$ERRORS duplicate(s) found."
echo "duplicate_errors=$ERRORS" >> $GITHUB_OUTPUT
exit 1
else
echo "✅ No duplicates found (case-sensitive or case-insensitive)."
echo "duplicate_errors=0" >> $GITHUB_OUTPUT
fi
- name: Check image format, resolution, and file size
run: |
ERRORS=0
MAX_WIDTH=1024
MAX_HEIGHT=768
MAX_FILE_SIZE=389120 # 380KB in bytes (380 * 1024)
FILES="${{ steps.changed-files.outputs.files }}"
if [ -z "$FILES" ]; then
echo "No files found in versioned_docs project folders – skipping checks."
exit 0
fi
while IFS= read -r FILE; do
[ -z "$FILE" ] && continue
[ ! -f "$FILE" ] && continue
echo "──────────────────────────────"
echo "Checking: $FILE"
EXT="${FILE##*.}"
EXT_LOWER=$(echo "$EXT" | tr '[:upper:]' '[:lower:]')
if [ "$EXT_LOWER" = "md" ]; then
echo " Markdown file – skipping image checks"
continue
fi
if [ "$EXT_LOWER" != "svg" ] && [ "$EXT_LOWER" != "webp" ]; then
echo " FAIL – Invalid extension: .$EXT_LOWER (only .svg and .webp are allowed)"
ERRORS=$((ERRORS + 1))
continue
fi
MIME_TYPE=$(file --mime-type -b "$FILE")
echo " Detected MIME type: $MIME_TYPE"
if [ "$EXT_LOWER" = "webp" ]; then
if [ "$MIME_TYPE" != "image/webp" ]; then
echo " FAIL – Extension is .webp but file content is $MIME_TYPE (Possible renamed PNG/JPG)"
ERRORS=$((ERRORS + 1))
continue
fi
elif [ "$EXT_LOWER" = "svg" ]; then
if [ "$MIME_TYPE" != "image/svg+xml" ] && [ "$MIME_TYPE" != "text/xml" ]; then
echo " FAIL – Extension is .svg but file content is $MIME_TYPE"
ERRORS=$((ERRORS + 1))
continue
fi
if [ "$MIME_TYPE" = "text/xml" ]; then
if ! grep -q "<svg" "$FILE"; then
echo " FAIL – File is XML but does not contain SVG tag"
ERRORS=$((ERRORS + 1))
continue
fi
fi
fi
echo " Format & Content OK (.$EXT_LOWER)"
# ── File Size Check (applies to all images including SVG) ──
FILE_SIZE=$(stat -c%s "$FILE")
FILE_SIZE_KB=$((FILE_SIZE / 1024))
echo " File size: ${FILE_SIZE_KB}KB (${FILE_SIZE} bytes)"
if [ "$FILE_SIZE" -gt "$MAX_FILE_SIZE" ]; then
echo " FAIL – File size ${FILE_SIZE_KB}KB exceeds limit of 380KB"
ERRORS=$((ERRORS + 1))
else
echo " File size OK"
fi
# ── Resolution check (skip for SVG – they are vector) ──────
if [ "$EXT_LOWER" = "svg" ]; then
echo " SVG is vector – resolution check skipped"
continue
fi
DIMENSIONS=$(identify -format "%wx%h" "$FILE" 2>/dev/null)
if [ -z "$DIMENSIONS" ]; then
echo " FAIL – Could not read dimensions (File might be corrupted)"
ERRORS=$((ERRORS + 1))
continue
fi
WIDTH=$(echo "$DIMENSIONS" | cut -d'x' -f1)
HEIGHT=$(echo "$DIMENSIONS" | cut -d'x' -f2)
echo " Dimensions: ${WIDTH}x${HEIGHT}"
if [ "$WIDTH" -gt "$MAX_WIDTH" ] || [ "$HEIGHT" -gt "$MAX_HEIGHT" ]; then
echo " FAIL – Resolution ${WIDTH}x${HEIGHT} exceeds limit of ${MAX_WIDTH}x${MAX_HEIGHT}"
ERRORS=$((ERRORS + 1))
else
echo " Resolution OK"
fi
done <<< "$FILES"
echo "══════════════════════════════"
if [ "$ERRORS" -gt 0 ]; then
echo "$ERRORS image(s) failed validation."
exit 1
else
echo "All images passed validation."
fi
# ── Check for embedded base64 images in SVG files ──
- name: Check for embedded base64 images in SVG files
run: |
FILES="${{ steps.changed-files.outputs.files }}"
if [ -z "$FILES" ]; then
echo "No files to check."
exit 0
fi
ERRORS=0
echo "══════════════════════════════"
echo "Checking for embedded base64 images in SVG files..."
echo "══════════════════════════════"
while IFS= read -r FILE; do
[ -z "$FILE" ] && continue
[ ! -f "$FILE" ] && continue
EXT="${FILE##*.}"
EXT_LOWER=$(echo "$EXT" | tr '[:upper:]' '[:lower:]')
if [ "$EXT_LOWER" != "svg" ]; then
continue
fi
echo "──────────────────────────────"
echo "Checking for embedded images: $FILE"
if grep -o 'data:image/[^;]*' "$FILE"; then
echo "$FILE -> has embedded images"
ERRORS=$((ERRORS + 1))
fi
done <<< "$FILES"
echo "══════════════════════════════"
if [ "$ERRORS" -gt 0 ]; then
echo "$ERRORS SVG file(s) contain embedded base64 images."
exit 1
else
echo "✅ All SVG files are clean – no embedded base64 images found."
fi