SPB Git

Repository Public

sync-astra.sh 7.0 KB 142 lines shellscript

1#!/bin/bash2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : ORIX Docs8# File             : Scripts/sync-astra.sh9# Description      : Re-vendors the ORIX Astra modules used by10#                    Packages/ORIXDocsAI (AstraCore, AstraProviders,11#                    AstraAgents, AstraLocal), their tests, the test fixtures12#                    and the model catalogue from one COMMITTED revision of an13#                    ORIX Astra checkout. The files are taken with `git14#                    archive`, so uncommitted work in that checkout never leaks15#                    in and the checkout itself is only read. After the copy:16#                    Vendor/patches/*.patch are applied (in name order),17#                    Vendor/ASTRA_REVISION is rewritten, the bundled catalogue18#                    of DocLocalModels is refreshed, and a summary of what19#                    changed is printed. Usage: Scripts/sync-astra.sh [--check]20#                    [<astra-checkout> [<revision>]] <astra-checkout> default:21#                    $ORIX_ASTRA_DIR, else ../ORIXAstra beside this repository22#                    <revision> default: HEAD of that checkout; any commit-ish23#                    (tag, branch, hash) --check compare only: exit 1 when24#                    Vendor/ differs from the recorded revision (+ patches);25#                    nothing is written26# Module           : Scripts27# Repository       : https://git.spboucher.ai/orix-docs28# Created          : 2026-11-2229# Last Modified    : 2026-11-2230#31# Author           : Simon-Pierre Boucher32# Position         : Professor of Finance33# Institution      : Université du Québec en Outaouais (UQO)34# Organization     : SP Boucher35# Website          : https://spboucher.ai36# Git              : https://git.spboucher.ai37#38# Preferred Contact: support@spboucher.ai39# Technical Contact: dev@spboucher.ai40# Security/Admin   : admin@spboucher.ai41#42# Copyright (c) 202643# Simon-Pierre Boucher44# All rights reserved where applicable. This file is governed by the45# applicable project license, copyright notices and relevant law.46# Existing third-party rights and notices remain unaffected.47#48# License          : None specified (no license file in this repository)49#50# Do not embed credentials, private keys, access tokens,51# certificates or confidential personal information.52#53# =============================================================================54# END OF SP BOUCHER SOURCE HEADER55# =============================================================================5657set -euo pipefail58ROOT="$(cd "$(dirname "$0")/.." && pwd)"59VENDOR="$ROOT/Packages/ORIXDocsAI/Vendor"60BUNDLED_CATALOG="$ROOT/Packages/ORIXDocsAI/Sources/DocLocalModels/Resources/catalog.json"61MODULES=(AstraCore AstraProviders AstraAgents AstraLocal)6263CHECK=064if [ "${1:-}" = "--check" ]; then CHECK=1; shift; fi65ASTRA="${1:-${ORIX_ASTRA_DIR:-$ROOT/../ORIXAstra}}"66[ -d "$ASTRA" ] || { echo "error: no ORIX Astra checkout at $ASTRA" >&2; exit 2; }67ASTRA="$(cd "$ASTRA" && pwd)"68git -C "$ASTRA" rev-parse --git-dir >/dev/null 2>&1 || { echo "error: $ASTRA is not a git checkout" >&2; exit 2; }6970if [ "$CHECK" = 1 ]; then71  WANT="${2:-$(tr -d '[:space:]' < "$VENDOR/ASTRA_REVISION")}"72else73  WANT="${2:-HEAD}"74fi75REV="$(git -C "$ASTRA" rev-parse --verify --quiet "$WANT^{commit}")" || { echo "error: $WANT is not a commit of $ASTRA" >&2; exit 2; }76OLD="$(tr -d '[:space:]' < "$VENDOR/ASTRA_REVISION" 2>/dev/null || true)"7778# What is taken from the Astra tree, and where it lands under Vendor/.79# AstraUI is not vendored; only the catalogue it bundles, which one AstraLocal test reads from the source tree.80PATHS=(LICENSE docs/catalog Tests/AstraLocalFixtures Packages/AstraUI/Sources/Resources/catalog.json)81for m in "${MODULES[@]}"; do PATHS+=("Packages/$m/Sources" "Tests/${m}Tests"); done82for p in "${PATHS[@]}"; do83  git -C "$ASTRA" cat-file -e "$REV:$p" 2>/dev/null || { echo "error: $p does not exist at $REV" >&2; exit 2; }84done8586STAGE="$(mktemp -d "${TMPDIR:-/tmp}/orixdocs-sync-astra.XXXXXX")"87trap 'rm -rf "$STAGE"' EXIT88mkdir -p "$STAGE/new"89git -C "$ASTRA" archive --format=tar "$REV" -- "${PATHS[@]}" | tar -x -C "$STAGE/new"9091# Minimal, recorded adaptations (see Vendor/README.md). A patch that no longer applies stops the sync: nothing is written.92shopt -s nullglob93PATCHES=("$VENDOR"/patches/*.patch)94for patch in "${PATCHES[@]}"; do95  if ! (cd "$STAGE/new" && patch -p1 --silent --forward < "$patch"); then96    echo "error: $(basename "$patch") does not apply to $REV. Rework the patch (or drop it if Astra fixed the problem), then run again." >&297    exit 398  fi99done100find "$STAGE/new" \( -name '*.orig' -o -name '*.rej' -o -name .DS_Store \) -delete101102# The same layout for what is vendored now, so the two trees can be compared.103mkdir -p "$STAGE/old"104for p in "${PATHS[@]}"; do105  [ -e "$VENDOR/$p" ] || continue106  mkdir -p "$STAGE/old/$(dirname "$p")"; cp -R "$VENDOR/$p" "$STAGE/old/$p"107done108find "$STAGE/old" -name .DS_Store -delete109110SUMMARY="$(diff -rq "$STAGE/old" "$STAGE/new" 2>/dev/null | sed -e "s|$STAGE/old|Vendor|g" -e "s|$STAGE/new|Astra|g" || true)"111ADDED=$(printf '%s\n' "$SUMMARY" | grep -c '^Only in Astra' || true)112REMOVED=$(printf '%s\n' "$SUMMARY" | grep -c '^Only in Vendor' || true)113CHANGED=$(printf '%s\n' "$SUMMARY" | grep -c '^Files ' || true)114115echo "ORIX Astra checkout : $ASTRA"116echo "recorded revision   : ${OLD:-none}"117echo "target revision     : $REV ($(git -C "$ASTRA" log -1 --format='%cs %s' "$REV"))"118echo "patches applied     : ${#PATCHES[@]}"119echo "difference          : $CHANGED changed, $ADDED added, $REMOVED removed (files or folders)"120[ -n "$SUMMARY" ] && printf '%s\n' "$SUMMARY" | sed 's/^/  /'121if [ -n "$OLD" ] && [ "$OLD" != "$REV" ] && git -C "$ASTRA" cat-file -e "$OLD^{commit}" 2>/dev/null; then122  echo "Astra commits $OLD..$REV touching the vendored paths:"123  git -C "$ASTRA" log --format='  %h %cs %s' "$OLD..$REV" -- "${PATHS[@]}" | head -40124  git -C "$ASTRA" diff --shortstat "$OLD" "$REV" -- "${PATHS[@]}" | sed 's/^/  /'125fi126127if [ "$CHECK" = 1 ]; then128  if [ -n "$SUMMARY" ]; then echo "CHECK FAILED: Vendor/ is not $REV plus Vendor/patches. Vendored files must never be edited by hand." >&2; exit 1; fi129  if ! cmp -s "$VENDOR/docs/catalog/catalog.json" "$BUNDLED_CATALOG"; then echo "CHECK FAILED: the bundled catalogue differs from Vendor/docs/catalog/catalog.json." >&2; exit 1; fi130  echo "CHECK OK: Vendor/ is exactly $REV plus ${#PATCHES[@]} patch(es)."131  exit 0132fi133134for p in "${PATHS[@]}"; do135  rm -rf "${VENDOR:?}/$p"136  mkdir -p "$VENDOR/$(dirname "$p")"; cp -R "$STAGE/new/$p" "$VENDOR/$p"137done138echo "$REV" > "$VENDOR/ASTRA_REVISION"139mkdir -p "$(dirname "$BUNDLED_CATALOG")"140cp "$VENDOR/docs/catalog/catalog.json" "$BUNDLED_CATALOG"141echo "Vendor/ now holds $REV. Next: (cd Packages/ORIXDocsAI && ORIXAI_NO_MLX=1 swift test) and the AstraLocalTests, then commit."142
Files main
Menu

Theme