Skip to content

ROSAENG-6320 | fix: Update "--build" argument to only show git commit - #3438

Open
jerichokeyne wants to merge 1 commit into
openshift:masterfrom
jerichokeyne:ROSAENG-6320
Open

ROSAENG-6320 | fix: Update "--build" argument to only show git commit#3438
jerichokeyne wants to merge 1 commit into
openshift:masterfrom
jerichokeyne:ROSAENG-6320

Conversation

@jerichokeyne

@jerichokeyne jerichokeyne commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PR Summary

Addressing Lucas' comments here: #3435 (comment)

  1. Instead of figuring out a clearer way to show that the date is just the date of the commit, I decided the commit SHA is the only part I care about, so now it only shows the commit SHA
  2. I made it so that release builds should also include the build info now. I both removed the -buildvcs=false flag and added the ldflags configs to set the info.Build variable. I can go back and disable -buildvcs if there's any concerns with enabling that in release builds
  3. Improved test coverage of the new argument

Detailed Description of the Issue

Related Issues and PRs

Type of Change

  • feat - adds a new user-facing capability.
  • fix - resolves an incorrect behavior or bug.
  • docs - updates documentation only.
  • style - formatting or naming changes with no logic impact.
  • refactor - code restructuring with no behavior change.
  • test - adds or updates tests only.
  • chore - maintenance work (tooling, housekeeping, non-product code).
  • build - changes build system, packaging, or dependencies for build output.
  • ci - changes CI pipelines, jobs, or automation workflows.
  • perf - improves performance without changing intended behavior.

Previous Behavior

Behavior After This Change

jkeyne@jkeyne-thinkpadp1gen7:~/work/repos/rosa$ make
go build -ldflags="-X github.com/openshift/rosa/pkg/info.Build=bedae9a35" ./cmd/rosa
jkeyne@jkeyne-thinkpadp1gen7:~/work/repos/rosa$ ./rosa version -b
I: 1.2.64
I: Git commit: bedae9a3588c94cdd21e9a06cde7ad4d4f44c33f
I: Your ROSA CLI is up to date.
jkeyne@jkeyne-thinkpadp1gen7:~/work/repos/rosa$ docker build . -t rosa-test
[+] Building 213.1s (11/11) FINISHED                                                                                                                                         docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                   0.0s
 => => transferring dockerfile: 739B                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                       0.3s
 => [internal] load metadata for registry.access.redhat.com/ubi9/go-toolset:1.26.5-1783931515                                                                                          0.2s
 => [internal] load .dockerignore                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                        0.0s
 => [internal] load build context                                                                                                                                                      0.7s
 => => transferring context: 122.80MB                                                                                                                                                  0.7s
 => CACHED [builder 1/3] FROM registry.access.redhat.com/ubi9/go-toolset:1.26.5-1783931515@sha256:c6b19c92a8613bcfdf69ef00a6ea94ac689ec76d07758d71416c1faa6f35f431                     0.0s
 => => resolve registry.access.redhat.com/ubi9/go-toolset:1.26.5-1783931515@sha256:c6b19c92a8613bcfdf69ef00a6ea94ac689ec76d07758d71416c1faa6f35f431                                    0.0s
 => CACHED [stage-2 1/2] FROM docker.io/library/alpine:latest@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b                                                  0.0s
 => => resolve docker.io/library/alpine:latest@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b                                                                 0.0s
 => [builder 2/3] COPY --chown=1001:0 . .                                                                                                                                              2.1s
 => [builder 3/3] RUN git config --global --add safe.directory /opt/app-root/src &&     make release                                                                                 203.5s
 => [stage-2 2/2] COPY --from=builder /opt/app-root/src/releases /releases                                                                                                             0.0s
 => exporting to image                                                                                                                                                                 5.8s
 => => exporting layers                                                                                                                                                                5.2s
 => => exporting manifest sha256:8305169a10cb7d77f90d8b1f4ef4777477b2d3a91d605bedb2f83e878409d72d                                                                                      0.0s
 => => exporting config sha256:fd849e01d96f28d464b205e0e890c74893b2b6c97984180b1a5f91d4221df99c                                                                                        0.0s
 => => exporting attestation manifest sha256:18d919d7051ace38d05d3d2be477de2fb28d0e5370304d733afa1c4ae6ee28bf                                                                          0.0s
 => => exporting manifest list sha256:90d3fe51123fdad1a64494fc05c0573feaf69e796e17e8a8b797c7dc3535677b                                                                                 0.0s
 => => naming to docker.io/library/rosa-test:latest                                                                                                                                    0.0s
 => => unpacking to docker.io/library/rosa-test:latest                                                                                                                                 0.5s
jkeyne@jkeyne-thinkpadp1gen7:~/work/repos/rosa$ docker run --rm -it rosa-test
/ # cd releases/
/releases # tar xvf rosa_linux_amd64.tar.gz
rosa
/releases # ./rosa version -b
I: 1.2.64
I: Git commit: bedae9a3588c94cdd21e9a06cde7ad4d4f44c33f
I: Your ROSA CLI is up to date.
/releases #

How to Test (Step-by-Step)

Preconditions

Test Steps

Expected Results

Proof of the Fix

  • Screenshots:
  • Videos:
  • Logs/CLI output:
  • Other artifacts:

Breaking Changes

  • No breaking changes
  • Yes, this PR introduces a breaking change (describe impact and migration plan below)

Breaking Change Details / Migration Plan

Developer Verification Checklist

  • Commit subject/title follows [JIRA-TICKET] | [TYPE]: <MESSAGE>.
  • PR description clearly explains both what changed and why.
  • Relevant Jira/GitHub issues and related PRs are linked.
  • make install-hooks has been run in this clone.
  • Tests were added/updated where appropriate.
  • I manually tested the change.
  • make test passes.
  • make lint passes.
  • make rosa passes.
  • Documentation or repo-local agent guidance was added/updated where appropriate.
  • Any risk, limitation, or follow-up work is documented.

Summary by CodeRabbit

  • New Features

    • Build metadata now records the current Git commit in released and locally installed CLI binaries.
    • The version command’s build information reports the Git commit, with a fallback value when detailed build metadata is unavailable.
  • Documentation

    • Updated the --build option description to clarify that it primarily displays the Git commit.
  • Tests

    • Expanded coverage for version output across available and unavailable build metadata scenarios.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Build and release commands now inject the short Git commit into github.com/openshift/rosa/pkg/info.Build, while Docker build stages no longer set GOFLAGS=-buildvcs=false. Version handling now reads build information through an injectable dependency and reports the Go revision or info.Build fallback. Tests cover unavailable build information, populated revisions, and empty-revision fallback output. The --build help text now emphasizes the Git commit.

Possibly related PRs

  • openshift/rosa#3435: Modifies the rosa version --build/-b flow and related build metadata tests.

Suggested reviewers: olucasfreitas

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: showing only the Git commit in --build output.
Description check ✅ Passed The PR includes summary, issue link, change type, behavior change, and validation; several template sections are still incomplete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed cmd/version/cmd_test.go uses only static Ginkgo titles; no fmt.Sprintf, IDs, dates, or other run-time values appear in test names.
Test Structure And Quality ✅ Passed The updated Ginkgo tests use focused It blocks, shared setup/teardown, and no cluster waits/resources; they match nearby test style.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the only new tests are unit tests in cmd/version/cmd_test.go and use no MicroShift-unsupported OpenShift APIs.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the only test changes are cmd/version unit tests with no cluster or node assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed PR only changes build/version tooling and tests; no deployment manifests, controllers, affinities, selectors, or replica/PDB logic were added.
Ote Binary Stdout Contract ✅ Passed PR changes are confined to version-command output and build flags; no new stdout writes were added in main/init/setup paths.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Only cmd/version unit tests changed; no new e2e Ginkgo tests or IPv4/external-network assumptions were added.
No-Weak-Crypto ✅ Passed Diff only updates version/build metadata and tests; no weak crypto, custom crypto, or secret/token comparisons were added.
Container-Privileges ✅ Passed The PR only changes build/version files; no touched manifest introduces privileged, hostPID/Network/IPC, SYS_ADMIN, root escalation, or allowPrivilegeEscalation settings.
No-Sensitive-Data-In-Logs ✅ Passed No sensitive data is logged; the new output only emits version text and Git commit SHA.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@openshift-ci

openshift-ci Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 2026

@coderabbitai coderabbitai Bot 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b82db51 and 3a1f04a.

📒 Files selected for processing (8)
  • .goreleaser.yaml
  • Dockerfile
  • Makefile
  • cmd/version/cmd.go
  • cmd/version/cmd_test.go
  • cmd/version/options.go
  • hack/build_cli.sh
  • images/Dockerfile.e2e
💤 Files with no reviewable changes (2)
  • Dockerfile
  • images/Dockerfile.e2e

Comment thread cmd/version/cmd_test.go
Comment on lines +234 to 315
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)))
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant