Skip to content

fix(main): forward release ldflags into internal/build.Version#222

Merged
CybotTM merged 1 commit intomainfrom
fix/add-version-vars
Apr 20, 2026
Merged

fix(main): forward release ldflags into internal/build.Version#222
CybotTM merged 1 commit intomainfrom
fix/add-version-vars

Conversation

@CybotTM
Copy link
Copy Markdown
Member

@CybotTM CybotTM commented Apr 20, 2026

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 default Version = vcs.revision (commit SHA only).

Add var version, build string to main.go (alias internal/build as buildpkg to avoid shadowing), and forward the injected value into buildpkg.Version at init(). 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.

Test plan

  • go build ./... + go vet pass.
  • Next tagged release: raybeam --version prints raybeam version <tag> instead of <commit-sha>.

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>
Copilot AI review requested due to automatic review settings April 20, 2026 17:59
@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@CybotTM CybotTM merged commit edb82c0 into main Apr 20, 2026
@CybotTM CybotTM deleted the fix/add-version-vars branch April 20, 2026 17:59
@github-actions
Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Mutation Testing Results

Mutation Score: 0% (threshold: 60%)

⚠️ Score is below threshold. Consider improving test coverage or test quality.

What is mutation testing?

Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.

  • Killed mutants: Tests caught the mutation (good!)
  • Survived mutants: Tests missed the mutation (needs improvement)

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated approval for maintainer PR

All automated quality gates passed. See SECURITY_CONTROLS.md for compensating controls.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.49%. Comparing base (7e4fbef) to head (6a381ed).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
main.go 0.00% 4 Missing ⚠️
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              
Flag Coverage Δ
e2e 74.49% <0.00%> (-0.61%) ⬇️
integration 74.49% <0.00%> (-0.61%) ⬇️
unittests 74.49% <0.00%> (-0.61%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/build variables in main as ldflag targets (-X main.version=..., -X main.build=...).
  • Forward version into internal/build.Version during main.init().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main.go
CybotTM added a commit that referenced this pull request Apr 20, 2026
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.
CybotTM added a commit that referenced this pull request Apr 20, 2026
## 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.
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.

2 participants