Skip to content
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

Heighliner should report version info. #225

Open
danbryan opened this issue Mar 6, 2024 · 0 comments
Open

Heighliner should report version info. #225

danbryan opened this issue Mar 6, 2024 · 0 comments

Comments

@danbryan
Copy link
Contributor

danbryan commented Mar 6, 2024

When I heighliner version --long
Then I should see:

  • The project name
  • Server name
  • Version number
  • Commit hash
  • Build tags
  • Go version
  • List of build dependencies with versions

Title

Add Version Support for Heighliner

Description

Request to add version support to Heighliner to enhance user experience and supportability. This would allow users to quickly verify the version, commit hash, build tags, Go version, and dependencies used to build the heighliner binary.

Proposed Feature Details

Implement a new command heighliner version --long that outputs detailed version information, similar to the provided example. This should include:

  • The project name
  • Server name
  • Version number
  • Commit hash
  • Build tags
  • Go version
  • List of build dependencies with versions

Example Output

heighliner version --long
name: heighliner
server_name: heighlinerd
version: x.y.z
commit: <commit_hash>
build_tags: <tags>,
go: go version go1.x.x <platform>
build_deps:
- dependency1@version
- dependency2@version
...

This feature will assist in troubleshooting, enhance the development workflow, and ensure compatibility across different environments.


To typically add version support in a Go project, you would:

  1. Define a Version Package: Create a package dedicated to managing version information. This package can contain variables for the version number, commit hash, build date, and other relevant information.

  2. Populate Version Information at Build Time: Use Go's -ldflags option to inject version information at build time. This can be done within a build script or your CI/CD pipeline.

    go build -ldflags "-X main.version=1.0.0 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date +%F)"
  3. Implement the Version Command: In your application's command-line interface (usually using a package like cobra for Go CLI applications), implement a version command that outputs this information.

  4. Retrieve and Display Version Information: Within the version command, retrieve the version information from the version package and display it to the user.

Example version.go in the version package might look like this:

package version

var (
    Version   = "dev" // overridden at build time
    Commit    = "none" // overridden at build time
    BuildDate = "unknown" // overridden at build time
)

And in your CLI handling part:

import (
    "fmt"
    "yourproject/version"
)

func printVersion() {
    fmt.Printf("Version: %s\nCommit: %s\nBuild Date: %s\n", version.Version, version.Commit, version.BuildDate)
}

Remember to replace "yourproject/version" with the actual import path of your version package.

@jonathanpberger jonathanpberger changed the title Add Version Support for Heighliner Heighliner should report version info. Mar 11, 2024
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

No branches or pull requests

2 participants