@@ -186,6 +186,12 @@ jobs:
186186 set -euo pipefail
187187 echo "waiting for db..."
188188 until pg_isready -h $RELEASE-db -p 5432; do sleep 2; done
189+ # the db is ephemeral but survives a helm upgrade that does not
190+ # restart it; skip the restore if it already has data.
191+ if [ "\$(psql -h $RELEASE-db -U postgres -d openhistoricalmap -tAc "SELECT to_regclass('public.users') IS NOT NULL")" = "t" ]; then
192+ echo "db already populated; skipping restore"
193+ exit 0
194+ fi
189195 echo "downloading + restoring backup..."
190196 # handle both plain .sql and gzipped .sql.gz
191197 case "\$BACKUP_URL" in
@@ -225,6 +231,29 @@ jobs:
225231 -f ./values.k3s.preview.yaml \
226232 --wait --timeout=20m
227233
234+ # The web image rewrites fingerprinted assets at startup (same URL, new
235+ # content), so Cloudflare can serve stale JS after a redeploy. Purge the
236+ # preview host's cache. Purge-by-host needs an Enterprise plan; on other
237+ # plans this is a no-op warning (use a "bypass cache" Cache Rule instead).
238+ - name : Purge Cloudflare cache for the preview host
239+ continue-on-error : true
240+ env :
241+ CF_TOKEN : ${{ secrets.STAGING_CF_API_TOKEN }}
242+ CF_ZONE : ${{ secrets.STAGING_CF_ZONE_ID }}
243+ HOST : ${{ steps.n.outputs.host }}
244+ run : |
245+ if [ -z "$CF_TOKEN" ] || [ -z "$CF_ZONE" ]; then
246+ echo "no STAGING_CF_API_TOKEN / STAGING_CF_ZONE_ID; skipping purge"; exit 0
247+ fi
248+ resp=$(curl -sS -X POST \
249+ "https://api.cloudflare.com/client/v4/zones/$CF_ZONE/purge_cache" \
250+ -H "Authorization: Bearer $CF_TOKEN" \
251+ -H "Content-Type: application/json" \
252+ --data "{\"hosts\":[\"$HOST\"]}")
253+ echo "$resp"
254+ echo "$resp" | grep -q '"success":true' \
255+ || echo "::warning::cache purge failed (purge-by-host needs Enterprise; or set a bypass Cache Rule for web-*.ohmstaging.org)"
256+
228257 - name : Summary
229258 if : always()
230259 run : |
0 commit comments