#!/usr/bin/env bash # # prepare_release.sh — replicate the Lyrebird dev repo's committed tree into the # public LyrebirdRelease (mooo) repo, minus the maintainer-only paths that never ship. # # Replaces the manual "export → hand-copy in Finder" step. Works from a clean # `git archive HEAD` of the dev repo (so untracked build junk and Finder " 2"/" 3" # duplicate cruft never leak in), strips the intentional exclusions, then rsyncs the # result over the release working tree with --delete (cleaning stale files) while # preserving the release repo's own .git and local .build. # # Dry-run by default. Pass --apply to actually modify the release working tree. # # Usage: # prepare_release.sh [--dev PATH] [--release PATH] [--apply] [--allow-dirty] # # Defaults: # --dev ~/Documents/src/Lyrebird # --release ~/Documents/src/LyrebirdRelease set -euo pipefail DEV="${HOME}/Documents/src/Lyrebird" RELEASE="${HOME}/Documents/src/LyrebirdRelease" APPLY=0 ALLOW_DIRTY=0 # Paths that are git-tracked in dev but must NOT ship in the public release. # (Verified: these exactly account for the dev↔release tracked-file delta.) EXCLUSIONS=( "legacy" "PLAN.md" "DOC_UPDATE_PLAN.md" "docs/00-working-order.md" "docs/01-completed-working-order.md" "docs/plans" "spikes" ".claude" ".githooks" ".swiftpm" ) # Regex the release repo's origin URL must match — a guard so --apply can never # nuke the wrong directory. Requires the mooo host AND the `Lyrebird` repo path # (so a sibling mooo repo like ShoeGaze can't be mistaken for the release repo). RELEASE_REMOTE_REGEX='realizedsound\.mooo\.com.*/Lyrebird(\.git)?/?$' while [ $# -gt 0 ]; do case "$1" in --dev) DEV="$2"; shift 2 ;; --release) RELEASE="$2"; shift 2 ;; --apply) APPLY=1; shift ;; --allow-dirty) ALLOW_DIRTY=1; shift ;; -h|--help) tail -n +2 "$0" | grep '^#' | sed 's/^# \{0,1\}//' exit 0 ;; *) echo "ERROR: unknown argument '$1'" >&2; exit 2 ;; esac done fail() { echo "ERROR: $*" >&2; exit 1; } # --- Validate repos --------------------------------------------------------- [ -d "$DEV/.git" ] || fail "dev repo not a git repo: $DEV" [ -d "$RELEASE/.git" ] || fail "release repo not a git repo: $RELEASE" RELEASE_URL="$(git -C "$RELEASE" remote get-url origin 2>/dev/null || echo "")" if [[ ! "$RELEASE_URL" =~ $RELEASE_REMOTE_REGEX ]]; then fail "release origin ('$RELEASE_URL') is not the Lyrebird mooo release repo (must match /$RELEASE_REMOTE_REGEX/) — refusing to sync. Wrong --release path?" fi # --- Guard: dev working tree should be committed (we archive HEAD) ----------- if [ -n "$(git -C "$DEV" status --porcelain)" ]; then if [ "$ALLOW_DIRTY" -eq 1 ]; then echo "WARNING: dev repo has uncommitted changes — they will NOT ship (archiving HEAD). Continuing (--allow-dirty)." else fail "dev repo ($DEV) has uncommitted changes. Commit them first (only HEAD ships), or pass --allow-dirty to archive HEAD anyway." fi fi DEV_HEAD="$(git -C "$DEV" rev-parse --short HEAD)" echo "Dev HEAD: $DEV_HEAD ($(git -C "$DEV" log -1 --format=%s))" echo "Release repo: $RELEASE (origin: $RELEASE_URL)" echo "Mode: $([ "$APPLY" -eq 1 ] && echo APPLY || echo DRY-RUN)" echo # --- Stage a pristine tree from git archive --------------------------------- STAGING="$(mktemp -d "${TMPDIR:-/tmp}/lyrebird-release-prep.XXXXXX")" trap 'rm -rf "$STAGING"' EXIT git -C "$DEV" archive --format=tar HEAD | tar -x -C "$STAGING" # Strip the intentional exclusions from the staged tree. echo "Excluding (maintainer-only, never shipped):" for p in "${EXCLUSIONS[@]}"; do if [ -e "$STAGING/$p" ]; then echo " - $p" rm -rf "$STAGING/$p" fi done echo # --- Sync staging → release ------------------------------------------------- # --delete removes release files not present in the staged tree (clears stale # files + accumulated Finder duplicates). Excludes protect the release repo's own # .git and local, non-shipped build/editor state from both transfer and deletion. RSYNC_ARGS=( -a -c --delete --itemize-changes --exclude='.git/' --exclude='.build/' --exclude='.swiftpm/' --exclude='.DS_Store' --exclude='xcuserdata/' --exclude='*.xcuserstate' ) [ "$APPLY" -eq 1 ] || RSYNC_ARGS+=(--dry-run) # Capture itemized output; filter to meaningful lines for display. rsync itemize # codes: leading '>' = content transfer, 'c' = created dir/file, '*deleting' = # removal. Leading '.' = metadata-only (mtime/perms) churn — harmless (git ignores # it), so suppress it from the summary. Content is authoritative via -c (checksum). ITEMS="$(rsync "${RSYNC_ARGS[@]}" "$STAGING/" "$RELEASE/")" MEANINGFUL="$(printf '%s\n' "$ITEMS" | grep -E '^(\*deleting|[>c])' || true)" echo "Content changes + deletions ($([ "$APPLY" -eq 1 ] && echo applied || echo would apply)):" if [ -n "$MEANINGFUL" ]; then printf '%s\n' "$MEANINGFUL" | sed 's/^/ /' else echo " (none — release tree already matches dev content)" fi META_COUNT="$(printf '%s\n' "$ITEMS" | grep -cE '^\.' || true)" echo " [$META_COUNT files: mtime/perms normalized only — no content change, git-invisible]" echo if [ "$APPLY" -eq 1 ]; then echo "Sync complete. Release working tree now mirrors dev HEAD ($DEV_HEAD) minus exclusions." echo echo "Release git status:" git -C "$RELEASE" status --short | sed 's/^/ /' echo echo "Next (run in $RELEASE — pushes need your key/touch):" echo " git -C \"$RELEASE\" add -A" echo " git -C \"$RELEASE\" commit -m \"\"" echo " git -C \"$RELEASE\" tag -a vX.Y.Z -m \"vX.Y.Z: \"" echo " git -C \"$RELEASE\" push origin main && git -C \"$RELEASE\" push origin vX.Y.Z" else echo "Dry-run only. Re-run with --apply to modify the release working tree." fi