Skip to content

hack: Prefer go toolchain version in go-version.sh#2713

Open
RamLavi wants to merge 1 commit into
kubevirt:mainfrom
RamLavi:prefer_toolchain
Open

hack: Prefer go toolchain version in go-version.sh#2713
RamLavi wants to merge 1 commit into
kubevirt:mainfrom
RamLavi:prefer_toolchain

Conversation

@RamLavi
Copy link
Copy Markdown
Collaborator

@RamLavi RamLavi commented May 3, 2026

What this PR does / why we need it:
When a toolchain directive is present in go.mod, use its version instead of the go directive. This ensures that install-go.sh downloads the correct patch-level Go binary and that Makefile's GO_VERSION reflects the intended toolchain.

This PR makes the repo toolchain aware.

Special notes for your reviewer:

Release note:

NONE

When a `toolchain` directive is present in go.mod, use its
version instead of the `go` directive. This ensures that
install-go.sh downloads the correct patch-level Go binary
and that Makefile's GO_VERSION reflects the intended toolchain.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ram Lavi <ralavi@redhat.com>
@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels May 3, 2026
@kubevirt-bot kubevirt-bot requested review from oshoval and qinqon May 3, 2026 06:08
@kubevirt-bot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ramlavi for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 3, 2026

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the hack/go-version.sh script to prioritize the toolchain directive over the go directive when determining the Go version from go.mod. The feedback suggests optimizing the script into a single awk command to improve efficiency and prevent potential false matches on non-directive lines.

Comment thread hack/go-version.sh
Comment on lines +2 to +7
toolchain=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/^go//')
if [ -n "$toolchain" ]; then
echo "$toolchain"
else
grep '^go' go.mod | awk '{print $2}'
fi
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation uses multiple pipes and multiple passes over the go.mod file. It also uses grep patterns that could potentially match non-directive lines (e.g., module paths starting with go or toolchain in a require block).

A more robust and efficient approach is to use a single awk command to parse the file in one pass, ensuring only the intended directives are matched and correctly handling the fallback logic.

Suggested change
toolchain=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/^go//')
if [ -n "$toolchain" ]; then
echo "$toolchain"
else
grep '^go' go.mod | awk '{print $2}'
fi
awk '/^toolchain[[:space:]]/ { sub(/^go/, "", $2); print $2; f=1; exit } /^go[[:space:]]/ { v=$2 } END { if (!f && v) print v }' go.mod

@RamLavi
Copy link
Copy Markdown
Collaborator Author

RamLavi commented May 3, 2026

/cherry-pick release-0.100
/cherry-pick release-0.101
/cherry-pick release-0.102

@kubevirt-bot
Copy link
Copy Markdown
Collaborator

@RamLavi: once the present PR merges, I will cherry-pick it on top of release-0.100, release-0.101, release-0.102 in new PRs and assign them to you.

Details

In response to this:

/cherry-pick release-0.100
/cherry-pick release-0.101
/cherry-pick release-0.102

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note-none Denotes a PR that doesn't merit a release note. size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants