fix(main): forward release ldflags into internal/build.Version#222
fix(main): forward release ldflags into internal/build.Version#222
Conversation
Addresses copilot-review follow-up from #219 / #220: the template's release ldflags ('-X main.version=<tag>', '-X main.build=<commit>') targeted variables that didn't exist in raybeam's main package, so tagged releases still reported raybeam's default Version = vcs.revision (commit SHA only) instead of the release tag. Add 'var version, build string' to main.go (alias internal/build as buildpkg to avoid shadowing the var), and forward the injected value into buildpkg.Version at init() time. Tagged releases now show the tag via cobra's --version flag; untagged builds keep falling back to ReadBuildInfo's vcs.revision via the original closure in internal/build/build.go — unchanged. The 'build' var is currently unused (only commit metadata, not yet surfaced). Kept so the ldflag has a target and the main.build assignment in the template doesn't silently vanish. Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
There was a problem hiding this comment.
Automated approval for maintainer PR
All automated quality gates passed. See SECURITY_CONTROLS.md for compensating controls.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #222 +/- ##
==========================================
- Coverage 75.10% 74.49% -0.61%
==========================================
Files 11 11
Lines 490 494 +4
==========================================
Hits 368 368
- Misses 101 105 +4
Partials 21 21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes release-time version reporting by introducing ldflag-target variables in main and attempting to forward them into the shared internal/build version value used by CLI/API surfaces.
Changes:
- Add
version/buildvariables inmainas ldflag targets (-X main.version=...,-X main.build=...). - Forward
versionintointernal/build.Versionduringmain.init().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Copilot review on [#222](#222): Go initializes the `cmd` package BEFORE package main's init runs, so the previous `Version: build.Version` captured the pre-ldflag value (ReadBuildInfo's `vcs.revision`) and main.init's forward into `build.Version` never reached rootCmd. Drop the Version field from the var declaration and assign it inside `Execute()`, which runs after all inits. Now `raybeam --version` reports the release tag on tagged releases, as intended.
## Summary Copilot-review follow-up on [#222](#222): the `build` shim var in main.go was reserved for the `-X main.build` ldflag target but never actually surfaced. Also makes `internal/build` expose CommitHash symmetrically to Version. ### Changes - **internal/build**: add `CommitHash` var, factor the ReadBuildInfo lookup into `vcsRevisionOr()` for reuse. Both Version and CommitHash self-describe from VCS when ldflags aren't applied. - **main.go**: extract `forwardBuildMetadata(v, b)` from init() so forwarding is unit-testable; forward the previously-dead `build` var into `buildpkg.CommitHash`. - **cmd/root.go**: assemble `rootCmd.Version` via `formatVersion()`, which renders `<tag> (<short-commit>)` and dedupes when Version equals CommitHash (the local VCS-fallback case). - **cmd/root_test.go**: 5 test cases covering tagged / untagged / short-commit / dedupe / unknown paths. - **release.yml** sync to template revision [netresearch/.github#74](netresearch/.github#74) (adds `main.buildTime` ldflag — silent no-op here since raybeam has no BuildTimestamp consumer, but keeps the file byte-identical with the fleet). ## Test plan - [x] `go test -v ./cmd` — 5 subtests pass. - [x] `go build ./...` — OK.
Summary
Copilot-review follow-up from #219 / #220: the template's release ldflags (
-X main.version=<tag>,-X main.build=<commit>) targeted variables that didn't exist in raybeam's main package, so tagged releases still reported the defaultVersion = vcs.revision(commit SHA only).Add
var version, build stringtomain.go(aliasinternal/buildasbuildpkgto avoid shadowing), and forward the injected value intobuildpkg.Versionatinit(). Tagged releases now show the tag via cobra's--versionflag; untagged builds keep falling back toReadBuildInfo'svcs.revisionvia the original closure ininternal/build/build.go— unchanged.Test plan
go build ./...+go vetpass.raybeam --versionprintsraybeam version <tag>instead of<commit-sha>.