Skip to content

feat: display build commit SHA in CLI version output#176

Merged
sergio-sisternes-epam merged 5 commits intomicrosoft:mainfrom
sergio-sisternes-epam:feat/sha-version
Mar 6, 2026
Merged

feat: display build commit SHA in CLI version output#176
sergio-sisternes-epam merged 5 commits intomicrosoft:mainfrom
sergio-sisternes-epam:feat/sha-version

Conversation

@sergio-sisternes-epam
Copy link
Collaborator

@sergio-sisternes-epam sergio-sisternes-epam commented Mar 5, 2026

Description

Display the short git commit SHA alongside the version number in apm --version to provide immediate visibility into which exact commit a build was produced from.

Before: Agent Package Manager (APM) CLI version 0.7.4
After: Agent Package Manager (APM) CLI version 0.7.4 (772671a)

  • src/apm_cli/version.py — Add __BUILD_SHA__ constant (injected at build time) and get_build_sha() function with git fallback for development
  • src/apm_cli/cli.py — Append the SHA to the version display in both Rich and plain-text output paths
  • scripts/build-binary.sh — Inject the SHA into version.py before PyInstaller runs, then restore afterward
Environment SHA source
Development (editable install) git rev-parse --short HEAD at runtime
Shipped binary (PyInstaller) Baked into __BUILD_SHA__ at build time
No git available Gracefully omitted

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

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
Copilot AI review requested due to automatic review settings March 5, 2026 23:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to version.py, with build-time constant fallback to live git query in dev
  • print_version in cli.py updated to append the SHA in both Rich and plain-text output paths
  • scripts/build-binary.sh extended to inject the SHA into version.py before 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.

@sergio-sisternes-epam sergio-sisternes-epam added this to the 0.8.0 milestone Mar 6, 2026
@sergio-sisternes-epam
Copy link
Collaborator Author

@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
Copy link
Collaborator

@danielmeppiel danielmeppiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean, well-scoped feature. No issues found.

What I verified:

  • trap 'restore' EXIT in build-binary.sh correctly handles all exit paths (success, failure, signals)
  • sed -i.bak is macOS-compatible ✓
  • if __BUILD_SHA__: correctly handles both None and "" (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.

@sergio-sisternes-epam sergio-sisternes-epam merged commit c8b8949 into microsoft:main Mar 6, 2026
6 checks passed
@sergio-sisternes-epam sergio-sisternes-epam deleted the feat/sha-version branch March 6, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants