feat: display build commit SHA in CLI version output#176
Conversation
Show the short git commit SHA alongside the version number in `apm --version` (e.g. 0.7.4 (772671a)) to give users and maintainers immediate visibility into which exact commit a build was produced from. - Add __BUILD_SHA__ constant to version.py, injected at build time - Fall back to live git query during development - Build script injects SHA before PyInstaller and restores afterward - Gracefully omits SHA when git is unavailable
There was a problem hiding this comment.
Pull request overview
This PR adds the short git commit SHA to the apm --version output (e.g., Agent Package Manager (APM) CLI version 0.7.4 (772671a)), giving immediate visibility into the exact build source. During development, the SHA is fetched live via git rev-parse; in shipped PyInstaller binaries it is baked in at build time; when git is unavailable it is gracefully omitted.
Changes:
get_build_sha()added toversion.py, with build-time constant fallback to live git query in devprint_versionincli.pyupdated to append the SHA in both Rich and plain-text output pathsscripts/build-binary.shextended to inject the SHA intoversion.pybefore PyInstaller runs and restore the file afterward
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/apm_cli/version.py |
New __BUILD_SHA__ constant and get_build_sha() function with dev/binary fallback logic |
src/apm_cli/cli.py |
print_version updated to append (sha) in both Rich and plain-text branches |
scripts/build-binary.sh |
SHA injection via sed before PyInstaller + restore via mv afterward |
You can also share your feedback on Copilot code review. Take the survey.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
- build-binary.sh: use EXIT trap to guarantee version.py restore on failure - cli.py: extract SHA + version string before Rich/plain-text branch (DRY) - tests: add unit tests for get_build_sha() covering all code paths
danielmeppiel
left a comment
There was a problem hiding this comment.
LGTM — clean, well-scoped feature. No issues found.
What I verified:
trap 'restore' EXITinbuild-binary.shcorrectly handles all exit paths (success, failure, signals)sed -i.bakis macOS-compatible ✓if __BUILD_SHA__:correctly handles bothNoneand""(falsy) ✓getattr(sys, 'frozen', False)guard prevents subprocess spawning in shipped binaries ✓- Tests cover all 5 code paths (build constant, frozen binary, dev fallback, git unavailable, git failure, timeout) ✓
Merge order: This is PR 1 of 3. Merge this first, then rebase #178, then #181.
Description
Display the short git commit SHA alongside the version number in
apm --versionto provide immediate visibility into which exact commit a build was produced from.Before:
Agent Package Manager (APM) CLI version 0.7.4After:
Agent Package Manager (APM) CLI version 0.7.4 (772671a)src/apm_cli/version.py— Add__BUILD_SHA__constant (injected at build time) andget_build_sha()function with git fallback for developmentsrc/apm_cli/cli.py— Append the SHA to the version display in both Rich and plain-text output pathsscripts/build-binary.sh— Inject the SHA intoversion.pybefore PyInstaller runs, then restore afterwardgit rev-parse --short HEADat runtime__BUILD_SHA__at build timeType of change
Testing