Skip to content

[backport] Keep backport branch's own .go-version during branch creation - #20469

Draft
mrodm wants to merge 4 commits into
elastic:mainfrom
mrodm:backport_keep_go_version_backports
Draft

[backport] Keep backport branch's own .go-version during branch creation#20469
mrodm wants to merge 4 commits into
elastic:mainfrom
mrodm:backport_keep_go_version_backports

Conversation

@mrodm

@mrodm mrodm commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Proposed commit message

WHAT:
The backport_branch.sh script previously forced-copied .go-version from the source branch (main) into the backport branch before running go mod tidy. This silently overwrote the backport branch's Go version, meaning all backport branches ended up with main's Go version — even when they were intentionally pinned to an older one.

The fix removes that forced copy and instead activates the backport branch's own .go-version via gvm before running go mod tidy, so that go.mod is tidied against the correct toolchain. After go mod tidy completes, the source branch Go version is restored for the rest of the script.

WHY:
Backport branches targeting older release lines may need to pin an older Go version. Overwriting .go-version from main breaks that invariant and can cause go mod tidy to produce a go.mod that is incompatible with the toolchain the backport branch is actually meant to use.

Example of errors:

 $ mage check
...
exec: go "run" "gotest.tools/gotestsum" "--format" "testname" "--junitfile" "tests-report.xml" "./dev/..."
# golang.org/x/tools/internal/tokeninternal
/go/pkg/mod/golang.org/x/tools@v0.22.0/internal/tokeninternal/tokeninternal.go:64:9: invalid array length -delta * delta (constant -256 of type int64)
Error: running "go run gotest.tools/gotestsum --format testname --junitfile tests-report.xml ./dev/..." failed with exit code 1
 $ mage check
dev/backports/owners/owners.go:13:2: package maps is not in GOROOT (/home/mariorodriguez/.gvm/versions/go1.19.1.linux.amd64/src/maps)
dev/citools/packages.go:13:2: package slices is not in GOROOT (/home/mariorodriguez/.gvm/versions/go1.19.1.linux.amd64/src/slices)
Error: error compiling magefiles

Author's Checklist

  • Verify that gvm is available in all Buildkite agent environments where this script runs.
  • Confirm the restored source-branch Go version is correctly picked up after go mod tidy.

Buildkite build testing this: https://buildkite.com/elastic/integrations-backport/builds/318

How to test this PR locally

  1. Trigger the backport branch creation script against a backport branch that has a different .go-version than main.
  2. Confirm .go-version on the resulting branch still reflects the backport branch's original version.
  3. Confirm go.mod is updated correctly by go mod tidy without changing the go directive to a newer version.

Related issues


This PR was generated with the assistance of Claude (claude-sonnet-4-6).

Instead of overwriting .go-version from the source branch, activate the
backport branch's Go version via gvm before running go mod tidy so that
go.mod stays consistent with the branch's toolchain requirement. Restore
the source branch Go version afterward for the rest of the script.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mrodm mrodm self-assigned this Aug 3, 2026
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.

1 participant