Skip to content

Commit e4adfbc

Browse files
authored
Update Go (#318)
* Update minimum Go version to 1.24.0. * Update Go build to 1.25. * Sync Prometheus files. * Update golangci-lint. * Fixup linting issues. Signed-off-by: SuperQ <[email protected]>
1 parent ef5c03d commit e4adfbc

File tree

7 files changed

+50
-30
lines changed

7 files changed

+50
-30
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ executors:
77
# also be updated.
88
golang:
99
docker:
10-
- image: cimg/go:1.23
10+
- image: cimg/go:1.25
1111
jobs:
1212
test:
1313
executor: golang

.github/workflows/golangci-lint.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ jobs:
2525
steps:
2626
- name: Checkout repository
2727
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
persist-credentials: false
2830
- name: Install Go
29-
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
31+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
3032
with:
31-
go-version: 1.24.x
33+
go-version: 1.25.x
3234
- name: Install snmp_exporter/generator dependencies
3335
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
3436
if: github.repository == 'prometheus/snmp_exporter'
37+
- name: Get golangci-lint version
38+
id: golangci-lint-version
39+
run: echo "version=$(make print-golangci-lint-version)" >> $GITHUB_OUTPUT
3540
- name: Lint
36-
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
41+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
3742
with:
3843
args: --verbose
39-
version: v2.0.2
44+
version: ${{ steps.golangci-lint-version.outputs.version }}

.golangci.yml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1+
version: "2"
12
linters:
23
enable:
34
- misspell
45
- revive
56
- sloglint
67
disable:
78
- unused
8-
9-
issues:
10-
exclude-rules:
11-
- path: _test.go
12-
linters:
13-
- errcheck
14-
15-
linters-settings:
16-
errcheck:
17-
exclude-functions:
18-
# Used in HTTP handlers, any error is handled by the server itself.
19-
- (net/http.ResponseWriter).Write
20-
revive:
9+
settings:
10+
errcheck:
11+
exclude-functions:
12+
- (net/http.ResponseWriter).Write
13+
revive:
14+
rules:
15+
- name: unused-parameter
16+
severity: warning
17+
disabled: true
18+
exclusions:
19+
generated: lax
20+
presets:
21+
- comments
22+
- common-false-positives
23+
- legacy
24+
- std-error-handling
2125
rules:
22-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
23-
- name: unused-parameter
24-
severity: warning
25-
disabled: true
26+
- linters:
27+
- errcheck
28+
path: _test.go
29+
formatters:
30+
exclusions:
31+
generated: lax

.promu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go:
22
# This must match .circle/config.yml.
3-
version: 1.23
3+
version: 1.25
44
repository:
55
path: github.com/prometheus-community/smartctl_exporter
66
build:

Makefile.common

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
6161
SKIP_GOLANGCI_LINT :=
6262
GOLANGCI_LINT :=
6363
GOLANGCI_LINT_OPTS ?=
64-
GOLANGCI_LINT_VERSION ?= v2.0.2
64+
GOLANGCI_LINT_VERSION ?= v2.4.0
65+
GOLANGCI_FMT_OPTS ?=
6566
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
6667
# windows isn't included here because of the path separator being different.
6768
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
@@ -138,7 +139,7 @@ common-deps:
138139
update-go-deps:
139140
@echo ">> updating Go dependencies"
140141
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
141-
$(GO) get -d $$m; \
142+
$(GO) get $$m; \
142143
done
143144
$(GO) mod tidy
144145

@@ -156,9 +157,13 @@ $(GOTEST_DIR):
156157
@mkdir -p $@
157158

158159
.PHONY: common-format
159-
common-format:
160+
common-format: $(GOLANGCI_LINT)
160161
@echo ">> formatting code"
161162
$(GO) fmt $(pkgs)
163+
ifdef GOLANGCI_LINT
164+
@echo ">> formatting code with golangci-lint"
165+
$(GOLANGCI_LINT) fmt $(GOLANGCI_FMT_OPTS)
166+
endif
162167

163168
.PHONY: common-vet
164169
common-vet:
@@ -248,8 +253,8 @@ $(PROMU):
248253
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
249254
rm -r $(PROMU_TMP)
250255

251-
.PHONY: proto
252-
proto:
256+
.PHONY: common-proto
257+
common-proto:
253258
@echo ">> generating code from proto files"
254259
@./scripts/genproto.sh
255260

@@ -261,6 +266,10 @@ $(GOLANGCI_LINT):
261266
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
262267
endif
263268

269+
.PHONY: common-print-golangci-lint-version
270+
common-print-golangci-lint-version:
271+
@echo $(GOLANGCI_LINT_VERSION)
272+
264273
.PHONY: precheck
265274
precheck::
266275

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/prometheus-community/smartctl_exporter
22

3-
go 1.22
3+
go 1.24.0
44

55
require (
66
github.com/alecthomas/kingpin/v2 v2.4.0

readjson.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func readSMARTctl(logger *slog.Logger, device Device, wg *sync.WaitGroup) {
8484

8585
func readSMARTctlDevices(logger *slog.Logger) gjson.Result {
8686
logger.Debug("Scanning for devices")
87-
var scanArgs []string = []string{"--json", "--scan"}
87+
scanArgs := []string{"--json", "--scan"}
8888
for _, d := range *smartctlScanDeviceTypes {
8989
scanArgs = append(scanArgs, "--device", d)
9090
}

0 commit comments

Comments
 (0)