1 #!/bin/sh2 # Assert the public output budgets before a release is tagged.3 #4 # scripts/gate-budgets.sh <DIST> <OCI-LAYOUT>5 #6 # Cloudflare Pages accepts at most 20,000 files and 25 MiB per file. The7 # release image budget is 24 MiB per OCI blob (15 MiB target) and 32 MiB for8 # the complete signed layout. The hard limits fail; the target is reported.9 set -eu10 dist=${1:?usage: gate-budgets.sh <DIST> <OCI-LAYOUT>}11 oci=${2:?usage: gate-budgets.sh <DIST> <OCI-LAYOUT>}12 pages_files=2000013 pages_file=$((25 * 1024 * 1024))14 oci_hard=$((24 * 1024 * 1024))15 oci_target=$((15 * 1024 * 1024))16 oci_total=$((32 * 1024 * 1024))17 18 fail() { printf 'budgets: %s\n' "$*" >&2; exit 1; }19 20 [ -d "$dist" ] || fail "$dist is not a directory"21 [ -d "$oci" ] || fail "$oci is not a directory"22 23 files=$(find -L "$dist" -type f | wc -l)24 [ "$files" -le "$pages_files" ] || fail "dist has $files files (limit $pages_files)"25 find -L "$dist" -type f -size +"${pages_file}"c -print | while IFS= read -r file; do26 fail "dist file $file is larger than 25 MiB"27 done28 29 # `find -size` uses 512-byte blocks above; use stat for the exact limit.30 find -L "$dist" -type f -print | while IFS= read -r file; do31 size=$(stat -c %s "$file")32 [ "$size" -le "$pages_file" ] || fail "dist file $file is $size bytes (limit $pages_file)"33 done34 35 find "$oci/blobs/sha256" -type f -print 2>/dev/null | while IFS= read -r blob; do36 size=$(stat -c %s "$blob")37 [ "$size" -le "$oci_hard" ] || fail "OCI blob $blob is $size bytes (limit $oci_hard)"38 if [ "$size" -gt "$oci_target" ]; then39 printf 'budgets: warning: OCI blob %s is %s bytes (target %s)\n' "$blob" "$size" "$oci_target" >&240 fi41 done42 43 total=$(du -sb "$oci" | cut -f1)44 [ "$total" -le "$oci_total" ] || fail "OCI layout is $total bytes (limit $oci_total)"45 printf 'budgets: ok (%s dist files, %s OCI bytes)\n' "$files" "$total"