-
Notifications
You must be signed in to change notification settings - Fork 65
73 lines (60 loc) · 2.15 KB
/
enforce-image-size.yml
File metadata and controls
73 lines (60 loc) · 2.15 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
name: LiveLabs Image Validation
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
jobs:
check-images:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install ffmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Detect oversized images (>1280px)
shell: bash
run: |
set -euo pipefail
MAX=1280
git fetch --no-tags --prune origin "${GITHUB_BASE_REF}:${GITHUB_BASE_REF}" || true
mapfile -d '' files < <(
git diff --name-only --diff-filter=AM -z "origin/${GITHUB_BASE_REF}...HEAD" -- \
'*.png' '*.jpg' '*.jpeg' '*.PNG' '*.JPG' '*.JPEG' || true
)
bad=0
for f in "${files[@]}"; do
[[ -f "$f" ]] || continue
dims="$(ffprobe -v error -select_streams v:0 \
-show_entries stream=width,height \
-of csv=p=0:s=x "$f" || true)"
if [[ -z "$dims" ]]; then
echo "Skipping unreadable image: $f"
continue
fi
w="${dims%x*}"
h="${dims#*x}"
if [[ "$w" -gt "$MAX" || "$h" -gt "$MAX" ]]; then
echo "::error file=$f::${f} is ${w}x${h}. Max allowed is ${MAX}px (either dimension)."
bad=1
fi
done
if [[ "$bad" -eq 1 ]]; then
echo ""
echo "One or more images exceed ${MAX}px."
echo "Please fix this locally in your fork."
echo ""
echo "Note: this script requires 'ffmpeg' to be installed on your system."
echo " macOS (Homebrew): brew install ffmpeg"
echo " Ubuntu/Debian: sudo apt-get install ffmpeg"
echo ""
echo "From the root directory of your workshop (not the repo root!), run:"
echo " ../_imgscript/resize-image.sh"
echo ""
echo "The script will only resize images whose width or height is greater than ${MAX}px."
exit 1
fi