From f04ccf787e796e6833d9be641be05dc5eaa992b3 Mon Sep 17 00:00:00 2001 From: Andrey Vasnetsov Date: Sat, 12 Sep 2026 20:42:26 +0200 Subject: [PATCH] Fail PRs that add images over 1MB (#2748) qdrant-landing/static/ is copied verbatim by Hugo, so a full-resolution camera JPEG is downloaded by every reader of the post. 178MB of such files were added in the last 12 months and are still shipping; .git is now 2.4GB. Checks only the files the PR touches, so it costs nothing on other PRs. Escape hatch: the 'allow-large-images' label skips the job. Co-authored-by: Claude Opus 5 (1M context) --- .github/workflows/image-size.yml | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/image-size.yml diff --git a/.github/workflows/image-size.yml b/.github/workflows/image-size.yml new file mode 100644 index 000000000..d52ae8ad8 --- /dev/null +++ b/.github/workflows/image-size.yml @@ -0,0 +1,45 @@ +name: Image Size + +on: + pull_request: + paths: + - '**.jpg' + - '**.jpeg' + - '**.png' + - '**.gif' + - '**.webp' + - '**.svg' + - '**.mp4' + +permissions: + contents: read + pull-requests: read + +jobs: + check-size: + runs-on: ubuntu-latest + if: ${{ !contains(github.event.pull_request.labels.*.name, 'allow-large-images') }} + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - name: Reject images over 1MB + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \ + --paginate --jq '.[] | select(.status != "removed") | .filename' \ + | grep -iE '\.(jpg|jpeg|png|gif|webp|svg|mp4)$' > changed.txt || exit 0 + + big=$(xargs -r -d '\n' du -k --apparent-size 2>/dev/null < changed.txt | awk -F'\t' '$1 > 1024') + [ -n "$big" ] || exit 0 + + echo "$big" | awk -F'\t' '{printf "%6.1f MB %s\n", $1/1024, $2}' | sort -rn + echo + echo "Nothing on the site is displayed wider than ~2000px, and qdrant-landing/static/" + echo "is copied verbatim by Hugo - a 20MB camera JPEG ships to every reader as-is." + echo "Resize before committing:" + echo " mogrify -resize '2000x2000>' -quality 82 -strip " + echo " pngquant --skip-if-larger --ext .png --force " + echo "If a file genuinely has to be this big, add the 'allow-large-images' label." + echo "::error::Images over 1MB in this PR - see the list above" + exit 1