Skip to content

Commit

Permalink
Establish minimum Go version of 1.21, with toolchain of Go 1.22 (#522)
Browse files Browse the repository at this point in the history
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.mod`s 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 [email protected] [email protected]

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
  • Loading branch information
brandur committed Aug 9, 2024
1 parent e1846b0 commit f9619a0
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ on:

jobs:
build_and_test:
env:
# The special value "local" tells Go to use the bundled Go version rather
# than trying to fetch one according to a `toolchain` value in `go.mod`.
# This ensures that we're really running the Go version in the CI matrix
# rather than one that the Go command has upgraded to automatically.
GOTOOLCHAIN: local
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Derive all internal contexts from user-provided `Client` context. This includes the job fetch context, notifier unlisten, and completer. [PR #514](https://github.com/riverqueue/river/pull/514).
- Lowered the `go` directives in `go.mod` to Go 1.21, which River aims to support. A more modern version of Go is specified with the `toolchain` directive. This should provide more flexibility on the minimum required Go version for programs importing River. [PR #522](https://github.com/riverqueue/river/pull/522).

## [0.11.1] - 2024-08-05

Expand Down
16 changes: 10 additions & 6 deletions cmd/river/go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
module github.com/riverqueue/river/cmd/river

go 1.22.5
go 1.21

// replace github.com/riverqueue/river => ../..
toolchain go1.22.5

// replace github.com/riverqueue/river/riverdriver => ../../riverdriver
replace github.com/riverqueue/river => ../..

// replace github.com/riverqueue/river/riverdriver/riverdatabasesql => ../../riverdriver/riverdatabasesql
replace github.com/riverqueue/river/riverdriver => ../../riverdriver

// replace github.com/riverqueue/river/riverdriver/riverpgxv5 => ../../riverdriver/riverpgxv5
replace github.com/riverqueue/river/riverdriver/riverdatabasesql => ../../riverdriver/riverdatabasesql

// replace github.com/riverqueue/river/rivertype => ../../rivertype
replace github.com/riverqueue/river/riverdriver/riverpgxv5 => ../../riverdriver/riverpgxv5

replace github.com/riverqueue/river/rivershared => ../../rivershared

replace github.com/riverqueue/river/rivertype => ../../rivertype

require (
github.com/jackc/pgx/v5 v5.6.0
Expand Down
12 changes: 0 additions & 12 deletions cmd/river/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ github.com/lmittmann/tint v1.0.4 h1:LeYihpJ9hyGvE0w+K2okPTGUdVLfng1+nDNVR4vWISc=
github.com/lmittmann/tint v1.0.4/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/riverqueue/river v0.11.1 h1:/etRDY73opKDNNeY+mPlPrIYszRdGUduFtsBmRwzChY=
github.com/riverqueue/river v0.11.1/go.mod h1:BaMj1UOC8mjMBlSY7Sjmuywm8XlkhgHkzNfH3eaX47g=
github.com/riverqueue/river/riverdriver v0.11.1 h1:AYgVhwL3Ifu6EO3fi4WjyVlHJVvbATbJnw37nSmUH6c=
github.com/riverqueue/river/riverdriver v0.11.1/go.mod h1:po4YTDEJRjxzdxK+IQ4Bu1JsW1PPQfslMdkj5rNNY9c=
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.11.1 h1:b81ZT8X8Kdrulim4hJ5wmQGQyumpQPsjepA6d+MxH3Y=
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.11.1/go.mod h1:Do5dgb+TsHC6O+NIyZx3SHbLIxKlEK8VeIsopgmVo1A=
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.11.1 h1:tmGBw3I52Fzj/W5KesGJPF0D7xOj83rnL4igd433UyI=
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.11.1/go.mod h1:rdDGaq/SOpfnqk0hRjvNAs+xqdvK6EkASh6tknbx2x4=
github.com/riverqueue/river/rivershared v0.11.1 h1:5HDZ5fPrHf68lrE2CTTTUfRfdCmfW1G6P/v0zCvor7I=
github.com/riverqueue/river/rivershared v0.11.1/go.mod h1:2egnQ7czNcW8IXKXMRjko0aEMrQzF4V3k3jddmYiihE=
github.com/riverqueue/river/rivertype v0.11.1 h1:sdrGb07cAGOy5f20HO/b2xts8Bz7lKCZLHl6jifzJ7A=
github.com/riverqueue/river/rivertype v0.11.1/go.mod h1:nDd50b/mIdxR/ezQzGS/JiAhBPERA7tUIne21GdfspQ=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/riverqueue/river

go 1.22.5
go 1.21

toolchain go1.22.5

replace github.com/riverqueue/river/riverdriver => ./riverdriver

Expand Down
2 changes: 1 addition & 1 deletion internal/jobcompleter/job_completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func withRetries[T any](logCtx context.Context, baseService *baseservice.BaseSer
ctx, cancel := context.WithTimeout(uncancelledCtx, timeout)
defer cancel()

retVal, err := retryFunc(ctx) //nolint:contextcheck
retVal, err := retryFunc(ctx)
if err != nil {
// A cancelled context will never succeed, return immediately.
if errors.Is(err, context.Canceled) {
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Subscription struct {
func (s *Subscription) Unlisten(ctx context.Context) {
s.unlistenOnce.Do(func() {
// Unlisten strips cancellation from the parent context to ensure it runs:
if err := s.notifier.unlisten(context.WithoutCancel(ctx), s); err != nil { //nolint:contextcheck
if err := s.notifier.unlisten(context.WithoutCancel(ctx), s); err != nil {
s.notifier.Logger.ErrorContext(ctx, s.notifier.Name+": Error unlistening on topic", "err", err, "topic", s.topic)
}
})
Expand Down
4 changes: 3 additions & 1 deletion riverdriver/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/riverqueue/river/riverdriver

go 1.21.4
go 1.21

toolchain go1.22.5

replace github.com/riverqueue/river/rivertype => ../rivertype

Expand Down
4 changes: 3 additions & 1 deletion riverdriver/riverdatabasesql/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/riverqueue/river/riverdriver/riverdatabasesql

go 1.22.5
go 1.21

toolchain go1.22.5

replace github.com/riverqueue/river/riverdriver => ../

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func TestReplaceNamed(t *testing.T) {
{Desc: "SliceUint64", ExpectedSQL: "SELECT ARRAY[123,124]", InputSQL: "SELECT @slice_uint64", InputArgs: map[string]any{"slice_uint64": []uint64{123, 124}}},
}
for _, tt := range testCases {
tt := tt

t.Run(tt.Desc, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 3 additions & 1 deletion riverdriver/riverpgxv5/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/riverqueue/river/riverdriver/riverpgxv5

go 1.22.5
go 1.21

toolchain go1.22.5

replace github.com/riverqueue/river/riverdriver => ../

Expand Down
4 changes: 3 additions & 1 deletion rivershared/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/riverqueue/river/rivershared

go 1.22.5
go 1.21

toolchain go1.22.5

require (
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 3 additions & 1 deletion rivertype/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/riverqueue/river/rivertype

go 1.21.4
go 1.21

toolchain go1.22.5

require github.com/stretchr/testify v1.9.0

Expand Down

0 comments on commit f9619a0

Please sign in to comment.