ROSAENG-6320 | fix: Update "--build" argument to only show git commit - #3438
ROSAENG-6320 | fix: Update "--build" argument to only show git commit#3438jerichokeyne wants to merge 1 commit into
Conversation
…ilds include build info
📝 WalkthroughWalkthroughBuild and release commands now inject the short Git commit into Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 15✅ Passed checks (15 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jerichokeyne The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/version/cmd_test.go`:
- Around line 234-315: Update both Version output tests around fakeBuildInfo to
include a sentinel vcs.time value in the build information, then assert that
sentinel is absent from stdout alongside the existing Git commit assertions.
Keep the current SHA and fallback expectations unchanged while ensuring build
timestamps are not printed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 75502bc5-9da2-4d40-9fe4-18ad13d6b6a8
📒 Files selected for processing (8)
.goreleaser.yamlDockerfileMakefilecmd/version/cmd.gocmd/version/cmd_test.gocmd/version/options.gohack/build_cli.shimages/Dockerfile.e2e
💤 Files with no reviewable changes (2)
- Dockerfile
- images/Dockerfile.e2e
| It("should print git commit info", func() { | ||
| rpt := reporter.CreateReporter() | ||
| opts = &RosaVersionOptions{ | ||
| verifyRosa: mockVerify, | ||
| reporter: rpt, | ||
| readBuildInfo: fakeBuildInfo("abc1234"), | ||
| args: &RosaVersionUserOptions{ | ||
| clientOnly: true, | ||
| build: true, | ||
| }, | ||
| } | ||
|
|
||
| rout, wout, pipeErr := os.Pipe() | ||
| Expect(pipeErr).ToNot(HaveOccurred()) | ||
| tmpout := os.Stdout | ||
| defer func() { | ||
| os.Stdout = tmpout | ||
| }() | ||
| os.Stdout = wout | ||
|
|
||
| type result struct { | ||
| versionErr error | ||
| closeErr error | ||
| } | ||
| ch := make(chan result, 1) | ||
| go func() { | ||
| vErr := opts.Version() | ||
| cErr := wout.Close() | ||
| ch <- result{versionErr: vErr, closeErr: cErr} | ||
| }() | ||
|
|
||
| stdout, readErr := io.ReadAll(rout) | ||
| Expect(readErr).ToNot(HaveOccurred()) | ||
|
|
||
| res := <-ch | ||
| Expect(res.versionErr).ToNot(HaveOccurred()) | ||
| Expect(res.closeErr).ToNot(HaveOccurred()) | ||
|
|
||
| Expect(string(stdout)).To(ContainSubstring("Git commit: abc1234")) | ||
| Expect(string(stdout)).ToNot(ContainSubstring(fmt.Sprintf("Git commit: %s", info.Build))) | ||
| }) | ||
|
|
||
| It("should fall back to info.Build when revision is empty", func() { | ||
| rpt := reporter.CreateReporter() | ||
| opts = &RosaVersionOptions{ | ||
| verifyRosa: mockVerify, | ||
| reporter: rpt, | ||
| readBuildInfo: fakeBuildInfo(""), | ||
| args: &RosaVersionUserOptions{ | ||
| clientOnly: true, | ||
| build: true, | ||
| }, | ||
| } | ||
|
|
||
| rout, wout, pipeErr := os.Pipe() | ||
| Expect(pipeErr).ToNot(HaveOccurred()) | ||
| tmpout := os.Stdout | ||
| defer func() { | ||
| os.Stdout = tmpout | ||
| }() | ||
| os.Stdout = wout | ||
|
|
||
| type result struct { | ||
| versionErr error | ||
| closeErr error | ||
| } | ||
| ch := make(chan result, 1) | ||
| go func() { | ||
| vErr := opts.Version() | ||
| cErr := wout.Close() | ||
| ch <- result{versionErr: vErr, closeErr: cErr} | ||
| }() | ||
|
|
||
| stdout, readErr := io.ReadAll(rout) | ||
| Expect(readErr).ToNot(HaveOccurred()) | ||
|
|
||
| res := <-ch | ||
| Expect(res.versionErr).ToNot(HaveOccurred()) | ||
| Expect(res.closeErr).ToNot(HaveOccurred()) | ||
|
|
||
| Expect(string(stdout)).To(ContainSubstring(fmt.Sprintf("Git commit: %s", info.Build))) | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert that build timestamps are omitted.
These fixtures contain no vcs.time, so a regression that prints the timestamp alongside the SHA would still pass. Add a sentinel vcs.time setting and assert it is absent from stdout.
Suggested test adjustment
- readBuildInfo: fakeBuildInfo("abc1234"),
+ readBuildInfo: func() (*debug.BuildInfo, bool) {
+ return &debug.BuildInfo{Settings: []debug.BuildSetting{
+ {Key: "vcs.revision", Value: "abc1234"},
+ {Key: "vcs.time", Value: "2099-01-01T00:00:00Z"},
+ }}, true
+ },
...
Expect(string(stdout)).To(ContainSubstring("Git commit: abc1234"))
+ Expect(string(stdout)).ToNot(ContainSubstring("2099-01-01T00:00:00Z"))As per coding guidelines, “tests should prove correctness and must not be weakened or changed merely to accommodate broken behavior.”
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| It("should print git commit info", func() { | |
| rpt := reporter.CreateReporter() | |
| opts = &RosaVersionOptions{ | |
| verifyRosa: mockVerify, | |
| reporter: rpt, | |
| readBuildInfo: fakeBuildInfo("abc1234"), | |
| args: &RosaVersionUserOptions{ | |
| clientOnly: true, | |
| build: true, | |
| }, | |
| } | |
| rout, wout, pipeErr := os.Pipe() | |
| Expect(pipeErr).ToNot(HaveOccurred()) | |
| tmpout := os.Stdout | |
| defer func() { | |
| os.Stdout = tmpout | |
| }() | |
| os.Stdout = wout | |
| type result struct { | |
| versionErr error | |
| closeErr error | |
| } | |
| ch := make(chan result, 1) | |
| go func() { | |
| vErr := opts.Version() | |
| cErr := wout.Close() | |
| ch <- result{versionErr: vErr, closeErr: cErr} | |
| }() | |
| stdout, readErr := io.ReadAll(rout) | |
| Expect(readErr).ToNot(HaveOccurred()) | |
| res := <-ch | |
| Expect(res.versionErr).ToNot(HaveOccurred()) | |
| Expect(res.closeErr).ToNot(HaveOccurred()) | |
| Expect(string(stdout)).To(ContainSubstring("Git commit: abc1234")) | |
| Expect(string(stdout)).ToNot(ContainSubstring(fmt.Sprintf("Git commit: %s", info.Build))) | |
| }) | |
| It("should fall back to info.Build when revision is empty", func() { | |
| rpt := reporter.CreateReporter() | |
| opts = &RosaVersionOptions{ | |
| verifyRosa: mockVerify, | |
| reporter: rpt, | |
| readBuildInfo: fakeBuildInfo(""), | |
| args: &RosaVersionUserOptions{ | |
| clientOnly: true, | |
| build: true, | |
| }, | |
| } | |
| rout, wout, pipeErr := os.Pipe() | |
| Expect(pipeErr).ToNot(HaveOccurred()) | |
| tmpout := os.Stdout | |
| defer func() { | |
| os.Stdout = tmpout | |
| }() | |
| os.Stdout = wout | |
| type result struct { | |
| versionErr error | |
| closeErr error | |
| } | |
| ch := make(chan result, 1) | |
| go func() { | |
| vErr := opts.Version() | |
| cErr := wout.Close() | |
| ch <- result{versionErr: vErr, closeErr: cErr} | |
| }() | |
| stdout, readErr := io.ReadAll(rout) | |
| Expect(readErr).ToNot(HaveOccurred()) | |
| res := <-ch | |
| Expect(res.versionErr).ToNot(HaveOccurred()) | |
| Expect(res.closeErr).ToNot(HaveOccurred()) | |
| Expect(string(stdout)).To(ContainSubstring(fmt.Sprintf("Git commit: %s", info.Build))) | |
| }) | |
| It("should print git commit info", func() { | |
| rpt := reporter.CreateReporter() | |
| opts = &RosaVersionOptions{ | |
| verifyRosa: mockVerify, | |
| reporter: rpt, | |
| readBuildInfo: func() (*debug.BuildInfo, bool) { | |
| return &debug.BuildInfo{Settings: []debug.BuildSetting{ | |
| {Key: "vcs.revision", Value: "abc1234"}, | |
| {Key: "vcs.time", Value: "2099-01-01T00:00:00Z"}, | |
| }}, true | |
| }, | |
| args: &RosaVersionUserOptions{ | |
| clientOnly: true, | |
| build: true, | |
| }, | |
| } | |
| rout, wout, pipeErr := os.Pipe() | |
| Expect(pipeErr).ToNot(HaveOccurred()) | |
| tmpout := os.Stdout | |
| defer func() { | |
| os.Stdout = tmpout | |
| }() | |
| os.Stdout = wout | |
| type result struct { | |
| versionErr error | |
| closeErr error | |
| } | |
| ch := make(chan result, 1) | |
| go func() { | |
| vErr := opts.Version() | |
| cErr := wout.Close() | |
| ch <- result{versionErr: vErr, closeErr: cErr} | |
| }() | |
| stdout, readErr := io.ReadAll(rout) | |
| Expect(readErr).ToNot(HaveOccurred()) | |
| res := <-ch | |
| Expect(res.versionErr).ToNot(HaveOccurred()) | |
| Expect(res.closeErr).ToNot(HaveOccurred()) | |
| Expect(string(stdout)).To(ContainSubstring("Git commit: abc1234")) | |
| Expect(string(stdout)).ToNot(ContainSubstring("2099-01-01T00:00:00Z")) | |
| Expect(string(stdout)).ToNot(ContainSubstring(fmt.Sprintf("Git commit: %s", info.Build))) | |
| }) | |
| It("should fall back to info.Build when revision is empty", func() { | |
| rpt := reporter.CreateReporter() | |
| opts = &RosaVersionOptions{ | |
| verifyRosa: mockVerify, | |
| reporter: rpt, | |
| readBuildInfo: fakeBuildInfo(""), | |
| args: &RosaVersionUserOptions{ | |
| clientOnly: true, | |
| build: true, | |
| }, | |
| } | |
| rout, wout, pipeErr := os.Pipe() | |
| Expect(pipeErr).ToNot(HaveOccurred()) | |
| tmpout := os.Stdout | |
| defer func() { | |
| os.Stdout = tmpout | |
| }() | |
| os.Stdout = wout | |
| type result struct { | |
| versionErr error | |
| closeErr error | |
| } | |
| ch := make(chan result, 1) | |
| go func() { | |
| vErr := opts.Version() | |
| cErr := wout.Close() | |
| ch <- result{versionErr: vErr, closeErr: cErr} | |
| }() | |
| stdout, readErr := io.ReadAll(rout) | |
| Expect(readErr).ToNot(HaveOccurred()) | |
| res := <-ch | |
| Expect(res.versionErr).ToNot(HaveOccurred()) | |
| Expect(res.closeErr).ToNot(HaveOccurred()) | |
| Expect(string(stdout)).To(ContainSubstring(fmt.Sprintf("Git commit: %s", info.Build))) | |
| }) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/version/cmd_test.go` around lines 234 - 315, Update both Version output
tests around fakeBuildInfo to include a sentinel vcs.time value in the build
information, then assert that sentinel is absent from stdout alongside the
existing Git commit assertions. Keep the current SHA and fallback expectations
unchanged while ensuring build timestamps are not printed.
Source: Coding guidelines
PR Summary
Addressing Lucas' comments here: #3435 (comment)
-buildvcs=falseflag and added theldflagsconfigs to set theinfo.Buildvariable. I can go back and disable-buildvcsif there's any concerns with enabling that in release buildsDetailed Description of the Issue
Related Issues and PRs
Type of Change
Previous Behavior
Behavior After This Change
How to Test (Step-by-Step)
Preconditions
Test Steps
Expected Results
Proof of the Fix
Breaking Changes
Breaking Change Details / Migration Plan
Developer Verification Checklist
[JIRA-TICKET] | [TYPE]: <MESSAGE>.make install-hookshas been run in this clone.make testpasses.make lintpasses.make rosapasses.Summary by CodeRabbit
New Features
Documentation
--buildoption description to clarify that it primarily displays the Git commit.Tests