Skip to content

build: move dev tools into per-tool Go modules#20293

Merged
arthurschreiber merged 2 commits into
mainfrom
arthur/per-tool-go-modules
Jun 11, 2026
Merged

build: move dev tools into per-tool Go modules#20293
arthurschreiber merged 2 commits into
mainfrom
arthur/per-tool-go-modules

Conversation

@arthurschreiber

@arthurschreiber arthurschreiber commented Jun 11, 2026

Copy link
Copy Markdown
Member

Description

This moves our dev tools out of the main module graph so tool dependencies can't influence application dependency resolution (and vice versa):

  • gofumpt, goimports, gotestsum, goyacc, golangci-lint each get their own pinned module under tools/, invoked via go tool -modfile=.... Everything stays at exactly the version we use today, so this is pure plumbing — no reformatting or lint fallout.
  • The protoc plugins (protoc-gen-go, protoc-gen-go-grpc, protoc-gen-go-vtproto) become tool directives in the main go.mod. The first and last are packages inside the protobuf/vtprotobuf runtime modules, so the generated code can no longer drift from the runtime libraries — same require line. The install_protoc-gen-go make target is gone; make proto resolves the plugin binaries straight out of the Go build cache with go tool -n.

Some inconsistencies this cleans up along the way:

  • goimports was installed ad-hoc in four CI workflows (one of them pinned differently from the others) and never had a go.sum-verified pin. Now it does, and the install steps are deleted — go/tools/codegen resolves the formatters via their modfiles instead of $PATH.
  • protoc-gen-go-grpc sat in the main go.mod at v1.6.2 (kept alive by tools/tools.go, dutifully bumped by dependabot) while the Makefile hardcoded @v1.2.0. It's now an honest require at v1.2.0 with a dependabot ignore, since bumping it changes the generated API and needs to be a conscious decision.
  • The lint-fmt git hook no longer version-compares a $PATH-installed golangci-lint against build.envgo tool builds the pinned version on demand. That also fixes the hook accepting a newer local lint version than CI uses.

A nice property for git worktrees: all tool resolution is anchored to the current checkout (relative -modfile paths, go env GOMOD in the codegen wrapper, git rev-parse --show-toplevel in the hook), so each worktree uses its own tools/*/go.mod at its own commit — a worktree on an older release branch automatically gets that branch's pinned tool versions. With $PATH-installed tools that was never guaranteed. The module and build caches stay per-user, so a given tool version is still only downloaded and compiled once across all worktrees.

CI changes: the tidy check now covers the tool modules, the go_files filter triggers on tool-module changes, and the Go caches hash tools/**/go.sum too. Dependabot bumps the light tools as a group and golangci-lint in its own PR (lint bumps can change findings).

Verified that proto, sqlparser, sizegen, and vtctldclient regeneration all produce byte-identical output, including make proto from a clean build cache.

Related Issue(s)

N/A

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

N/A — developer tooling and CI only, no runtime changes.

Backporting

I'd like to backport this to release-23.0 and release-24.0, because it's a significant QoL improvement when switching between branches / working on backports.

AI Disclosure

This PR was written primarily by Claude Code — I provided direction and review.


🤖 Generated with Claude Code

Move the dev tools (gofumpt, goimports, gotestsum, goyacc,
golangci-lint) out of the main module graph into isolated, pinned
modules under tools/, invoked via `go tool -modfile=...`. The protoc
plugins become tool directives in the main go.mod so that
protoc-gen-go and protoc-gen-go-vtproto always build at the same
version as the protobuf/vtprotobuf runtime libraries; the
install_protoc-gen-go make target is replaced by resolving plugin
binaries straight from the Go build cache with `go tool -n`.

Every tool stays at exactly the version in use before; goimports gets
a go.sum-verified pin for the first time, replacing four ad-hoc
`go install` steps in CI. golangci-lint is now pinned in its tool
module instead of build.env, and the lint-fmt git hook builds it on
demand instead of comparing versions of a PATH-installed binary.
protoc-gen-go-grpc becomes an honest direct require at v1.2.0 (the
version the Makefile actually installed) instead of the unused v1.6.2
that dependabot had been bumping.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Copilot AI review requested due to automatic review settings June 11, 2026 10:27
@github-actions github-actions Bot added this to the v25.0.0 milestone Jun 11, 2026
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jun 11, 2026
@vitess-bot

vitess-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures Vitess developer tooling dependencies so they no longer participate in (or get influenced by) the main module’s dependency graph, while keeping tool versions pinned and reproducible across local dev and CI.

Changes:

  • Moved several dev tools (gofumpt, goimports, gotestsum, goyacc, golangci-lint) into dedicated tools/<tool>/ Go modules and updated scripts/Make targets to run them via go tool -modfile=....
  • Replaced the legacy tools/tools.go “tools” pattern by using tool directives in the root go.mod for protoc plugins, and adjusted make proto to locate plugin binaries via go tool -n.
  • Updated CI caching, change detection, tidy checks, and Dependabot configuration to account for the new tool modules.

Reviewed changes

Copilot reviewed 22 out of 28 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/unit_test_runner.sh Runs gotestsum via the pinned tool-module modfile.
tools/e2e_go_test.sh Runs gotestsum via the pinned tool-module modfile for e2e harness.
tools/check_make_parser.sh Switches parser regeneration checks to pinned goyacc/goimports/gofumpt tool modules.
misc/git/hooks/lint-fmt Runs golangci-lint via pinned tool-module modfile instead of $PATH/version checks.
Makefile Uses pinned tool modules for lint/format; removes install target for protoc plugins and resolves them via go tool -n.
go/vt/vtctl/vtctldclient/Makefile Formats generated client code via pinned gofumpt modfile.
go/vt/sqlparser/generate.go Updates go:generate directives to use pinned tool-module modfiles.
go/tools/codegen/goimports.go Executes goimports/gofumpt via go tool -modfile=... using repo-root resolution.
tools/tools.go Removes the legacy “tools” build-tag file that pinned tool deps in the main module graph.
tools/gofumpt/go.mod Adds a dedicated Go module to pin gofumpt as a tool.
tools/gofumpt/go.sum Checksums for the pinned gofumpt tool module.
tools/goimports/go.mod Adds a dedicated Go module to pin goimports as a tool.
tools/goimports/go.sum Checksums for the pinned goimports tool module.
tools/gotestsum/go.mod Adds a dedicated Go module to pin gotestsum as a tool.
tools/gotestsum/go.sum Checksums for the pinned gotestsum tool module.
tools/goyacc/go.mod Adds a dedicated Go module to pin goyacc as a tool.
tools/goyacc/go.sum Checksums for the pinned goyacc tool module.
tools/golangci-lint/go.mod Adds a dedicated Go module to pin golangci-lint as a tool.
tools/golangci-lint/go.sum Checksums for the pinned golangci-lint tool module.
go.mod Replaces tool pinning approach: removes tool pins for formatting/testing tools; adds tool directives for protoc plugins and pins protoc-gen-go-grpc.
go.sum Drops now-unneeded tool-related sums from the main module; updates sums for the new root requirements.
build.env Removes golangci-lint version export since lint version is now pinned by tool module.
.github/workflows/unit_test.yml Updates Go cache dependency paths; removes ad-hoc goimports install; uses pinned gotestsum modfile.
.github/workflows/static_checks_etc.yml Expands change filters and cache deps for tool modules; runs go mod tidy across tool modules; derives golangci-lint version from tool module.
.github/workflows/codecov.yml Updates Go cache dependency paths; removes ad-hoc goimports install.
.github/workflows/check_make_vtadmin_authz_testgen.yml Updates Go cache dependency paths; removes ad-hoc goimports install.
.github/dependabot.yml Adds separate update groups for tool modules; ignores protoc-gen-go-grpc auto-bumps.
.github/actions/setup-go/action.yml Includes tools/**/go.sum in Go cache key hashing to avoid stale caches.

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.26%. Comparing base (70c7a72) to head (2c090e9).
⚠️ Report is 311 commits behind head on main.

Files with missing lines Patch % Lines
go/tools/codegen/goimports.go 76.92% 3 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (70c7a72) and HEAD (2c090e9). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (70c7a72) HEAD (2c090e9)
1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #20293       +/-   ##
===========================================
- Coverage   69.67%   56.26%   -13.41%     
===========================================
  Files        1614       46     -1568     
  Lines      216793    14176   -202617     
===========================================
- Hits       151044     7976   -143068     
+ Misses      65749     6200    -59549     
Flag Coverage Δ
partial 56.26% <76.92%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arthurschreiber arthurschreiber marked this pull request as ready for review June 11, 2026 11:15
@arthurschreiber arthurschreiber added Backport to: release-23.0 Needs to be backport to release-23.0 Backport to: release-24.0 Needs to be backport to release-24.0 and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request Component: vtctldclient NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jun 11, 2026
@arthurschreiber arthurschreiber enabled auto-merge (squash) June 11, 2026 11:25
The hook passes every directory with staged .go files to a single
golangci-lint run in the main module. Files in nested Go modules
(e.g. test/antithesis) make that run fail with a typechecking error,
aborting the commit even when there are no lint findings.

Filter the changed packages down to those whose nearest go.mod is the
repo root's, and print a notice for skipped directories. CI doesn't
lint nested modules either, so this matches existing coverage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
@arthurschreiber arthurschreiber merged commit dc9b73d into main Jun 11, 2026
109 checks passed
@arthurschreiber arthurschreiber deleted the arthur/per-tool-go-modules branch June 11, 2026 12:32
arthurschreiber added a commit that referenced this pull request Jun 11, 2026
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
arthurschreiber added a commit that referenced this pull request Jun 11, 2026
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
arthurschreiber added a commit that referenced this pull request Jun 11, 2026
Add tools/check_license_headers.sh, which checks that every tracked Go
file carries a license header, and run it from the static checks
workflow. Generated files (marked with "DO NOT EDIT") are skipped.

The check uses github.com/google/addlicense, pinned as a per-tool Go
module under tools/addlicense following the layout from #20293.
addlicense accepts any existing copyright notice, so files derived
from third-party code keep their original attribution.

Backfill headers for the 90 Go files that were missing one:
- the standard Vitess header for hand-written files
- the dual Vitess/Yiling-J header for the go/cache/theine files,
  matching their package siblings
- the upstream "Code generated" marker for two collation data tables
  copied from golang.org/x/text, rather than inventing a copyright

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
arthurschreiber added a commit that referenced this pull request Jun 11, 2026
#20298)

Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Arthur Schreiber <arthur@planetscale.com>
arthurschreiber added a commit that referenced this pull request Jun 11, 2026
#20296)

Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Arthur Schreiber <arthur@planetscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport to: release-23.0 Needs to be backport to release-23.0 Backport to: release-24.0 Needs to be backport to release-24.0 Component: Build/CI Type: Dependencies Dependency updates Type: Internal Cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants