#!/usr/bin/env bash # # Shared helpers for the workspace-level scripts. # # Layout assumed by every script (see AGENTS.md): # # gpustack-all-lofyer/ # ├── scripts/ # ├── gpustack-ui-lofyer/ frontend fork # └── gpustack-lofyer/ backend fork # # Resolve the workspace root from the calling script's location. WORKSPACE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" UI_REPO="${UI_REPO:-${WORKSPACE_DIR}/gpustack-ui-lofyer}" BACKEND_REPO="${BACKEND_REPO:-${WORKSPACE_DIR}/gpustack-lofyer}" # Private registry (origin) and upstream GitHub remotes for both forks. UI_ORIGIN_URL="${UI_ORIGIN_URL:-ssh://git@git.digiman.live:11022/root/gpustack-ui.git}" UI_UPSTREAM_URL="${UI_UPSTREAM_URL:-https://github.com/gpustack/gpustack-ui.git}" BACKEND_ORIGIN_URL="${BACKEND_ORIGIN_URL:-ssh://git@git.digiman.live:11022/root/gpustack.git}" BACKEND_UPSTREAM_URL="${BACKEND_UPSTREAM_URL:-https://github.com/gpustack/gpustack.git}" # Image coordinates. NAMESPACE="${NAMESPACE:-mesastack}" REPOSITORY="${REPOSITORY:-gpustack}" _name="$(basename "${0}")" log() { echo -e "\033[1;34m[${_name}]\033[0m $*"; } warn() { echo -e "\033[1;33m[${_name}]\033[0m $*" >&2; } fail() { echo -e "\033[1;31m[${_name}]\033[0m $*" >&2; exit 1; } step() { echo -e "\n\033[1;36m==> $*\033[0m"; } require_cmd() { for c in "$@"; do command -v "${c}" >/dev/null 2>&1 || fail "'${c}' is required but not installed" done } require_repos() { [[ -d "${UI_REPO}/.git" ]] || fail "frontend repo missing at ${UI_REPO} (run scripts/bootstrap)" [[ -d "${BACKEND_REPO}/.git" ]] || fail "backend repo missing at ${BACKEND_REPO} (run scripts/bootstrap)" } # Current branch of a repo. repo_branch() { git -C "${1}" rev-parse --abbrev-ref HEAD 2>/dev/null; } # Extract the upstream version from a v-lofyer branch name. # Echoes the version (e.g. v2.2.3) or fails. lofyer_branch_version() { local branch="${1}" if [[ "${branch}" =~ ^(v[0-9]+\.[0-9]+\.[0-9]+[0-9A-Za-z.]*)-lofyer$ ]]; then echo "${BASH_REMATCH[1]}" return 0 fi return 1 } # Verify both forks sit on the same v-lofyer branch and echo the version. resolve_workspace_version() { local ui_branch backend_branch ui_version backend_version ui_branch="$(repo_branch "${UI_REPO}")" backend_branch="$(repo_branch "${BACKEND_REPO}")" ui_version="$(lofyer_branch_version "${ui_branch}")" \ || fail "frontend is on '${ui_branch}', expected a v-lofyer branch" backend_version="$(lofyer_branch_version "${backend_branch}")" \ || fail "backend is on '${backend_branch}', expected a v-lofyer branch" [[ "${ui_version}" == "${backend_version}" ]] \ || fail "version mismatch: frontend=${ui_branch} backend=${backend_branch} (must match)" echo "${ui_version}" }