Warn when local golangci-lint version differs from CI (#1052)#1683
Open
pujitha24 wants to merge 1 commit into
Open
Warn when local golangci-lint version differs from CI (#1052)#1683pujitha24 wants to merge 1 commit into
pujitha24 wants to merge 1 commit into
Conversation
Motivation:
`make lint` runs the locally installed `golangci-lint` binary, but
nothing checks that its version matches the one pinned for the
`golangci-lint-action` step in .github/workflows/dapr_cli.yaml
(GOLANG_CI_LINT_VER). A version drift between a contributor's local
lint and CI's lint can produce different results locally vs. in the
pipeline, which is confusing to debug. This mirrors the approach
already adopted in dapr/components-contrib (PR #1861), which the
issue explicitly links as a reference solution.
Approach:
Add two new Makefile targets, wired as prerequisites of `lint`:
- `verify-linter-installed`: fails with exit 1 and an install
command if `golangci-lint` is not found on PATH.
- `verify-linter-version`: compares the installed version (parsed
from `golangci-lint --version`) against GOLANG_CI_LINT_VER
(parsed from .github/workflows/dapr_cli.yaml) and prints a
warning with an upgrade command if they differ. This check is
non-fatal (it does not fail the build) since a version mismatch
doesn't prevent linting from running, it just risks different
results than CI.
This is a Makefile-only, developer-tooling change; it does not
touch Go source and does not affect CI itself, since CI's lint
step invokes golangci-lint-action directly rather than `make lint`.
Validation:
- `go build ./...` and `go test ./pkg/...` both pass (no Go source
was changed).
- Manually exercised all three code paths of the new targets:
- golangci-lint not on PATH: `make verify-linter-installed` exits
1 with a helpful install command.
- golangci-lint v2.10.1 installed (matches GOLANG_CI_LINT_VER):
`make verify-linter-installed verify-linter-version` exits 0
silently.
- golangci-lint v2.5.0 installed (mismatch): prints a Yours/Theirs
warning with an upgrade command and exits 0 (non-fatal).
Fixes dapr#1052
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves developer experience around make lint by adding checks that (1) ensure golangci-lint is installed locally and (2) warn when the locally installed golangci-lint version differs from the version pinned in the CI workflow (.github/workflows/dapr_cli.yaml), reducing confusion caused by local-vs-CI lint drift.
Changes:
- Add
verify-linter-installedMakefile target to fail fast with installation guidance whengolangci-lintis missing. - Add
verify-linter-versionMakefile target to warn (non-fatally) when localgolangci-lintdiffers from CI-pinned version. - Wire both targets as prerequisites of
lint.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+76
to
+83
| # Version of golangci-lint used by the GitHub Actions pipeline (.github/workflows/dapr_cli.yaml). | ||
| GH_LINT_VERSION := $(shell grep 'GOLANG_CI_LINT_VER:' .github/workflows/dapr_cli.yaml | xargs | cut -d' ' -f2) | ||
| LINTER_BINARY := $(shell $(FINDBIN) $(GOLANGCI_LINT) 2>/dev/null) | ||
| ifeq (,$(LINTER_BINARY)) | ||
| INSTALLED_LINT_VERSION := v0.0.0 | ||
| else | ||
| INSTALLED_LINT_VERSION := v$(shell $(GOLANGCI_LINT) --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | ||
| endif |
Comment on lines
+143
to
+150
| @if [ "$(GH_LINT_VERSION)" != "$(INSTALLED_LINT_VERSION)" ]; then \ | ||
| echo "[!] Your locally installed version of golangci-lint is different from the pipeline"; \ | ||
| echo "[!] This will likely cause linting issues for you locally"; \ | ||
| echo "[!] Yours: $(INSTALLED_LINT_VERSION)"; \ | ||
| echo "[!] Theirs: $(GH_LINT_VERSION)"; \ | ||
| echo "[!] Upgrade: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GH_LINT_VERSION)"; \ | ||
| sleep 3; \ | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
make lintruns the locally installedgolangci-lintbinary, butnothing checks that its version matches the one pinned for the
golangci-lint-actionstep in .github/workflows/dapr_cli.yaml(GOLANG_CI_LINT_VER). A version drift between a contributor's local
lint and CI's lint can produce different results locally vs. in the
pipeline, which is confusing to debug. This mirrors the approach
already adopted in dapr/components-contrib (PR #1861), which the
issue explicitly links as a reference solution.
Approach:
Add two new Makefile targets, wired as prerequisites of
lint:verify-linter-installed: fails with exit 1 and an installcommand if
golangci-lintis not found on PATH.verify-linter-version: compares the installed version (parsedfrom
golangci-lint --version) against GOLANG_CI_LINT_VER(parsed from .github/workflows/dapr_cli.yaml) and prints a
warning with an upgrade command if they differ. This check is
non-fatal (it does not fail the build) since a version mismatch
doesn't prevent linting from running, it just risks different
results than CI.
This is a Makefile-only, developer-tooling change; it does not
touch Go source and does not affect CI itself, since CI's lint
step invokes golangci-lint-action directly rather than
make lint.Validation:
go build ./...andgo test ./pkg/...both pass (no Go sourcewas changed).
make verify-linter-installedexits1 with a helpful install command.
make verify-linter-installed verify-linter-versionexits 0silently.
warning with an upgrade command and exits 0 (non-fatal).
Fixes #1052
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com