Skip to content

feat(main): forward buildTime ldflag + extract testable helper - #565

Merged
CybotTM merged 1 commit into
mainfrom
feat/forward-buildtime
Apr 20, 2026
Merged

feat(main): forward buildTime ldflag + extract testable helper#565
CybotTM merged 1 commit into
mainfrom
feat/forward-buildtime

Conversation

@CybotTM

@CybotTM CybotTM commented Apr 20, 2026

Copy link
Copy Markdown
Member

Summary

Addresses copilot-review follow-ups from #564.

1. BuildTimestamp actually populates

FormatVersion() previously reported built at n/a even on tagged releases because the template injected only main.version + main.build. netresearch/.github#74 extended the template with -X main.buildTime=<commit-timestamp>; this PR adds var buildTime string and forwards it into internal/version.BuildTimestamp.

2. Testable forwarding helper

Extracted the three if X != "" { ... } assignments into forwardBuildMetadata(v, b, t). Three new test cases in main_test.go:

  • all values forwarded — confirms the happy path mutates internalversion.*
  • empty inputs preserve existing values — confirms local go run / untagged go build leaves defaults intact
  • partial injection — confirms only the non-empty inputs land (e.g. buildTime empty on workflow_dispatch backfill still populates version + build)

Tests use snapshot/restore via t.Cleanup so they don't leak state.

3. Sync release.yml to latest template

Picks up the -X main.buildTime= ldflag from #74.

Test plan

  • go test -run TestForwardBuildMetadata -v ./cmd/ldap-manager/ passes (3 subtests).

Addresses two copilot review follow-ups from #564:

1. FormatVersion() previously reported 'built at n/a' even on
   tagged releases because the template's ldflags injected only
   main.version + main.build. netresearch/.github#74 extended the
   template with -X main.buildTime=<commit-timestamp>; this PR adds
   'var buildTime string' and forwards it into
   internal/version.BuildTimestamp so the value lands.

2. The init() forwarding logic is extracted into
   forwardBuildMetadata(v, b, t), unit-tested in main_test.go against
   the internal/version package-level vars with snapshot/restore.
   Empty inputs are treated as 'not injected' and preserve the
   defaults — locked in by the partial-injection test case.

Sync release.yml to the latest template (buildTime ldflag now present).

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
Copilot AI review requested due to automatic review settings April 20, 2026 19:25
@CybotTM
CybotTM merged commit 1797362 into main Apr 20, 2026
@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 deleted the feat/forward-buildtime branch April 20, 2026 19:25
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

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

Scanned Files

None

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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.

@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)

@codecov

codecov Bot commented Apr 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.94%. Comparing base (4f65e45) to head (30931a0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #565   +/-   ##
=======================================
  Coverage   81.94%   81.94%           
=======================================
  Files          18       18           
  Lines        1855     1855           
=======================================
  Hits         1520     1520           
  Misses        265      265           
  Partials       70       70           
Flag Coverage Δ
e2e 57.55% <ø> (ø)
unittests 83.91% <ø> (ø)

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

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 updates the build metadata plumbing so release builds can populate internal/version.BuildTimestamp (via a new main.buildTime ldflag), and refactors the forwarding logic into a unit-testable helper.

Changes:

  • Add buildTime as a build-injected main package variable and forward it into internal/version.BuildTimestamp.
  • Extract forwardBuildMetadata(v, b, t) from init() and add unit tests covering full/empty/partial forwarding.
  • Update release.yml to pass -X main.buildTime=... in ldflags.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cmd/ldap-manager/main.go Adds buildTime, introduces forwardBuildMetadata, and forwards build metadata during init.
cmd/ldap-manager/main_test.go Adds tests validating forwarding behavior without leaking global state.
.github/workflows/release.yml Passes the new main.buildTime ldflag in the release build matrix.

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

Comment thread cmd/ldap-manager/main.go
Comment thread .github/workflows/release.yml
CybotTM added a commit that referenced this pull request Apr 20, 2026
)

Copilot review on
[#565](#565):
`internal/version/doc.go` still described ldflags as being applied
directly to `internal/version.*`, contradicting the new `main.*` +
`forwardBuildMetadata` flow in `cmd/ldap-manager/main.go`.

Rewrite the package docstring to describe:
- The shared go-app template as the canonical ldflag source (`-X
main.version`, `main.build`, `main.buildTime`).
- `forwardBuildMetadata()` as the init-time bridge into
`internal/version.Version` / `.CommitHash` / `.BuildTimestamp`.
- Local-dev default behavior (defaults preserved when shim vars are
empty).

Also drop the obsolete Makefile / Dockerfile example snippets — the new
release pipeline replaces both paths with the shared template, so those
sections were actively misleading.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants