#!/usr/bin/env bash # The build a phone UPDATES FROM in the release walk's update case. # # scripts/release-walk-before.sh # prints " " # # The update case (scripts/update-walk.ts) is "a phone holds unsent changes, the # Mac moves to a higher schema, the phone updates". The schema is a constant # compiled into the server and the app, so the lower side is a REAL build: the # commit just before the newest schema bump in 's history — the app a phone # had the day before that bump, and the household that app's server wrote. No # knob lowers a build's schema; a walk that faked the step would prove a move # no phone ever makes. # # It moves only when the schema does, so its build (release-walk.sh, # build-) is made once and serves every walk until the next bump. set -euo pipefail refuse() { printf 'FAIL setup: %s\n' "$*" >&2; exit 1; } [[ $# -eq 1 ]] || refuse 'usage: release-walk-before.sh ' ROOT="${RELEASE_WALK_REPO:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" DDL=crates/cotton-store/src/schema/ddl.rs schema_at() { git -C "$ROOT" show "$1:$DDL" 2>/dev/null \ | sed -n 's/^pub const SCHEMA_VERSION: u32 = \([0-9][0-9]*\);.*/\1/p' | head -1 } SHA="$(git -C "$ROOT" rev-parse --verify --quiet "$1^{commit}")" || refuse "$1 is not a commit here" NOW="$(schema_at "$SHA")" [[ -n "$NOW" ]] || refuse "${SHA:0:9} names no SCHEMA_VERSION in $DDL" # The newest commit that changed the constant's own line. BUMP="$(git -C "$ROOT" log -1 --format=%H -G'^pub const SCHEMA_VERSION: u32 = ' "$SHA" -- "$DDL")" [[ -n "$BUMP" ]] || refuse "no commit in ${SHA:0:9}'s history changes SCHEMA_VERSION (a shallow checkout?)" BEFORE="$(git -C "$ROOT" rev-parse --verify --quiet "$BUMP^")" \ || refuse "the schema bump ${BUMP:0:9} has no parent here (a shallow checkout?)" WAS="$(schema_at "$BEFORE")" [[ -n "$WAS" && "$WAS" -lt "$NOW" ]] \ || refuse "${BEFORE:0:9} is at schema ${WAS:-none} and ${SHA:0:9} at $NOW — the update case needs a lower schema to update from" echo "$BEFORE $WAS $NOW"