Repository navigation
ci: bump Go to 1.26 and golangci-lint to v2 to unblock dependency updates - #1463
Iamrushabhshahh wants to merge 3 commits into
Conversation
…ates Recent dependency updates need Go >= 1.25, but CI is pinned to Go 1.22 and golangci-lint v1.56.2. golangci-lint v1 cannot load a module that targets Go 1.25 and fails with "unsupported version: 2" typecheck errors. - Set up Go 1.26 in the test, e2e and release workflows, and build the Docker image with golang:1.26. - Move to golangci-lint v2.14.0 with golangci-lint-action@v9 and migrate .golangci.yml to the v2 format, keeping the v1 rule set. - Update actions/checkout, actions/setup-go and actions/setup-node to v7 (Node 24 runtime) and actions-goveralls to v1.11.2. - Fix the go vet findings that newer Go toolchains report: slog calls with a missing key, and non-constant format strings. Co-authored-by: Iamrushabhshahh <rushabhshah842@gmail.com> Signed-off-by: Iamrushabhshahh <rushabhshah842@gmail.com>
mockey v1.2.10 links to runtime.sysAllocOS through go:linkname. Go 1.23 and later reject that at link time, so every test binary that imports mockey fails with: link: github.com/bytedance/mockey/internal/monkey/common: invalid reference to runtime.sysAllocOS mockey v1.4.6 supports Go 1.26 and still declares go 1.18, so the go directive in go.mod is unchanged. Co-authored-by: Iamrushabhshahh <rushabhshah842@gmail.com> Signed-off-by: Iamrushabhshahh <rushabhshah842@gmail.com>
golangci-lint v2 ships newer staticcheck, predeclared, prealloc and gofumpt versions. Fix what they now report: - staticcheck SA1006: use errors.New for constant messages in the secrets providers. - staticcheck S1009: drop nil checks that len() already covers. - predeclared: rename local "max" variables, which shadow the Go 1.21 builtin, to "maxItems". - prealloc: preallocate slices in non-test code, and skip prealloc in _test.go files. - gofumpt: reformat k8s_printer.go. - Match third_party, builtin and examples directories the way v1 did. Co-authored-by: Iamrushabhshahh <rushabhshah842@gmail.com> Signed-off-by: Iamrushabhshahh <rushabhshah842@gmail.com>
|
Note for review: |
|
Thanks so much for this, it's a really thorough migration, and I verified locally that it builds and tests the same on 1.22 and 1.26. To keep review and rollback simple, could we split it into two PRs? First, just the golangci-lint v2 migration on the current Go version. Then a smaller Go bump separately, to 1.25, which the new dependencies need. Also, the Makefile only installs the linter if none is found, so a local v1 would be picked up; a version check there would help. Happy to review both quickly! |
|
Hi @elliotxx, thanks for testing it on both versions. That makes sense. I've split it:
I'll close this one in favour of those two. |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Unblocks #1452, #1454, #1457, #1459 and #1460.
What is broken
Every open Dependabot Go module PR fails the
Golang LintandUnit tests with coveragejobs:All five raise the
godirective in go.mod from1.22.1to1.25.0, because the new versions need Go 1.25. The #1451 description already noted this: go-git v5.19.2 needs Go >= 1.25 while CI is pinned to 1.22.Root cause
CI installs Go 1.22 and golangci-lint v1.56.2. With
go 1.25.0in go.mod, Go 1.22 downloads a Go 1.25 toolchain on its own (GOTOOLCHAIN=auto), sogo buildworks. Three things then break.golangci-lint v1 cannot type check code for a newer Go. From the chore(deps): bump github.com/containerd/containerd from 1.7.23 to 1.7.36 #1460 lint job:
The last v1 release (v1.64.8, built with Go 1.24) refuses outright. I ran it locally on the chore(deps): bump github.com/containerd/containerd from 1.7.23 to 1.7.36 #1460 head:
So golangci-lint has to move to v2, and
.golangci.ymlhas to move to the v2 format.go vetin newer Go reports real problems. From the chore(deps): bump github.com/containerd/containerd from 1.7.23 to 1.7.36 #1460 unit test job (go vet ./...step):The slog finding shows up with Go 1.26 even on the current go.mod. The format string findings show up once go.mod says 1.24 or later.
Once vet passes, every test binary that imports mockey fails to link on Go 1.23 and later. I hit this in my fork's CI:
mockey v1.2.10 uses a
go:linknamethat newer linkers block.What this PR changes
There are three commits.
ci: bump Go to 1.26 and golangci-lint to v2 ....github/workflows/test.yaml,e2e-test.yml,release.yaml:go-version: '1.26';actions/checkout@v7,actions/setup-go@v7,actions/setup-node@v7(Node 24 runtime);golangci/golangci-lint-action@v9withversion: v2.14.0;shogo82148/actions-goveralls@v1.11.2..github/workflows/constraint.yaml:actions/checkout@v7.Dockerfile:golang:1.22togolang:1.26. The official Go images setGOTOOLCHAIN=local, so the image build would break as soon as go.mod says 1.25.Makefile:GOLINTER_VERSIONto v2.14.0 and the v2 module path forgo install..golangci.yml: migrated to v2 withgolangci-lint migrate, then tidied by hand to keep the v1 behaviour:gosimpleandstylecheckare now part ofstaticcheck.exportlooprefis gone (it was already inactive).typecheckcannot be listed any more.gofumptmoves toformatters.QF*quick fixes, which v1 never ran.inlineanalyser is disabled, as v1 did not have it.comments,common-false-positives,legacyandstd-error-handlingpresets, and the existingexcludetexts are kept as rules.go vetfindings:pkg/server/route/route.go,pkg/server/handler/endpoint/endpoint.go:logger.Error(err.Error(), "msg", "error", err)becomeslogger.Error("msg", "error", err). The old calls logged the error as the message and produced a!BADKEYattribute.pkg/engine/operation/watch.go,pkg/engine/runtime/terraform/tfops/tferrors.go:fmt.Errorf(s)becomeserrors.New(s).pkg/engine/operation/models/change.go:fmt.Printf(s)becomesfmt.Print(s).third_party/dyff/output_human.go:red(s)becomesred("%s", s)and so on. The output is identical.test: bump mockey to v1.4.6 ...go.mod,go.sum: mockey v1.2.10 to v1.4.6. Its release notes say it supports Go 1.26 and it still declaresgo 1.18, so ourgodirective stays at1.22.1.go mod tidyalso moves three test-only indirect dependencies (goconvey, assertions, gopherjs).style: fix findings reported by golangci-lint v2The newer linters inside v2 report 26 findings in
pkg/. All of them are mechanical:fmt.Errorf(errConst)becomeserrors.New(errConst)in the secrets providers.x == nil ||beforelen(x) == 0.maxink8s_printer.goshadows the Go 1.21 builtin, so I renamed it tomaxItems._test.gofiles.k8s_printer.go(*(x)becomes*x).third_party$, which does not match files inside them. I changed them to(^|/)third_party($|/), which is the pattern v1 used, so third_party stays out of lint as before.Why this option
godirective left at 1.22.1. Each Dependabot PR raises it when it needs to. That keeps this PR to CI and tooling, and the Dependabot PRs rebase on top unchanged.How I tested it
Locally on macOS arm64 with
GOTOOLCHAIN=go1.26.9:I ran lint only on the packages I changed locally. The full repository lint and the full
make coverran in CI on my fork. For that I added a temporary commit, which is not part of this PR, so thattest.yamlruns on push and lint prints every finding (--max-issues-per-linter=0 --max-same-issues=0):Golang Lintpassed with0 issues.andUnit tests with coveragepassed.Does this unblock Dependabot? I cherry-picked #1460 (containerd 1.7.36,
go 1.25.0) on top of this branch and resolved go.sum withgo mod tidy.go build ./...andgo vet ./...exit 0, and lint on the changed packages gives0 issues.Golang Lintpassed (0 issues.) andUnit tests with coveragepassed.Before these changes, the #1460 head failed both jobs (run linked above).
Risks and follow-ups
@dependabot rebase). They may conflict on go.sum because of the mockey bump. Dependabot resolves that itself.release.yamlstill usesdocker/login-action@v2andgoreleaser/goreleaser-action@v4. Their newer majors change defaults (goreleaser v2 needsversion: 2in the config), so I left them for a separate change. A tag push is the only way to test that workflow.check-md-links.yamlusesactions/checkout@master. I did not touch it.make lintinstalls v2.14.0 only if no golangci-lint is onPATH. Contributors with a v1 binary installed need to upgrade it.Which issue(s) this PR fixes:
Fixes #1462
Special notes for your reviewer:
@ruquanzhao, could you take a look when you have time? This is three commits, kept separate so they are easy to review: the CI and Go version change, the mockey bump, and the mechanical lint fixes. Once it is merged, the Dependabot PRs above need
@dependabot rebase.Does this PR introduce a user-facing change?
Additional documentation e.g., design docs, usage docs, etc.: