-
Notifications
You must be signed in to change notification settings - Fork 12
fix: inject version from git tag at build time #522
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
Goreleaser now injects the version from the git tag via ldflags,
eliminating the need to manually update version.go before releases.
Changes:
- .goreleaser.yml: Add -X main.Version={{ .Version }} to ldflags
- version.go: Change const to var with "dev" default
- Makefile: Use git describe for local builds
- CLAUDE.md: Simplify release process documentation
Fixes #521
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 automates version injection during builds by using git tags and ldflags, eliminating the need to manually maintain version numbers in source code.
Changes:
- Configured goreleaser and Makefile to inject version from git tags via ldflags
- Modified
version.goto use variables instead of constants, with "dev" as default - Updated documentation to reflect the simplified release workflow
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cmd/confd/version.go | Changed Version from const to var, grouped with GitSHA, added default "dev" value |
| Makefile | Updated VERSION extraction to use git describe and added Version to ldflags |
| CLAUDE.md | Removed manual version.go update steps from release documentation |
| .goreleaser.yml | Added Version variable injection to ldflags |
💡 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84db6f305a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .PHONY: build install clean lint test integration dep release | ||
| VERSION=`egrep -o '[0-9]+\.[0-9a-z.\-]+' cmd/confd/version.go` | ||
| GIT_SHA=`git rev-parse --short HEAD || echo` | ||
| VERSION=$(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//' || echo "dev") |
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.
Preserve version when git metadata is missing
When building from a source tree without .git (e.g., distro tarballs or vendored source), git describe fails, but the pipeline still exits 0 because sed succeeds, so the || echo "dev" fallback never runs. That leaves VERSION empty and the -ldflags "-X main.Version=$(VERSION)" assignment overwrites the default Version = "dev" with an empty string, so confd --version prints a blank version in those environments. Consider moving the fallback before the pipe or grouping it, e.g., (git describe ... || echo dev) | sed 's/^v//', so non-git builds still get a meaningful version.
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #522 +/- ##
==========================================
+ Coverage 62.45% 62.50% +0.05%
==========================================
Files 48 48
Lines 5420 5420
==========================================
+ Hits 3385 3388 +3
+ Misses 1828 1825 -3
Partials 207 207 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Goreleaser now injects the version from the git tag via ldflags, eliminating the need to manually update
version.gobefore releases..goreleaser.yml: Add-X main.Version={{ .Version }}to ldflagsversion.go: Changeconsttovarwith"dev"defaultMakefile: Usegit describefor local buildsCLAUDE.md: Simplify release process documentationTest plan
make buildproduces versioned binaryFixes #521