Skip to content

Commit 1ca6f85

Browse files
author
Your Name
committed
2 parents 9fe2a41 + f2aada4 commit 1ca6f85

4 files changed

Lines changed: 82 additions & 2 deletions

File tree

.githooks/post-commit

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ echo "$NEW_VERSION" > "$VERSION_FILE"
6060
# Update version in index.html footer
6161
sed -i "s/v${CURRENT_VERSION}/v${NEW_VERSION}/g" index.html
6262

63+
# Update sw.js's CACHE_NAME too — if this drifts behind VERSION, installed
64+
# PWAs never see an update (the browser only reinstalls a service worker
65+
# when sw.js's bytes change). See scripts/check-version-sync.sh.
66+
sed -i "s/nsnvc-tracker-v${CURRENT_VERSION}/nsnvc-tracker-v${NEW_VERSION}/g" sw.js
67+
6368
# Stage and amend the commit
64-
git add VERSION index.html
69+
git add VERSION index.html sw.js
6570
git commit --amend --no-edit
6671

6772
echo ""
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Version sync check
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
paths:
7+
- VERSION
8+
- index.html
9+
- sw.js
10+
push:
11+
branches: [main]
12+
paths:
13+
- VERSION
14+
- index.html
15+
- sw.js
16+
17+
jobs:
18+
check:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- run: bash scripts/check-version-sync.sh

scripts/check-version-sync.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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"

sw.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
const CACHE_NAME = 'nsnvc-tracker-v1.28.0';
1+
// Must be bumped on every deploy that changes index.html/manifest.json —
2+
// this is the only signal that makes the browser treat sw.js as changed and
3+
// install/activate a fresh worker. If it's left stale, already-installed
4+
// PWAs keep serving whatever was cached under the old name indefinitely
5+
// (this has silently happened before: see the v1.25.6 and v1.28.0 fixes).
6+
const CACHE_NAME = 'nsnvc-tracker-v1.29.3';
27
const urlsToCache = [
38
'./',
49
'./index.html',

0 commit comments

Comments
 (0)