Skip to content

Commit

Permalink
Run golangci-lint from a docker container.
Browse files Browse the repository at this point in the history
There's no reason why telepresence should download and compile this
tool from source. In fact, the authors recommend against it with a
motivation that can be found here:

https://golangci-lint.run/welcome/install/
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Dec 23, 2024
1 parent 990cf76 commit 28cf6f1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1,161 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ jobs:
- name: install dependencies
uses: ./.github/actions/install-dependencies
- name: Lint
run: make lint
if: ${{ runner.os != 'Windows' }}
uses: golangci/golangci-lint-action@v6
with:
args: --timeout 8m ./...
- name: Lint (limited on windows)
if: ${{ runner.os == 'Windows' }}
uses: golangci/golangci-lint-action@v6
with:
args: --timeout 8m ./cmd/telepresence/... ./integration_test/... ./pkg/...
- name: Build
run: make build
- name: Run tests
Expand Down
17 changes: 13 additions & 4 deletions build-aux/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ promote-nightly: ## (Release) Update nightly.txt in S3

.PHONY: lint-deps
lint-deps: build-deps ## (QA) Everything necessary to lint
lint-deps: $(tools/golangci-lint)
lint-deps: $(tools/protolint)
lint-deps: $(tools/gosimports)
ifneq ($(GOHOSTOS), windows)
Expand All @@ -376,13 +375,17 @@ shellscripts += ./packaging/windows-package.sh

lint: lint-rpc lint-go

GOLANGCI_VERSION:=v1.62.2

lint-go: lint-deps ## (QA) Run the golangci-lint
$(eval badimports = $(shell find cmd integration_test pkg -name '*.go' | grep -v '/mocks/' | xargs $(tools/gosimports) --local github.com/datawire/,github.com/telepresenceio/ -l))
$(if $(strip $(badimports)), echo "The following files have bad import ordering (use make format to fix): " $(badimports) && false)
ifeq ($(GOHOSTOS),windows)
CGO_ENABLED=$(CGO_ENABLED) $(tools/golangci-lint) run --timeout 8m ./cmd/telepresence/... ./integration_test/... ./pkg/...
docker run -e GOOS=$(GOOS) --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/$(GOLANGCI_VERSION):/root/.cache -w /app golangci/golangci-lint:$(GOLANGCI_VERSION) golangci-lint \
run --timeout 8m ./cmd/telepresence/... ./integration_test/... ./pkg/...
else
CGO_ENABLED=$(CGO_ENABLED) $(tools/golangci-lint) run --timeout 8m ./...
docker run -e GOOS=$(GOOS) --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/$(GOLANGCI_VERSION):/root/.cache -w /app golangci/golangci-lint:$(GOLANGCI_VERSION) golangci-lint \
run --timeout 8m ./...
endif

lint-rpc: lint-deps ## (QA) Run rpc linter
Expand All @@ -394,7 +397,13 @@ endif
.PHONY: format
format: lint-deps ## (QA) Automatically fix linter complaints
find cmd integration_test pkg -name '*.go' | grep -v '/mocks/' | xargs $(tools/gosimports) --local github.com/datawire/,github.com/telepresenceio/ -w
$(tools/golangci-lint) run --fix --timeout 2m ./... || true
ifeq ($(GOHOSTOS),windows)
docker run -e GOOS=$(GOOS) --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/$(GOLANGCI_VERSION):/root/.cache -w /app golangci/golangci-lint:$(GOLANGCI_VERSION) golangci-lint \
run --timeout 8m --fix ./cmd/telepresence/... ./integration_test/... ./pkg/...
else
docker run -e GOOS=$(GOOS) --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/$(GOLANGCI_VERSION):/root/.cache -w /app golangci/golangci-lint:$(GOLANGCI_VERSION) golangci-lint \
run --timeout 8m --fix ./...
endif
$(tools/protolint) lint --fix rpc || true

.PHONY: check-all
Expand Down
1 change: 0 additions & 1 deletion build-aux/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ $(TOOLSDIR)/$(notdir $(HELM_TGZ)):
tools/protoc-gen-go = $(TOOLSBINDIR)/protoc-gen-go$(EXE)
tools/protoc-gen-go-grpc = $(TOOLSBINDIR)/protoc-gen-go-grpc$(EXE)
tools/ko = $(TOOLSBINDIR)/ko$(EXE)
tools/golangci-lint = $(TOOLSBINDIR)/golangci-lint$(EXE)
tools/gosimports = $(TOOLSBINDIR)/gosimports$(EXE)
tools/go-mkopensource = $(TOOLSBINDIR)/go-mkopensource$(EXE)
$(TOOLSBINDIR)/%$(EXE): $(TOOLSSRCDIR)/%/go.mod $(TOOLSSRCDIR)/%/pin.go
Expand Down
192 changes: 0 additions & 192 deletions tools/src/golangci-lint/go.mod

This file was deleted.

Loading

0 comments on commit 28cf6f1

Please sign in to comment.