fix(version): embed VERSION file so source builds show a real version#618
Open
LeanSheng wants to merge 1 commit into
Open
fix(version): embed VERSION file so source builds show a real version#618LeanSheng wants to merge 1 commit into
LeanSheng wants to merge 1 commit into
Conversation
`gog --version` previously returned the bare string "dev" when built via plain `go build ./cmd/gog` from a source checkout. That is the most common install path for contributors, and the existing fallback chain (ldflags -> debug.BuildInfo) does not cover it because debug.BuildInfo.Main.Version is "(devel)" for binaries built directly from a main module. Bake a VERSION file (currently "v0.17.0-dev") into the package via //go:embed and consult it after BuildInfo. Adds a post-release-bump workflow that rewrites internal/cmd/VERSION to "<just-pushed-tag>-dev" on every v* tag push, so the fallback stays current with zero maintainer effort. Goreleaser / Makefile / Dockerfile ldflags paths are unchanged and still win when available. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Problem
gog --versionreturns the bare worddevwhen the binary was built via plaingo build ./cmd/gogfrom a source checkout — the most common path for contributors and anyone trying the project locally.Commit
6af52a4was meant to fix exactly this forgo install …@vX.Y.Zusers by adding aruntime/debug.ReadBuildInfo()fallback. That fallback works for module-versioned installs, but Go reportsMain.Version == "(devel)"for binaries built directly from the main module, and the new code explicitly skips that sentinel. Sogo buildfrom a clone still printsdev.The runtime is also fundamentally limited here:
debug.BuildInfo.Settingsembedsvcs.revision(commit SHA) but never the tag name. So something has to bake the tag in at build time.Fix
Bake an
internal/cmd/VERSIONfile (currentlyv0.17.0-dev) into the package via//go:embed, and consult it after BuildInfo inresolvedVersion(). The file lives next toversion.gobecause//go:embedcannot escape the package directory.To keep the file from rotting, add a
post-release-bumpworkflow that runs on everyv*tag push and rewritesinternal/cmd/VERSIONto<just-pushed-tag>-dev. So after you tagv0.18.0, CI commitsv0.18.0-devtomainautomatically. No human maintenance required after this PR.Behavior after this lands
v0.17.0 (abc123 …)make buildv0.17.0/v0.17.0-N-gabc1234go install …/cmd/gog@v0.17.0v0.17.0debug.BuildInfo.Main.Version— unchangedgo build ./cmd/gogfrom a fresh clonev0.17.0-devv0.17.0-devFiles changed
internal/cmd/VERSION(new) —v0.17.0-devinternal/cmd/version.go—//go:embed VERSION, renamedevVersion→sentinelDev, add embedded fallback inresolvedVersion()internal/cmd/version_test.go— two new tests covering the(devel)fallback and the empty-everything sentinel. All existing tests pass unmodified..github/workflows/post-release-bump.yml(new) — auto-bumpsVERSIONto<tag>-devon tag push, commits tomainwith[skip ci].CHANGELOG.md— note under## 0.17.1 - Unreleased / Fixed.Things for the maintainer to confirm
main: the workflow pushes directly tomainusingGITHUB_TOKEN. Ifmainis protection-gated against direct pushes from Actions, the workflow will fail visibly on the next tag and we'd need to switch it to open a PR viagh pr createinstead. I left it as direct push because it's the simpler model and a[skip ci]chore commit feels low-risk.<just-pushed-tag>-dev(e.g. after taggingv0.17.1, VERSION becomesv0.17.1-dev). Means VERSION always tracks the last released tag, with-devmarking the period afterward. If you preferv0.17.2-dev(predicting next) instead, easy one-line workflow change.Verification
🤖 Generated with Claude Code