-
Notifications
You must be signed in to change notification settings - Fork 10
fix: show module version for go install builds #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes introduce a version initialization system that extracts build version information from Go build metadata. A new Changes
Sequence DiagramsequenceDiagram
participant main as main()
participant init as initVersion()
participant buildInfo as debug.ReadBuildInfo()
main->>init: Call initVersion()
alt version == defaultVersion
init->>buildInfo: Read build information
alt Build info available
buildInfo-->>init: Return build info
alt info.Main.Version not empty<br/>and not "(devel)"
init->>init: Set version to info.Main.Version
else Version is empty or "(devel)"
init->>init: Keep defaultVersion
end
else Build info unavailable
buildInfo-->>init: Return error/nil
init->>init: Keep defaultVersion
end
else version != defaultVersion
init->>init: Exit early, preserve preset version
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this 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 introduces runtime version detection using Go's build info when the version is not set via ldflags. The implementation allows the application to automatically determine its version from the module metadata when running in development mode.
- Adds
initVersion()function to detect version fromdebug.ReadBuildInfo()when version equals the default value - Extracts the default version string into a
defaultVersionconstant for consistency - Includes comprehensive test coverage for version initialization scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cmd/wtp/main.go | Introduces defaultVersion constant and calls initVersion() at startup |
| cmd/wtp/version_info.go | Implements version detection logic using build info |
| cmd/wtp/version_info_test.go | Adds tests for version initialization behavior with mocked build info |
| cmd/wtp/main_test.go | Updates test to reference defaultVersion constant instead of hardcoded "dev" string |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cmd/wtp/version_info.go (1)
9-24: Logic is sound. Consider simplifying the nil check.The version initialization logic correctly implements the priority order (preset > build info > default) and handles edge cases like
"(devel)". The implementation is robust.On Line 15, the
info == nilcheck is redundant sinceok == falsealready impliesinfowill benilper Go's convention for boolean returns.Apply this diff to simplify the condition:
info, ok := readBuildInfo() - if !ok || info == nil { + if !ok { return }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
cmd/wtp/main.go(1 hunks)cmd/wtp/main_test.go(1 hunks)cmd/wtp/version_info.go(1 hunks)cmd/wtp/version_info_test.go(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: E2E Tests (macos-latest)
🔇 Additional comments (5)
cmd/wtp/main_test.go (1)
50-51: LGTM! Correct refactoring to use the new constant.The test now references
defaultVersioninstead of the hardcoded"dev"string, improving consistency with the constant introduced inmain.go.cmd/wtp/main.go (2)
15-18: LGTM! Good introduction of the default version constant.The
defaultVersionconstant makes the default value explicit, testable, and reusable across the codebase.
24-24: LGTM! initVersion() correctly placed at program startup.The call is appropriately positioned before app initialization, ensuring version information is available when needed.
cmd/wtp/version_info.go (1)
7-7: LGTM! Good testability pattern.The
readBuildInfovariable enables clean mocking in tests while maintaining production behavior.cmd/wtp/version_info_test.go (1)
10-77: LGTM! Comprehensive test coverage with proper cleanup.The three tests effectively cover all scenarios:
- Using build info when version is default
- Ignoring
"(devel)"from build info- Respecting preset versions
Each test properly saves and restores state using
t.Cleanup, ensuring test isolation.
Summary
Testing
Summary by CodeRabbit
New Features
Tests