Skip to content

Conversation

@kriscoleman
Copy link
Collaborator

This PR

Added ldflags configuration to GoReleaser and Makefile to inject the actual CLI version, commit hash, and build date at compile time.

This ensures:

  • GoReleaser builds embed the release version from git tags
  • Local builds via make build use git describe for versioning
  • The version command displays accurate version info instead of "dev"

Related Issues

Closes #192

How to test

To see the behavior when you built locally prior to this change, pull main and run make install then run openfeature and notice:
image

To see the behavior after this change, pull this branch, run make install and then run openfeature and notice more meaninful meta:
image

Added ldflags configuration to GoReleaser and Makefile to inject the actual CLI version, commit hash, and build date at compile time.

This ensures:
- GoReleaser builds embed the release version from git tags
- Local builds via `make build` use git describe for versioning
- The version command displays accurate version info instead of "dev"

Closes open-feature#192

Signed-off-by: Kris Coleman <kriscodeman@gmail.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @kriscoleman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the build process by integrating dynamic versioning information into the CLI binary. By leveraging ldflags, it ensures that both official releases and local development builds accurately reflect the current version, commit, and build date, thereby improving the clarity and traceability of the compiled application.

Highlights

  • Accurate Versioning: Implemented ldflags configuration in both GoReleaser and the Makefile to inject the actual CLI version, commit hash, and build date directly into the compiled binary at compile time.
  • Build Process Enhancement: Ensures that GoReleaser builds embed the release version derived from git tags, while local builds executed via make build utilize git describe for dynamic versioning.
  • Improved User Experience: The version command of the CLI will now display accurate and meaningful metadata instead of a generic 'dev' placeholder, providing better context for users.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a solid improvement by embedding version information into the CLI binary at build time using ldflags. The changes in both .goreleaser.yaml and the Makefile correctly implement this for both release and local builds. My review includes a couple of minor suggestions to improve consistency between the two build methods and to make the local build process more robust against custom variable values.

ldflags:
- -s -w
- -X main.version={{ .Version }}
- -X main.commit={{ .FullCommit }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the Makefile, which uses the short commit hash (git rev-parse --short HEAD), it's better to use the short commit hash here as well. GoReleaser provides a {{ .ShortCommit }} template variable for this purpose.

      - -X main.commit={{ .ShortCommit }}

VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The values for the -X flags are not quoted. If any of the variables (VERSION, COMMIT, DATE) are overridden with a value containing spaces, the build command will fail. To make the build more robust, you should quote the values being injected.

For example, if you run make build VERSION="my version", the current LDFLAGS would be -s -w -X main.version=my version ..., which would be parsed incorrectly by the linker. Quoting the values prevents this.

LDFLAGS := -s -w -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'

@erka
Copy link
Member

erka commented Jan 21, 2026

runtime/debug.BuildInfo.Main.Version could be a better option

@erka
Copy link
Member

erka commented Jan 21, 2026

go install github.com/erka/gobuild@v0.0.1 as example

@georgesdugue
Copy link
Contributor

georgesdugue commented Jan 21, 2026

Testing: Looks great

main

image

this branch

image

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.

chore: wire the Version up to the actual CLI version

3 participants