Skip to content

Commit 3eda791

Browse files
authored
Move submodule update command to rivershared + check for go/toolchain + workspace (riverqueue#528)
This one's a bit of a grab bucket, but do a few refactors and additions: * Bring the project over to use a Go workspace, thereby letting us run tests and programs across module directories and cut out our `replace` statements in `go.mod` all over the place. * Move the River version update program for `go.mod` files over to `rivershared` so that it can be used by other River projects. It's modified so that instead of hardcoding a submodule list, it can now read them straight out of the project's workspace in `go.work`. * Add a new program that's similar to this one whose job it is to check that the `go`/`toolchain` directives across all `go.mod`s in the workspace match, which will help prevent accidental regressions of riverqueue#522. It can also be used locally to update `go`/`toolchain` directives to new values in case we want to do that in the future. * Do a lot of repaving in `Makefile` so that we can use list of submodules from the workspace to run a series of commands instead of needing to maintain independent lists for each target, a practice that was often unreliable.
1 parent e97f2a3 commit 3eda791

File tree

21 files changed

+499
-174
lines changed

21 files changed

+499
-174
lines changed

.github/workflows/ci.yaml

+18-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828
strategy:
2929
matrix:
3030
go-version:
31-
- "1.22"
3231
- "1.21"
33-
postgres-version: [16, 15, 14]
32+
- "1.22"
33+
postgres-version: [14, 15, 16]
3434
fail-fast: false
3535
timeout-minutes: 5
3636

@@ -59,10 +59,7 @@ jobs:
5959
run: go version
6060

6161
- name: Install dependencies
62-
run: |
63-
echo "::group::go get"
64-
go get -t ./...
65-
echo "::endgroup::"
62+
run: go get -t ./...
6663

6764
- name: Set up test DBs
6865
run: go run ./internal/cmd/testdbman create
@@ -265,3 +262,18 @@ jobs:
265262
run: |
266263
echo "Make sure that all sqlc changes are checked in"
267264
make verify/sqlc
265+
266+
submodule_check:
267+
runs-on: ubuntu-latest
268+
269+
steps:
270+
- uses: actions/setup-go@v5
271+
with:
272+
go-version: "stable"
273+
check-latest: true
274+
275+
- name: Checkout
276+
uses: actions/checkout@v4
277+
278+
- name: Check all go/toolchain directives match
279+
run: CHECK=true make update-mod-go

Makefile

+52-36
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,87 @@
1-
.PHONY: generate
2-
generate:
3-
generate: generate/migrations
4-
generate: generate/sqlc
1+
.DEFAULT_GOAL := help
52

63
.PHONY: db/reset
7-
db/reset: ## drop, create, and migrate dev and test databases
4+
db/reset: ## Drop, create, and migrate dev and test databases
85
db/reset: db/reset/dev
96
db/reset: db/reset/test
107

118
.PHONY: db/reset/dev
12-
db/reset/dev: ## drop, create, and migrate dev database
9+
db/reset/dev: ## Drop, create, and migrate dev database
1310
dropdb river_dev --force --if-exists
1411
createdb river_dev
1512
cd cmd/river && go run . migrate-up --database-url "postgres://localhost/river_dev"
1613

1714
.PHONY: db/reset/test
18-
db/reset/test: ## drop, create, and migrate test databases
15+
db/reset/test: ## Drop, create, and migrate test databases
1916
go run ./internal/cmd/testdbman reset
2017

18+
.PHONY: generate
19+
generate: ## Generate generated artifacts
20+
generate: generate/migrations
21+
generate: generate/sqlc
22+
2123
.PHONY: generate/migrations
22-
generate/migrations: ## sync changes of pgxv5 migrations to database/sql
24+
generate/migrations: ## Sync changes of pgxv5 migrations to database/sql
2325
rsync -au --delete "riverdriver/riverpgxv5/migration/" "riverdriver/riverdatabasesql/migration/"
2426

2527
.PHONY: generate/sqlc
26-
generate/sqlc:
28+
generate/sqlc: ## Generate sqlc
2729
cd riverdriver/riverdatabasesql/internal/dbsqlc && sqlc generate
2830
cd riverdriver/riverpgxv5/internal/dbsqlc && sqlc generate
2931

32+
# Looks at comments using ## on targets and uses them to produce a help output.
33+
.PHONY: help
34+
help: ALIGN=22
35+
help: ## Print this message
36+
@awk -F '::? .*## ' -- "/^[^':]+::? .*## /"' { printf "'$$(tput bold)'%-$(ALIGN)s'$$(tput sgr0)' %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
37+
38+
# Each directory of a submodule in the Go workspace. Go commands provide no
39+
# built-in way to run for all workspace submodules. Add a new submodule to the
40+
# workspace with `go work use ./driver/new`.
41+
submodules := $(shell go list -f '{{.Dir}}' -m)
42+
43+
# Definitions of following tasks look ugly, but they're done this way because to
44+
# produce the best/most comprehensible output by far (e.g. compared to a shell
45+
# loop).
3046
.PHONY: lint
31-
lint:
32-
cd . && golangci-lint run --fix
33-
cd cmd/river && golangci-lint run --fix
34-
cd riverdriver && golangci-lint run --fix
35-
cd riverdriver/riverdatabasesql && golangci-lint run --fix
36-
cd riverdriver/riverpgxv5 && golangci-lint run --fix
37-
cd rivershared && golangci-lint run --fix
38-
cd rivertype && golangci-lint run --fix
47+
lint:: ## Run linter (golangci-lint) for all submodules
48+
define lint-target
49+
lint:: ; cd $1 && golangci-lint run --fix
50+
endef
51+
$(foreach mod,$(submodules),$(eval $(call lint-target,$(mod))))
3952

4053
.PHONY: test
41-
test:
42-
cd . && go test ./... -p 1
43-
cd cmd/river && go test ./...
44-
cd riverdriver && go test ./...
45-
cd riverdriver/riverdatabasesql && go test ./...
46-
cd riverdriver/riverpgxv5 && go test ./...
47-
cd rivershared && go test ./...
48-
cd rivertype && go test ./...
54+
test:: ## Run test suite for all submodules
55+
define test-target
56+
test:: ; cd $1 && go test ./... -p 1
57+
endef
58+
$(foreach mod,$(submodules),$(eval $(call test-target,$(mod))))
4959

5060
.PHONY: tidy
51-
tidy:
52-
cd . && go mod tidy
53-
cd cmd/river && go mod tidy
54-
cd riverdriver && go mod tidy
55-
cd riverdriver/riverdatabasesql && go mod tidy
56-
cd riverdriver/riverpgxv5 && go mod tidy
57-
cd rivertype && go mod tidy
61+
tidy:: ## Run `go mod tidy` for all submodules
62+
define tidy-target
63+
tidy:: ; cd $1 && go mod tidy
64+
endef
65+
$(foreach mod,$(submodules),$(eval $(call tidy-target,$(mod))))
66+
67+
.PHONY: update-mod-go
68+
update-mod-go: ## Update `go`/`toolchain` directives in all submodules to match `go.work`
69+
go run ./rivershared/cmd/update-mod-go ./go.work
70+
71+
.PHONY: update-mod-version
72+
update-mod-version: ## Update River packages in all submodules to $VERSION
73+
go run ./rivershared/cmd/update-mod-version ./go.work
5874

5975
.PHONY: verify
60-
verify:
76+
verify: ## Verify generated artifacts
6177
verify: verify/migrations
6278
verify: verify/sqlc
6379

6480
.PHONY: verify/migrations
65-
verify/migrations:
81+
verify/migrations: ## Verify synced migrations
6682
diff -qr riverdriver/riverpgxv5/migration riverdriver/riverdatabasesql/migration
6783

6884
.PHONY: verify/sqlc
69-
verify/sqlc:
85+
verify/sqlc: ## Verify generated sqlc
7086
cd riverdriver/riverdatabasesql/internal/dbsqlc && sqlc diff
71-
cd riverdriver/riverpgxv5/internal/dbsqlc && sqlc diff
87+
cd riverdriver/riverpgxv5/internal/dbsqlc && sqlc diff

cmd/river/go.mod

-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ go 1.21
44

55
toolchain go1.22.5
66

7-
// replace github.com/riverqueue/river => ../..
8-
9-
// replace github.com/riverqueue/river/riverdriver => ../../riverdriver
10-
11-
// replace github.com/riverqueue/river/riverdriver/riverdatabasesql => ../../riverdriver/riverdatabasesql
12-
13-
// replace github.com/riverqueue/river/riverdriver/riverpgxv5 => ../../riverdriver/riverpgxv5
14-
15-
// replace github.com/riverqueue/river/rivershared => ../../rivershared
16-
17-
// replace github.com/riverqueue/river/rivertype => ../../rivertype
18-
197
require (
208
github.com/jackc/pgx/v5 v5.6.0
219
github.com/lmittmann/tint v1.0.4

docs/development.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ queries. After changing an sqlc `.sql` file, generate Go with:
3030
```shell
3131
git checkout master && git pull --rebase
3232
export VERSION=v0.x.y
33-
go run ./internal/cmd/update-submodule-versions/main.go
33+
make update-mod-version
3434
git checkout -b $USER-$VERSION
3535
```
3636

go.mod

-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@ go 1.21
44

55
toolchain go1.22.5
66

7-
replace github.com/riverqueue/river/riverdriver => ./riverdriver
8-
9-
replace github.com/riverqueue/river/riverdriver/riverpgxv5 => ./riverdriver/riverpgxv5
10-
11-
replace github.com/riverqueue/river/riverdriver/riverdatabasesql => ./riverdriver/riverdatabasesql
12-
13-
replace github.com/riverqueue/river/rivershared => ./rivershared
14-
15-
replace github.com/riverqueue/river/rivertype => ./rivertype
16-
177
require (
188
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
199
github.com/jackc/pgx/v5 v5.6.0
@@ -26,7 +16,6 @@ require (
2616
github.com/robfig/cron/v3 v3.0.1
2717
github.com/stretchr/testify v1.9.0
2818
go.uber.org/goleak v1.3.0
29-
golang.org/x/mod v0.20.0
3019
golang.org/x/sync v0.8.0
3120
golang.org/x/text v0.17.0
3221
)

go.sum

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
1919
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
2020
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2121
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
22+
github.com/riverqueue/river/riverdriver v0.11.2 h1:2xC+R0Y+CFEOSDWKyeFef0wqQLuvhk3PsLkos7MLa1w=
23+
github.com/riverqueue/river/riverdriver v0.11.2/go.mod h1:RhMuAjEtNGexwOFnz445G1iFNZVOnYQ90HDYxHMI+jM=
24+
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.11.2 h1:I4ye1YEa35kqB6Jd3xVPNxbGDL6S1gpSTkZu25qffhc=
25+
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.11.2/go.mod h1:+cOcD4U+8ugUeRZVTGqVhtScy0FS7LPyp+ZsoPIeoMI=
26+
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.11.2 h1:yxFi09ECN02iAr2uO0n7QhFKAyyGZ+Rn9fzKTt2TGhk=
27+
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.11.2/go.mod h1:ajPqIw7OgYBfR24MqH3VGI/SiYVgq0DkvdM7wrs+uDA=
28+
github.com/riverqueue/river/rivershared v0.11.2 h1:VbuLE6zm68R24xBi1elfnerhLBBn6X7DUxR9j4mcTR4=
29+
github.com/riverqueue/river/rivershared v0.11.2/go.mod h1:J4U3qm8MbjHY1o5OlRNiWaminYagec1o8sHYX4ZQ4S4=
30+
github.com/riverqueue/river/rivertype v0.11.2 h1:YREWOGxDMDe1DTdvttwr2DVq/ql65u6e4jkw3VxuNyU=
31+
github.com/riverqueue/river/rivertype v0.11.2/go.mod h1:bm5EMOGAEWhtXKqo27POWnViqSD5nHMZDP/jsrJc530=
2232
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
2333
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
2434
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
@@ -32,8 +42,6 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
3242
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
3343
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
3444
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
35-
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
36-
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
3745
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
3846
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
3947
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=

go.work

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
go 1.21
2+
3+
toolchain go1.22.5
4+
5+
use (
6+
.
7+
./cmd/river
8+
./riverdriver
9+
./riverdriver/riverdatabasesql
10+
./riverdriver/riverpgxv5
11+
./rivershared
12+
./rivertype
13+
)

go.work.sum

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
2+
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
3+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
5+
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
6+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
7+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
9+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
10+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
11+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
12+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
13+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
14+
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
15+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
16+
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
17+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
18+
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
19+
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
20+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
21+
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
22+
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
23+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
24+
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
25+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26+
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
27+
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
28+
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
29+
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY=
30+
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
31+
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
32+
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
33+
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
34+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
35+
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
36+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
37+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
38+
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=

internal/cmd/update-submodule-versions/main_test.go

-72
This file was deleted.

riverdriver/go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ go 1.21
44

55
toolchain go1.22.5
66

7-
replace github.com/riverqueue/river/rivertype => ../rivertype
8-
97
require github.com/riverqueue/river/rivertype v0.11.2

riverdriver/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/riverqueue/river/rivertype v0.11.2 h1:YREWOGxDMDe1DTdvttwr2DVq/ql65u6e4jkw3VxuNyU=
6+
github.com/riverqueue/river/rivertype v0.11.2/go.mod h1:bm5EMOGAEWhtXKqo27POWnViqSD5nHMZDP/jsrJc530=
57
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
68
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
79
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)