Skip to content

fix(version): report module version for go-install builds#68

Merged
shreemaan-abhishek merged 1 commit into
masterfrom
fix/version-go-install
Jun 3, 2026
Merged

fix(version): report module version for go-install builds#68
shreemaan-abhishek merged 1 commit into
masterfrom
fix/version-go-install

Conversation

@shreemaan-abhishek
Copy link
Copy Markdown
Contributor

@shreemaan-abhishek shreemaan-abhishek commented Jun 3, 2026

Summary

a7 version reports dev with unknown commit/date when the binary is installed with go install github.com/api7/a7/cmd/a7@v1.0.0. The version fields are only populated via -ldflags -X (Makefile / GoReleaser), which go install never applies.

internal/version now falls back to runtime/debug.ReadBuildInfo():

  • Version: filled from the Go module version (e.g. v1.0.0) when not injected via ldflags
  • Commit / Date: filled from the vcs.revision / vcs.time build settings when available (source builds)
  • ldflags-injected values always take precedence, so make build and GoReleaser output are unchanged

This also fixes a7 update for go-installed binaries: it no longer hits the dev build path and can compare the current version against the latest release.

Test plan

  • New unit tests for the fallback logic (internal/version/version_test.go)
  • go build ./... && go test ./... passes
  • Reproduced the bug and verified the fix with a local module proxy: go install github.com/api7/a7/cmd/a7@<tag> previously printed dev, now prints the tag version
  • Plain go build from a clone now reports version, commit, and build time from VCS info
  • E2E version tests (TestVersion, TestVersion_ContainsCommitInfo) only assert output shape, unaffected

Bug-class audit

Class: build metadata that only exists when ldflags are applied. internal/version is the only ldflags-injected metadata in the repo (checked Makefile and .goreleaser.yml), so no other call sites are affected. The same bug exists in a6 and is fixed by the matching PR api7/a6#55.

Summary by CodeRabbit

  • Chores
    • Enhanced version detection to automatically resolve version, commit, and build date information from Go build metadata, with fallback support for manually injected values.

Binaries installed with 'go install github.com/api7/a7/cmd/a7@<tag>'
bypass the Makefile/GoReleaser ldflags, so 'a7 version' reported
'dev' with unknown commit and date.

Fall back to runtime/debug.ReadBuildInfo: the Go module version fills
Version, and vcs.revision/vcs.time fill Commit/Date for source builds.
Values injected via ldflags still take precedence.

This also fixes 'a7 update' treating go-installed binaries as dev
builds when comparing against the latest release.

Audited for the same bug class: internal/version is the only
ldflags-injected metadata in the repo.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9140332b-3c06-46ee-95d3-e5628efa4f70

📥 Commits

Reviewing files that changed from the base of the PR and between d99f5fa and 725fb69.

📒 Files selected for processing (2)
  • internal/version/version.go
  • internal/version/version_test.go

📝 Walkthrough

Walkthrough

The PR enhances the version package to resolve build metadata from Go's runtime debug info at startup. It imports runtime/debug, adds initialization logic that calls a new resolve() helper to populate version strings from embedded build info while preserving ldflag-set values, and provides comprehensive test coverage for all resolution scenarios.

Changes

Build Metadata Resolution

Layer / File(s) Summary
Version resolution implementation
internal/version/version.go
Imports runtime/debug and adds init() that calls resolve(). The resolve() function conditionally populates Version, Commit, and Date from debug.BuildInfo, preferring existing ldflag values, deriving short commit hashes from vcs.revision, and extracting timestamps from vcs.time.
Resolution test coverage
internal/version/version_test.go
Tests the resolve() function across scenarios: resolving go install module versions, preserving "dev" for devel builds, ldflags precedence over build info, fallback to VCS metadata with commit shortening, and defaults when build info is empty.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning Unit tests only—init() function never invoked/tested. E2E tests build with go build, not go install, so the PR's core fix (go-install scenario) remains untested end-to-end. Add E2E test using go install to verify version/commit/date are populated correctly, and test init() invocation in unit tests via package initialization or TestMain.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding Go build metadata fallback to report module version for go-install builds, which directly addresses the core issue fixed in this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Check ✅ Passed PR adds version metadata reading via runtime/debug for non-sensitive build data (module version, commit hash, build time). No security vulnerabilities found across all 7 categories.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/version-go-install

Comment @coderabbitai help to get the list of available commands and usage tips.

@shreemaan-abhishek shreemaan-abhishek merged commit c0400ff into master Jun 3, 2026
6 checks passed
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.

1 participant