Skip to content

fix version command & remove duplication with the server version subcommand#539

Merged
irees merged 4 commits intomainfrom
version-subcommand
Jan 6, 2026
Merged

fix version command & remove duplication with the server version subcommand#539
irees merged 4 commits intomainfrom
version-subcommand

Conversation

@drewda
Copy link
Copy Markdown
Member

@drewda drewda commented Dec 20, 2025

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.go

    • Enhanced getVersion() to first check info.Main.Version for version info (supports go install scenarios)
    • Improved ldflags parsing with proper index-based extraction
    • Added nil check for BuildInfo to prevent potential panics
    • Removed unused embed import
  • Removed duplicate code from cmds/server_cmd.go

    • Removed redundant VersionInfo struct, getVersion() function, and versionCommand implementation
    • Cleaned up unused imports (runtime/debug, strings, tl)
  • Simplified cmd/transitland/main.go

    • Replaced local getVersion() implementation with reference to centralized tl.Version
    • Added tag variable and init() function to support ldflags override
    • Removed unused imports (embed, runtime/debug, strings)
  • Updated .github/workflows/release.yml

    • Added -buildvcs=true flag to all build commands (Linux, macOS amd64, macOS arm64)
    • Ensures automatic VCS metadata embedding in release binaries

Benefits

  • Single source of truth for version information
  • Improved version detection supporting both VCS stamping and go install scenarios
  • Reduced code duplication across the codebase
  • More robust nil checking prevents potential runtime panics

@drewda drewda marked this pull request as ready for review December 30, 2025 15:30
Copilot AI review requested due to automatic review settings December 30, 2025 15:30
Copy link
Copy Markdown
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 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.go with improved parsing logic
  • Removed duplicate VersionInfo and getVersion() implementations from multiple files
  • Added -buildvcs=true flag 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.

@irees irees merged commit 7acdeba into main Jan 6, 2026
6 checks passed
@irees irees deleted the version-subcommand branch January 6, 2026 09:35
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