11# Copyright 2020 Google LLC
2- # Modifications Copyright (C) 2025-2026 OpenInfra Foundation Europe.
2+ # Modifications Copyright (C) 2025-2026 The kpt Authors
33#
44# Licensed under the Apache License, Version 2.0 (the "License");
55# you may not use this file except in compliance with the License.
1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515SHELL =/bin/bash
16- GOPATH := $(shell go env GOPATH)
1716TAG ?= latest
1817DEFAULT_CR ?= ghcr.io/kptdev/krm-functions-catalog
1918GOBIN := $(shell go env GOPATH) /bin
2019
20+ GOLANGCI_LINT_VERSION ?= 2.12.2
21+
2122# Edit this list to contain all go functions
2223FUNCTIONS := \
2324 annotate-apply-time-mutations \
@@ -93,14 +94,14 @@ $(FUNCTION_GENERATE_DOCS): | install-mdtogo
9394build : generate $(FUNCTION_BUILDS ) # # Build all function images. 'TAG' env is used to specify tag. 'dev' will be used if not set.
9495
9596.PHONY : $(FUNCTION_BUILDS )
96- $(FUNCTION_BUILDS ) : | generate install-golangci-lint
97+ $(FUNCTION_BUILDS ) : | generate
9798 $(MAKE ) CURRENT_FUNCTION=$(subst -BUILD,,$@ ) TAG=$(TAG ) DEFAULT_CR=$(DEFAULT_CR ) func-build
9899
99100.PHONY : format
100101format : generate $(FUNCTION_FORMATS )
101102
102103.PHONY : $(FUNCTION_FORMATS )
103- $(FUNCTION_FORMATS ) : | generate install-golangci-lint
104+ $(FUNCTION_FORMATS ) : | generate
104105 $(MAKE ) CURRENT_FUNCTION=$(subst -FORMAT,,$@ ) TAG=$(TAG ) DEFAULT_CR=$(DEFAULT_CR ) func-format
105106
106107.PHONY : push
@@ -119,19 +120,19 @@ install-mdtogo:
119120func-verify : func-format func-test
120121func-format : docs-generate func-fix func-vet func-fmt func-lint
121122
122- .PHONY : install-golangci-lint
123- install-golangci-lint :
124- (which $( GOPATH) /bin/golangci-lint || \
125- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(GOPATH ) /bin latest)
126-
127123func-fix :
128124 cd $(CURRENT_FUNCTION ) && go fix -omitzero=false ./...
129125
130126func-fmt :
131127 cd $(CURRENT_FUNCTION ) && go fmt ./...
132128
133- func-lint : install-golangci-lint
134- cd $(CURRENT_FUNCTION ) && time $(GOPATH ) /bin/golangci-lint run --allow-parallel-runners --fix --timeout=10m ./...
129+ func-lint :
130+ @if ! command -v golangci-lint > /dev/null 2>&1 || \
131+ ! golangci-lint version --short 2> /dev/null | grep -qx " $( GOLANGCI_LINT_VERSION) " ; then \
132+ echo " Installing golangci-lint v$( GOLANGCI_LINT_VERSION) ..." ; \
133+ go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION ) ; \
134+ fi
135+ cd $(CURRENT_FUNCTION ) && time golangci-lint run --allow-parallel-runners --fix --timeout=10m ./...
135136
136137func-test :
137138 cd $(CURRENT_FUNCTION ) && go test -cover ./...
0 commit comments