fix version command & remove duplication with the server version subcommand#539
Merged
fix version command & remove duplication with the server version subcommand#539
version command & remove duplication with the server version subcommand#539Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors version handling by consolidating duplicate version information code into a single location and enhancing the version detection logic. The changes remove redundant implementations from server_cmd.go and main.go while improving the version extraction logic in version.go to support Go's built-in VCS stamping.
- Centralized version information extraction in
version.gowith improved parsing logic - Removed duplicate
VersionInfoandgetVersion()implementations from multiple files - Added
-buildvcs=trueflag to build commands to enable automatic VCS metadata embedding
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| version.go | Enhanced getVersion() to check info.Main.Version first and improved ldflags parsing; added nil check for BuildInfo |
| cmds/server_cmd.go | Removed duplicate version-related code (VersionInfo, getVersion, versionCommand) that was redundant with centralized implementation |
| cmd/transitland/main.go | Replaced local getVersion() with reference to tl.Version; added tag variable and init function for ldflags override |
| .github/workflows/release.yml | Added -buildvcs=true flag to all build commands to enable automatic VCS metadata embedding in binaries |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors version handling by consolidating duplicate version information code into a single location and enhancing the version detection logic.
Changes
Centralized version handling in
version.gogetVersion()to first checkinfo.Main.Versionfor version info (supportsgo installscenarios)BuildInfoto prevent potential panicsembedimportRemoved duplicate code from
cmds/server_cmd.goVersionInfostruct,getVersion()function, andversionCommandimplementationruntime/debug,strings,tl)Simplified
cmd/transitland/main.gogetVersion()implementation with reference to centralizedtl.Versiontagvariable andinit()function to support ldflags overrideembed,runtime/debug,strings)Updated
.github/workflows/release.yml-buildvcs=trueflag to all build commands (Linux, macOS amd64, macOS arm64)Benefits
go installscenarios