Repository Public
1#!/bin/bash2# Re-extracts the platform-neutral ORIX Astra modules at a given commit into Packages/AstraKit and re-applies the3# local patch set (Packages/AstraKit/Patches/*.patch, in name order). ORIX Astra is only ever read: the script uses4# `git archive` on a commit, never the working tree, and never writes to that repository.5#6# Scripts/sync-astra.sh <commit> re-vendor that Astra commit, apply patches, rewrite SNAPSHOT.md7# Scripts/sync-astra.sh --verify check that the vendored tree is exactly "recorded commit + patches"8#9# Environment: ASTRA_REPO = path of the ORIX Astra repository (default: ../ORIXAstra next to this repository).10#11# Layout mapping (Astra -> Packages/AstraKit):12# Packages/<Module>/Sources/* -> Sources/<Module>/*13# Tests/<Module>Tests/* -> Tests/<Module>Tests/*14# LICENSE -> LICENSE-ASTRA15# Package.swift, SNAPSHOT.md, README.md and Patches/ belong to ORIX Sheet and are not touched by the extraction16# (SNAPSHOT.md is regenerated at the end).17set -euo pipefail1819MODULES=(AstraCore AstraProviders AstraAgents)2021ROOT="$(cd "$(dirname "$0")/.." && pwd)"22KIT="$ROOT/Packages/AstraKit"23ASTRA="${ASTRA_REPO:-$ROOT/../ORIXAstra}"24SNAPSHOT="$KIT/SNAPSHOT.md"2526die() { echo "sync-astra: $*" >&2; exit 1; }2728[ -d "$ASTRA/.git" ] || die "ORIX Astra repository not found at $ASTRA (set ASTRA_REPO)"2930# Builds "commit + patches" in directory $2 for commit $1, in the AstraKit layout.31materialise() {32 local commit="$1" out="$2" raw33 raw="$(mktemp -d /tmp/sync-astra-raw.XXXXXX)"34 local paths=(LICENSE)35 for m in "${MODULES[@]}"; do paths+=("Packages/$m/Sources" "Tests/${m}Tests"); done36 git -C "$ASTRA" archive "$commit" "${paths[@]}" | tar -x -C "$raw"37 mkdir -p "$out/Sources" "$out/Tests"38 for m in "${MODULES[@]}"; do39 cp -R "$raw/Packages/$m/Sources" "$out/Sources/$m"40 cp -R "$raw/Tests/${m}Tests" "$out/Tests/${m}Tests"41 done42 cp "$raw/LICENSE" "$out/LICENSE-ASTRA"43 rm -rf "$raw"44 if compgen -G "$KIT/Patches/*.patch" > /dev/null; then45 for p in "$KIT"/Patches/*.patch; do46 (cd "$out" && patch -p1 --silent --no-backup-if-mismatch < "$p") || die "patch $(basename "$p") does not apply to $commit"47 done48 fi49}5051recorded_commit() { sed -n 's/^- Commit: `\([0-9a-f]\{40\}\)`.*/\1/p' "$SNAPSHOT" | head -1; }5253if [ "${1:-}" = "--verify" ]; then54 commit="$(recorded_commit)"; [ -n "$commit" ] || die "no commit recorded in $SNAPSHOT"55 tmp="$(mktemp -d /tmp/sync-astra-verify.XXXXXX)"56 materialise "$commit" "$tmp"57 status=058 for d in Sources Tests LICENSE-ASTRA; do59 diff -r -q "$tmp/$d" "$KIT/$d" || status=160 done61 rm -rf "$tmp"62 [ $status -eq 0 ] && echo "sync-astra: Packages/AstraKit matches ORIX Astra $commit + local patches" || die "vendored tree differs from $commit + patches"63 exit 064fi6566[ $# -eq 1 ] || die "usage: sync-astra.sh <commit> | --verify"67commit="$(git -C "$ASTRA" rev-parse --verify "$1^{commit}")" || die "unknown commit $1"68commit_date="$(git -C "$ASTRA" show -s --format=%cI "$commit")"69commit_subject="$(git -C "$ASTRA" show -s --format=%s "$commit")"70origin="$(git -C "$ASTRA" config --get remote.origin.url || echo unknown)"7172tmp="$(mktemp -d /tmp/sync-astra-new.XXXXXX)"73materialise "$commit" "$tmp"74rm -rf "$KIT/Sources" "$KIT/Tests" "$KIT/LICENSE-ASTRA"75mkdir -p "$KIT"76mv "$tmp/Sources" "$tmp/Tests" "$tmp/LICENSE-ASTRA" "$KIT/"77rm -rf "$tmp"7879{80 echo "# AstraKit snapshot"81 echo82 echo "Generated by \`Scripts/sync-astra.sh\`. Do not edit by hand: change the patch set or re-run the script."83 echo84 echo "- Source repository: ORIX Astra (\`$origin\`)"85 echo "- Commit: \`$commit\`"86 echo "- Commit date: $commit_date"87 echo "- Commit subject: $commit_subject"88 echo "- Modules: ${MODULES[*]} (sources and tests, including test fixtures)"89 echo "- Layout: \`Packages/<Module>/Sources\` -> \`Sources/<Module>\`, \`Tests/<Module>Tests\` -> \`Tests/<Module>Tests\`, \`LICENSE\` -> \`LICENSE-ASTRA\`"90 echo91 echo "## Local patches"92 echo93 if compgen -G "$KIT/Patches/*.patch" > /dev/null; then94 for p in "$KIT"/Patches/*.patch; do95 echo "- \`Patches/$(basename "$p")\`: $(sed -n 's/^Subject: //p' "$p" | head -1)"96 grep '^+++ ' "$p" | sed 's/^+++ [^/]*\// - /; s/\t.*//'97 done98 else99 echo "None. Every file below is byte-identical to the commit above."100 fi101 echo102 echo "## Not vendored"103 echo104 echo "AstraPersistence (GRDB), AstraLocal (MLX), AstraDesign and AstraUI (SwiftUI, iOS) and their tests stay in ORIX Astra."105 echo "\`Package.swift\` here is written for ORIX Sheet (macOS 14, three modules, no third-party dependency)."106 echo107 echo "## Files"108 echo109 for top in Sources Tests; do110 for dir in "$KIT/$top"/*/; do111 n=$(find "$dir" -type f | wc -l | tr -d ' ')112 echo "- \`$top/$(basename "$dir")\`: $n files"113 done114 done115 echo116 echo '```'117 (cd "$KIT" && find LICENSE-ASTRA Sources Tests -type f | LC_ALL=C sort | while read -r f; do echo "$(shasum -a 256 "$f" | cut -c1-64) $f"; done)118 echo '```'119} > "$SNAPSHOT"120121echo "sync-astra: vendored ORIX Astra $commit into Packages/AstraKit ($(find "$KIT/Sources" "$KIT/Tests" -type f | wc -l | tr -d ' ') files)"122