From 47276dcb6c9c38feda315f98b9ef7b54eae988b5 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Mon, 16 Mar 2026 18:41:19 -0700 Subject: [PATCH] Improve handling of version info in pre-built bundles --- app/routers/debug.py | 23 ++++++++++++++++++++- scripts/publish.sh | 9 ++++++++- tests/test_api.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/app/routers/debug.py b/app/routers/debug.py index c91532c..aa5f457 100644 --- a/app/routers/debug.py +++ b/app/routers/debug.py @@ -1,5 +1,6 @@ import hashlib import importlib.metadata +import json import logging import subprocess import sys @@ -23,6 +24,7 @@ router = APIRouter(tags=["debug"]) LOG_COPY_BOUNDARY_MESSAGE = "STOP COPYING HERE IF YOU DO NOT WANT TO INCLUDE LOGS BELOW" LOG_COPY_BOUNDARY_LINE = "-" * 64 +RELEASE_BUILD_INFO_FILENAME = "build_info.json" LOG_COPY_BOUNDARY_PREFIX = [ LOG_COPY_BOUNDARY_LINE, LOG_COPY_BOUNDARY_LINE, @@ -128,11 +130,30 @@ def _git_output(*args: str) -> str | None: return output or None +def _release_build_info() -> dict[str, Any] | None: + build_info_path = _repo_root() / RELEASE_BUILD_INFO_FILENAME + try: + data = json.loads(build_info_path.read_text()) + except Exception: + return None + + if isinstance(data, dict): + return data + return None + + def _build_application_info() -> DebugApplicationInfo: + release_build_info = _release_build_info() dirty_output = _git_output("status", "--porcelain") + commit_hash = _git_output("rev-parse", "HEAD") + if commit_hash is None and release_build_info is not None: + commit_hash_value = release_build_info.get("commit_hash") + if isinstance(commit_hash_value, str) and commit_hash_value.strip(): + commit_hash = commit_hash_value.strip() + return DebugApplicationInfo( version=_get_app_version(), - commit_hash=_git_output("rev-parse", "HEAD"), + commit_hash=commit_hash, git_branch=_git_output("rev-parse", "--abbrev-ref", "HEAD"), git_dirty=(dirty_output is not None and dirty_output != ""), python_version=sys.version.split()[0], diff --git a/scripts/publish.sh b/scripts/publish.sh index 21b0611..60b8144 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -11,6 +11,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" cd "$SCRIPT_DIR" RELEASE_WORK_DIR="" +RELEASE_BUNDLE_DIR_NAME="Remote-Terminal-for-MeshCore" cleanup_release_build_artifacts() { if [ -d "$SCRIPT_DIR/frontend/prebuilt" ]; then @@ -178,11 +179,17 @@ npm run packaged-build cd "$SCRIPT_DIR" RELEASE_WORK_DIR=$(mktemp -d) -RELEASE_BUNDLE_DIR="$RELEASE_WORK_DIR/remoteterm-prebuilt-frontend-v${VERSION}-${GIT_HASH}" +RELEASE_BUNDLE_DIR="$RELEASE_WORK_DIR/$RELEASE_BUNDLE_DIR_NAME" mkdir -p "$RELEASE_BUNDLE_DIR" git archive "$FULL_GIT_HASH" | tar -x -C "$RELEASE_BUNDLE_DIR" mkdir -p "$RELEASE_BUNDLE_DIR/frontend" cp -R "$SCRIPT_DIR/frontend/prebuilt" "$RELEASE_BUNDLE_DIR/frontend/prebuilt" +cat > "$RELEASE_BUNDLE_DIR/build_info.json" <