#!/usr/bin/env bash # Sync the shared chart module to both thin apps, and re-pin them. # # ops-docs/scripts/sync-chart-module.sh # # The canonical module is scripts/shared/coop_chart.js in THIS repo. The two # consumer repos (member-dashboard, admin-panel) ship BYTE-IDENTICAL copies at # app/coop_chart.js; each app's main.py splices it into PAGE_HTML at import # time. Editing a copy by hand is a dead end: this script overwrites it, and # the repo's tests/test_chart_sync.py goes red on any drift from the pinned # revision. # # What this does: # 1. copies the canonical module over both repos' app/coop_chart.js # 2. regenerates each repo's tests/test_chart_sync.py with the CURRENT # canonical sha256 (the pin CI checks, since CI has no ops-docs checkout) # 3. node --check's the module # 4. runs check-chart-sync.py as the gate — a red check leaves the working # tree dirty so nothing can be silently committed half-synced # # After it passes: commit all three repos (ops-docs + both apps). set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPOS="$(dirname "$(dirname "$HERE")")" # ops-docs/scripts -> ops-docs -> ~/repos CANONICAL="$HERE/shared/coop_chart.js" [ -f "$CANONICAL" ] || { echo "canonical module missing: $CANONICAL" >&2; exit 1; } if command -v node >/dev/null 2>&1; then node --check "$CANONICAL" && echo "node --check canonical: OK" else echo "node not found; skipping node --check (CI runs it)" >&2 fi SHA="$(sha256sum "$CANONICAL" | cut -d' ' -f1)" echo "canonical sha256: $SHA" gen_pin_test() { # local repo="$1" local dir="$REPOS/$repo" mkdir -p "$dir/tests" cat > "$dir/tests/test_chart_sync.py" < $repo/app/coop_chart.js" done python3 "$HERE/check-chart-sync.py"