#!/usr/bin/env bash # Every cache-bust stamp web/assemble.sh writes must be readable back. # # Usage: scripts/assemble-stamp.sh FILE PATTERN [FILE PATTERN ...] # # It RECORDS every miss and fails once at the end, naming all of them. Exiting # on the first named one file and never reached the rest, so a shape change # that broke two stamps cost two wasm-pack rebuilds to diagnose -- the slowest # loop in this repo (improvise-x4wv). # # It lives here rather than inside assemble.sh because the gate is the whole # guard and deleting it was invisible: both misses still printed and the # assembly exited 0 (improvise-w8ih). Exercising it in assemble.sh would need a # fabricated web/pkg, which is a second answer to "what does the site assemble # from"; exercising it here needs nothing. scripts/assemble-stamp-test.sh is # the check_the_checker, and CI runs it. set -eu test $# -ge 2 || { echo "usage: assemble-stamp.sh FILE PATTERN [FILE PATTERN ...]" >&2; exit 2; } test $((($# % 2))) -eq 0 || { echo "assemble-stamp: FILE and PATTERN come in pairs" >&2; exit 2; } missing="" while [ $# -ge 2 ]; do file=$1 pattern=$2 shift 2 # -F, because every pattern is a literal and `.` as "any character" would # let a corrupted stamp match -- a pass in the direction that looks like one. if [ -f "$file" ] && grep -qF "$pattern" "$file"; then grep -nF "$pattern" "$file" else echo "assemble: $file is missing the cache-bust stamp: $pattern" >&2 missing="${missing} $file" fi done test -z "$missing" || { echo "assemble: refusing to ship; unstamped:${missing}" >&2 exit 1 }