Add make lint-code-fast (#11786)

When using `git worktree` for agentic workflows during development, the
golangci-lint cache is always cold.

That means the first invocation scans the entire codebase (consuming all
CPU cores) unnecessarily, since almost all lints can be found by just
scanning the changed packages. The exceptions are type-based checks, but
they are rare.

This PR speeds up the agentic development cycle greatly for local
development; and anything that slips through is still caught in CI where
the full codebase is checked.

Example benchmark for cold cache with 1 changed file with 1 finding:
- `lint-code-fast`: 8s
- `lint-code`: 14min

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dan Davison <dan.davison@temporal.io>
This commit is contained in:
Stephan Behnke
2026-08-26 10:00:40 -07:00
committed by GitHub
parent 30e0884ac0
commit 109a38e8ca
2 changed files with 32 additions and 4 deletions

View File

@@ -47,7 +47,8 @@ Before starting the implementation of any request, you MUST REVIEW the following
- `/service/worker`: worker service implementation
## Important Commands:
- Linting: `make lint-code`
- Fast Go linting (changed packages): `make lint-code-fast`
- Full Go linting (all packages): `make lint-code`
- Formatting imports: `make fmt-imports`
- Code generation: `make proto`
- Update API proto: `make update-go-api`
@@ -87,7 +88,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
3. **Implement:** Use the available tools to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates').
4. **Regenerate:** If necessary, regenerate code based on your changes. If you alter anything annotated with `//go:generate` or in a `.proto` file you will need to do this.
5. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'Makefile'), or existing test execution patterns. NEVER assume standard test commands.
6. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (`make lint-code`)
6. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (`make lint-code-fast` for development)
## Planning
When planning (under 'Software Engineering Tasks'):

View File

@@ -173,6 +173,7 @@ $(LOCALBIN):
@mkdir -p $(LOCALBIN)
.PHONY: golangci-lint
LINT_CODE_TARGETS ?= ./...
GOLANGCI_LINT_BASE_REV ?= $(MAIN_BRANCH)
GOLANGCI_LINT_FIX ?= true
GOLANGCI_LINT_VERSION := v2.13.0
@@ -403,10 +404,36 @@ lint-actions: $(ACTIONLINT)
@printf $(COLOR) "Linting GitHub actions..."
@$(ACTIONLINT)
.PHONY: lint-code lint-code-fast
# --new-from-rev filters reported issues _after_ analysis; this target also reduces package inputs _before_ analysis.
lint-code-fast:
@if ! git rev-parse --verify --quiet "$(GOLANGCI_LINT_BASE_REV)^{commit}" >/dev/null; then \
printf $(RED) "GOLANGCI_LINT_BASE_REV=$(GOLANGCI_LINT_BASE_REV) is not a known commit; fetch it or override GOLANGCI_LINT_BASE_REV"; \
exit 1; \
fi
@base=$$(git merge-base HEAD "$(GOLANGCI_LINT_BASE_REV)"); \
targets=$$({ \
git diff --no-renames --name-only "$$base" -- '*.go'; \
git ls-files --others --exclude-standard -- '*.go'; \
} | sed 's|^|./|; s|/[^/]*$$||' | sort -u \
| while read -r dir; do [ -d "$$dir" ] && printf '%s ' "$$dir"; done); \
if [ -z "$$targets" ]; then \
printf $(COLOR) "No changed Go packages to lint."; \
else \
$(MAKE) GOLANGCI_LINT_BASE_REV="$$base" LINT_CODE_TARGETS="$$targets" lint-code; \
fi
lint-code: $(GOLANGCI_LINT) $(ERRORTYPE)
@printf $(COLOR) "Linting code..."
@$(GOLANGCI_LINT) run --verbose --build-tags $(ALL_TEST_TAGS) --timeout 10m --fix=$(GOLANGCI_LINT_FIX) --new-from-rev=$(GOLANGCI_LINT_BASE_REV) --config=.github/.golangci.yml
@go vet -tags $(ALL_TEST_TAGS) -vettool="$(ERRORTYPE)" -style-check=false ./...
@$(GOLANGCI_LINT) run \
--verbose \
--build-tags $(ALL_TEST_TAGS) \
--timeout 10m \
--fix=$(GOLANGCI_LINT_FIX) \
--new-from-rev=$(GOLANGCI_LINT_BASE_REV) \
--config=.github/.golangci.yml \
$(LINT_CODE_TARGETS)
@go vet -tags $(ALL_TEST_TAGS) -vettool="$(ERRORTYPE)" -style-check=false $(LINT_CODE_TARGETS)
lint-yaml: $(YAMLFMT)
@printf $(COLOR) "Checking YAML formatting..."