|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Fails if VERSION, sw.js's CACHE_NAME, and index.html's footer don't all |
| 3 | +# report the same version. They're three separate hand-edited strings with |
| 4 | +# no shared source of truth, and letting sw.js's CACHE_NAME drift behind the |
| 5 | +# others is what silently strands installed PWAs on stale cached content — |
| 6 | +# the browser only reinstalls a service worker when sw.js's bytes change, |
| 7 | +# so an unbumped CACHE_NAME means no update is ever detected (this has |
| 8 | +# happened twice already: v1.25.6 and v1.28.0/v1.29.2). |
| 9 | +set -euo pipefail |
| 10 | +cd "$(dirname "$0")/.." |
| 11 | + |
| 12 | +VERSION_FILE=$(tr -d ' \n' < VERSION) |
| 13 | +SW_VERSION=$(grep -oP "CACHE_NAME = 'nsnvc-tracker-v\K[0-9.]+(?=')" sw.js || true) |
| 14 | +FOOTER_VERSION=$(grep -oP 'Village Council · v\K[0-9.]+(?=</footer>)' index.html || true) |
| 15 | + |
| 16 | +fail=0 |
| 17 | + |
| 18 | +if [ -z "$SW_VERSION" ]; then |
| 19 | + echo "::error file=sw.js::Could not find CACHE_NAME version string (expected format: const CACHE_NAME = 'nsnvc-tracker-vX.Y.Z';)" |
| 20 | + fail=1 |
| 21 | +fi |
| 22 | +if [ -z "$FOOTER_VERSION" ]; then |
| 23 | + echo "::error file=index.html::Could not find footer version string (expected format: ...Village Council · vX.Y.Z</footer>)" |
| 24 | + fail=1 |
| 25 | +fi |
| 26 | + |
| 27 | +if [ "$fail" -eq 0 ]; then |
| 28 | + if [ "$VERSION_FILE" != "$SW_VERSION" ]; then |
| 29 | + echo "::error file=sw.js::sw.js CACHE_NAME version ($SW_VERSION) does not match VERSION ($VERSION_FILE). Installed PWAs won't detect this deploy as an update until CACHE_NAME is bumped to match." |
| 30 | + fail=1 |
| 31 | + fi |
| 32 | + if [ "$VERSION_FILE" != "$FOOTER_VERSION" ]; then |
| 33 | + echo "::error file=index.html::index.html footer version ($FOOTER_VERSION) does not match VERSION ($VERSION_FILE)." |
| 34 | + fail=1 |
| 35 | + fi |
| 36 | +fi |
| 37 | + |
| 38 | +if [ "$fail" -ne 0 ]; then |
| 39 | + echo "" |
| 40 | + echo "VERSION file: $VERSION_FILE" |
| 41 | + echo "sw.js CACHE_NAME: ${SW_VERSION:-<not found>}" |
| 42 | + echo "index.html footer: ${FOOTER_VERSION:-<not found>}" |
| 43 | + echo "" |
| 44 | + echo "All three must match on every version bump." |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +echo "Version sync check passed: $VERSION_FILE" |
0 commit comments