Backport of ci: Single source of truth for Go version in CI and Dockerfile into release/1.15.x #20116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport
This PR is auto-generated from #20058 to be assessed for backporting due to the inclusion of the label backport/1.15.
🚨
The person who merged in the original PR is:
@zalimeni
This person should manually cherry-pick the original PR into a new backport PR,
and close this one when the manual backport PR is merged in.
The below text is copied from the body of the original PR.
Description
To simplify Go version management and enable simpler conflict-less (CE + Ent) upgrades in the future, move all Go version management for CI, Docker builds, and related tooling to a single source of truth.
To do this, introduce a new
.go-version
file and reusable workflow to read it that all jobs usingsetup-go
can depend on. Having a separate reusable job allows multiple dependent jobs to use the version after it's determined once. It also enables us to centralize control over the version in our own CI config rather than depending on the behavior ofsetup-go
or other imported actions (see more below).Make all reusable workflows require a Go version as input s.t. we can ensure it is always provided.
Rationale
We have two needs for our CI when it comes to Go versions:
When we upgrade to Go 1.21, we'll have the new
toolchain
directive available in addition to thego
directive. More on how these work here; the salient point is that Go now attempts to install the correct toolchain for us when we update thego
ortoolchain
directive and the local version of Go does not satisfy those versions. It also means that thego
directive provides an enforced minimum version, not the suggested one.However, this presents some rough edges in CI:
setup-go
does not yet supporttoolchain
detection (see also Tar errors on cache restore after toolchain installation actions/setup-go#424)setup-go
and the one required locally; this sort of mistake would be easy to overlooksetup-go
, we rely onhashicorp/action-go-build
to produce binaries, which has a required input for the Go version that is not managed bysetup-go
; managing this separately fromsetup-go
runs the risk of error when changing Go versionsGiven these constraints, and the clarity provided by setting essential versions explicitly to avoid confusion or side-effect mistakes, this change proposes enforcing a consistently installed Go version throughout our workflows, still allowing for explicit overrides where we need a different version. It's easy to reverse if we want to go back to individual
go-version-file
declarations.Futures
My hope is that we can move to calling
go version
to retrieve thetoolchain
version provided in Go 1.21+, as well as introduce a versionedgo.work
in the near future (which will bring several benefits, including removing submodulereplace
s, explicitly setting Go version via a singletoolchain
directive). The current change allows us to control the version from a single source of truth in CI, which is beneficial regardless of Go-native toolchain management changes in the future.Testing & Reproduction steps
PR Checklist
Overview of commits