Skip to content

Commit 5484de9

Browse files
committed
chore: Use go 1.24's 'go tool' support for CLI tooling
This change mirrors a change already made to avalanchego and avoids the problem of a cached version of golangci-lint being incompatible with a new version of golang when upgrading the golang version between minor versions.
1 parent a0df90c commit 5484de9

File tree

20 files changed

+2587
-42
lines changed

20 files changed

+2587
-42
lines changed

.github/CONTRIBUTING.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc
4040
* To **re-generate all mocks**, use the command below from the root of the project:
4141

4242
```sh
43-
go generate -run "go.uber.org/mock/mockgen" ./...
43+
go generate -run mockgen ./...
4444
```
4545

4646
* To **add** an interface that needs a corresponding mock generated:
4747
* if the file `mocks_generate_test.go` exists in the package where the interface is located, either:
48-
* modify its `//go:generate go run go.uber.org/mock/mockgen` to generate a mock for your interface (preferred); or
49-
* add another `//go:generate go run go.uber.org/mock/mockgen` to generate a mock for your interface according to specific mock generation settings
48+
* modify its `//go:generate go tool -modfile=tools/go.mod mockgen` to generate a mock for your interface (preferred); or
49+
* add another `//go:generate go tool -modfile=tools/go.mod mockgen` to generate a mock for your interface according to specific mock generation settings
5050
* if the file `mocks_generate_test.go` does not exist in the package where the interface is located, create it with content (adapt as needed):
5151

5252
```go
@@ -55,7 +55,7 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc
5555
5656
package mypackage
5757
58-
//go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mocks_test.go . YourInterface
58+
//go:generate go tool -modfile=tools/go.mod mockgen -package=${GOPACKAGE} -destination=mocks_test.go . YourInterface
5959
```
6060

6161
Notes:
@@ -66,3 +66,26 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc
6666
1. If the `//go:generate` mockgen command line:
6767
* generates a mock file for multiple interfaces, remove your interface from the line
6868
* generates a mock file only for the interface, remove the entire line. If the file is empty, remove `mocks_generate_test.go` as well.
69+
70+
## Tool Dependencies
71+
72+
This project uses `go tool` to manage development tool dependencies in `tools/go.mod`. This isolates tool dependencies from the main application dependencies and provides consistent, version-locked tools across the team.
73+
74+
### Managing Tools
75+
76+
* To **add a new tool**:
77+
```sh
78+
go get -tool -modfile=tools/go.mod example.com/tool/cmd/toolname@version
79+
```
80+
81+
* To **upgrade a tool**:
82+
```sh
83+
go get -tool -modfile=tools/go.mod example.com/tool/cmd/toolname@newversion
84+
```
85+
86+
* To **run a tool manually**:
87+
```sh
88+
go tool -modfile=tools/go.mod toolname [args...]
89+
```
90+
91+
Note: `ginkgo` remains in the main `go.mod` as it is used directly in e2e test code.

.github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
- uses: actions/setup-go@v5
3434
with:
3535
go-version-file: "go.mod"
36+
cache-dependency-path: |
37+
go.sum
38+
tools/go.sum
39+
tools/legacy-golangci-lint.sum
3640
- name: change avalanchego dep
3741
if: ${{ github.event_name == 'workflow_dispatch' }}
3842
run: |
@@ -67,6 +71,9 @@ jobs:
6771
- uses: actions/setup-go@v5
6872
with:
6973
go-version-file: "go.mod"
74+
cache-dependency-path: |
75+
go.sum
76+
tools/go.sum
7077
- name: change avalanchego dep
7178
if: ${{ github.event_name == 'workflow_dispatch' }}
7279
run: |
@@ -96,9 +103,6 @@ jobs:
96103
ref: ${{ github.event.inputs.avalanchegoBranch }}
97104
path: avalanchego
98105
token: ${{ secrets.AVALANCHE_PAT }}
99-
- uses: actions/setup-go@v5
100-
with:
101-
go-version-file: "go.mod"
102106
- name: Run e2e tests
103107
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@23ace817fe84e8f9b20bf1155075f8d4541d4295
104108
with:
@@ -120,10 +124,6 @@ jobs:
120124
uses: actions/checkout@v4
121125
with:
122126
fetch-depth: 0
123-
- name: Set up Go
124-
uses: actions/setup-go@v5
125-
with:
126-
go-version-file: "go.mod"
127127
- name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }}
128128
if: ${{ github.event_name == 'workflow_dispatch' }}
129129
uses: actions/checkout@v4

Taskfile.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ tasks:
5959
- task: check-clean-branch
6060

6161
check-go-mod-tidy:
62-
desc: Checks that go.mod and go.sum are up-to-date (requires a clean git working tree)
62+
desc: Checks that all go.mod and go.sum files are up-to-date (requires a clean git working tree)
6363
cmds:
6464
- cmd: go mod tidy
6565
- task: check-clean-branch
66+
- cmd: cd tools && go mod tidy
67+
- task: check-clean-branch
68+
- cmd: cd tools && go mod tidy -modfile=legacy-golangci-lint.mod
69+
- task: check-clean-branch
6670

6771
coverage:
6872
desc: Display test coverage statistics from coverage.out file
@@ -72,19 +76,19 @@ tasks:
7276
desc: Generates fjl/gencodec files
7377
cmds:
7478
- cmd: grep -lr -E '^// Code generated by github\.com\/fjl\/gencodec\. DO NOT EDIT\.$' . | xargs -r rm
75-
- cmd: go generate -run "github.com/fjl/gencodec" ./...
79+
- cmd: go generate -run gencodec ./...
7680

7781
generate-mocks:
7882
desc: Generates testing mocks
7983
cmds:
8084
- cmd: grep -lr -E '^// Code generated by MockGen\. DO NOT EDIT\.$' . | xargs -r rm
81-
- cmd: go generate -run "go.uber.org/mock/mockgen" ./...
85+
- cmd: go generate -run mockgen ./...
8286

8387
generate-rlp:
8488
desc: Generates rlp files
8589
cmds:
8690
- cmd: grep -lr -E '^// Code generated by rlpgen\. DO NOT EDIT.\.$' . | xargs -r rm
87-
- cmd: go generate -run "github.com/ava-labs/libevm/rlp/rlpgen" ./...
91+
- cmd: go generate -run rlpgen ./...
8892

8993
lint:
9094
desc: Run golangci-lint and check for allowed Ethereum imports in Go code

bin/ginkgo

Lines changed: 0 additions & 13 deletions
This file was deleted.

bin/ginkgo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/run_ginkgo.sh

core/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import (
5555
"github.com/holiman/uint256"
5656
)
5757

58-
//go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
58+
//go:generate go tool -modfile=../tools/go.mod gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
5959

6060
var errGenesisNoConfig = errors.New("genesis has no chain configuration")
6161

eth/ethconfig/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func NewDefaultConfig() Config {
7575
}
7676
}
7777

78-
//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
78+
//go:generate go tool -modfile=../../tools/go.mod gencodec -type Config -formats toml -out gen_config.go
7979

8080
// Config contains configuration options for ETH and LES protocols.
8181
type Config struct {

go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
module github.com/ava-labs/coreth
22

3+
// CLI tools intended for invocation with `go tool` should be added to
4+
// tools/go.mod to avoid polluting the main module's dependencies. See
5+
// CONTRIBUTING.md for more details.
6+
7+
// - Changes to the minimum golang version must also be replicated in:
8+
// - go.mod (here)
9+
// - tools/go.mod
10+
// - tools/legacy-golangci-lint.mod
11+
//
12+
// - If updating between minor versions (e.g. 1.24.x -> 1.25.x):
13+
// - Consider updating the version of golangci-lint (see tools/go.mod)
314
go 1.24.7
415

516
require (
@@ -175,3 +186,10 @@ require (
175186
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
176187
sigs.k8s.io/yaml v1.3.0 // indirect
177188
)
189+
190+
// The following tools are managed here instead of in tools/go.mod
191+
// because they are already direct dependencies of the main module.
192+
tool (
193+
github.com/ava-labs/libevm/rlp/rlpgen
194+
github.com/onsi/ginkgo/v2/ginkgo
195+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package ethapi
22

3-
//go:generate go run go.uber.org/mock/mockgen -package=$GOPACKAGE -destination=mocks_test.go . Backend
3+
//go:generate go tool -modfile=../../tools/go.mod mockgen -package=$GOPACKAGE -destination=mocks_test.go . Backend

plugin/evm/customtypes/header_ext.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ func (h *HeaderSerializable) updateToExtras(extras *HeaderExtra) {
178178
// NOTE: both generators currently do not support type aliases.
179179
// We are using custom versions of these programs for now to support type aliases,
180180
// see https://github.com/ava-labs/coreth/pull/746#discussion_r1969673252
181-
//go:generate go run github.com/fjl/gencodec -type HeaderSerializable -field-override headerMarshaling -out gen_header_serializable_json.go
182-
//go:generate go run github.com/ava-labs/libevm/rlp/rlpgen -type HeaderSerializable -out gen_header_serializable_rlp.go
181+
//go:generate go tool -modfile=../../../tools/go.mod gencodec -type HeaderSerializable -field-override headerMarshaling -out gen_header_serializable_json.go
182+
//go:generate go tool rlpgen -type HeaderSerializable -out gen_header_serializable_rlp.go
183183

184184
// HeaderSerializable defines the header of a block in the Ethereum blockchain,
185185
// as it is to be serialized into RLP and JSON. Note it must be exported so that

0 commit comments

Comments
 (0)