riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.34k stars 89 forks source link

Establish minimum Go version of 1.21, with toolchain of Go 1.22 #522

Closed brandur closed 1 month ago

brandur commented 1 month ago

This one related to #520, in which it turns out that our Go 1.21 build step has actually been automatically upgrading itself to Go 1.22, so under the radar that we didn't notice.

Here, leverage a Go "toolchain" to establish a preferred version of Go for the project, but keeping a go directive in go.mods that's at the 1.21 lower bound that we're trying to support. The presence of a toolchain directive prevents go mod tidy from upgrading the go directive to the latest version of Go installed.

I found the easiest way to add the toolchain directive to be with go get [2] like:

go get go@1.21 toolchain@1.22.5

Maintaining this correctly is going to be a little tricky. This is one of those classic Go features that kind of works, but various Go commands will perform all kinds of confusing behavior like stripping directives out of your file if there's anything even a tiny bit wrong, and with no explanation whatsoever.

I found that to get this working I had to started with the "inner" dependencies like rivershared and rivertype, go get Go/toolchain there first, then work my way up the stack all the way up to the main project.

I'm going to try and follow this up with some tooling to help make this easier for ourselves, and a build check that verifies in CI that nothing gets accidentally regressed as we make changes because this is very easy to do accidentally.

Fixes #520.

[1] https://go.dev/doc/toolchain [2] https://go.dev/doc/toolchain#get

brandur commented 1 month ago

Thx.