Skip to content

Commit 652814e

Browse files
authored
Unify golangci-lint setup: pin version, use go run (#1260)
Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
1 parent 2da0efa commit 652814e

3 files changed

Lines changed: 48 additions & 13 deletions

File tree

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2022 Google LLC
2-
# Modifications Copyright (C) 2025 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.
@@ -26,7 +26,7 @@ jobs:
2626
name: function-release
2727
steps:
2828
- name: Checkout
29-
uses: actions/checkout@v5
29+
uses: actions/checkout@v6
3030
- name: Create Short Tag for Function Release
3131
# Create secondary short tag, e.g. functions/go/apply-setters/v1.1.1 -> apply-setters/v1.1.1
3232
run: |

functions/go/.golangci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2026 The kpt Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
version: "2"
16+
linters:
17+
default: none
18+
enable:
19+
- errcheck
20+
- govet
21+
- ineffassign
22+
- staticcheck
23+
- unused
24+
exclusions:
25+
generated: lax
26+
paths:
27+
- "generated/*"
28+
rules:
29+
- path: _test\.go
30+
linters:
31+
- errcheck
32+
formatters:
33+
enable:
34+
- gofmt

functions/go/Makefile

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -13,11 +13,12 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
SHELL=/bin/bash
16-
GOPATH := $(shell go env GOPATH)
1716
TAG ?= latest
1817
DEFAULT_CR ?= ghcr.io/kptdev/krm-functions-catalog
1918
GOBIN := $(shell go env GOPATH)/bin
2019

20+
GOLANGCI_LINT_VERSION ?= 2.12.2
21+
2122
# Edit this list to contain all go functions
2223
FUNCTIONS := \
2324
annotate-apply-time-mutations \
@@ -93,14 +94,14 @@ $(FUNCTION_GENERATE_DOCS): | install-mdtogo
9394
build: 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
100101
format: 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:
119120
func-verify: func-format func-test
120121
func-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-
127123
func-fix:
128124
cd $(CURRENT_FUNCTION) && go fix -omitzero=false ./...
129125

130126
func-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

136137
func-test:
137138
cd $(CURRENT_FUNCTION) && go test -cover ./...

0 commit comments

Comments
 (0)