d73ff9b0fb
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
52 lines
2.1 KiB
Python
52 lines
2.1 KiB
Python
"""
|
|
Baked-in build metadata for Hermes Agent.
|
|
|
|
Source installs report their git revision live via ``git rev-parse`` (see
|
|
``hermes_cli/dump.py`` and ``hermes_cli/banner.py``). That doesn't work inside
|
|
the published Docker image because ``.dockerignore`` excludes ``.git``, so
|
|
those callsites fall back to ``"(unknown)"`` / drop the banner suffix entirely.
|
|
|
|
To make ``hermes dump`` and the startup banner identify the exact commit the
|
|
image was built from, the Docker build writes the build-time ``$HERMES_GIT_SHA``
|
|
arg into ``<project_root>/.hermes_build_sha``. This module is the single
|
|
read-side helper consumed by both callsites — keeping the lookup in one place
|
|
so the file path and missing-file behaviour stay consistent.
|
|
|
|
Behaviour:
|
|
|
|
- Returns ``None`` when the file is absent. Source installs and dev images
|
|
built without the ``HERMES_GIT_SHA`` build-arg fall through to live-git
|
|
resolution in the caller, so non-Docker installs are unaffected.
|
|
- Returns ``None`` on any IO / decoding error. The build-sha is a nice-to-have
|
|
for support triage; nothing in the CLI is allowed to crash because of it.
|
|
- Truncates to ``short`` characters (default 8) to match the format used by
|
|
``git rev-parse --short=8`` throughout the codebase.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
# Path is resolved relative to this module so it works regardless of cwd —
|
|
# matches the pattern used by ``banner._resolve_repo_dir``.
|
|
_BUILD_SHA_FILE = Path(__file__).parent.parent / ".hermes_build_sha"
|
|
|
|
|
|
def get_build_sha(short: int = 8) -> Optional[str]:
|
|
"""Return the baked-in build SHA, truncated to ``short`` chars, or None.
|
|
|
|
Reads ``<project_root>/.hermes_build_sha`` if present. The file is
|
|
written by the Dockerfile's ``HERMES_GIT_SHA`` build-arg and contains
|
|
the full 40-character commit hash on a single line.
|
|
"""
|
|
try:
|
|
if not _BUILD_SHA_FILE.is_file():
|
|
return None
|
|
sha = _BUILD_SHA_FILE.read_text(encoding="utf-8").strip()
|
|
except Exception:
|
|
return None
|
|
if not sha:
|
|
return None
|
|
return sha[:short] if short and short > 0 else sha
|