Skip to content

Commit 3a6ceb2

Browse files
authored
Merge pull request #4041 from apostasie/ci-tigron-break-1
[CI] Tigron breakout: golangci v2 and cleanups
2 parents 0190e81 + a92e93c commit 3a6ceb2

21 files changed

+280
-199
lines changed

mod/tigron/.golangci.yml

+52-43
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
1-
---
2-
output:
3-
sort-results: true
4-
5-
issues:
6-
max-issues-per-linter: 0
7-
max-same-issues: 0
1+
version: "2"
82

93
run:
10-
concurrency: 0
11-
timeout: 5m
124
issues-exit-code: 2
13-
tests: true
145
modules-download-mode: readonly
156
allow-parallel-runners: true
167
allow-serial-runners: true
178

9+
issues:
10+
max-issues-per-linter: 0
11+
max-same-issues: 0
12+
1813
linters:
19-
disable-all: false
20-
enable-all: true
14+
default: all
2115
disable:
22-
# Opting-out
23-
- nonamedreturns # named returns are occasionally useful
24-
- exhaustruct # does not serve much of a purpose
25-
- funlen # not interested
26-
- cyclop # not interested much
27-
- godox # having these are useful
28-
# Duplicating
29-
- gci # we use go-imports instead
30-
# Deprecated
31-
- tenv
32-
# TODO: Temporarily out until we wrap up all of them
33-
# - wrapcheck
16+
- cyclop
17+
- exhaustruct
18+
- funlen
19+
- godox
20+
- nonamedreturns
21+
settings:
22+
depguard:
23+
rules:
24+
main:
25+
files:
26+
- $all
27+
allow:
3428

35-
linters-settings:
36-
staticcheck:
37-
checks:
38-
- "all"
29+
- $gostd
30+
- github.com/containerd/nerdctl/mod/tigron
31+
- github.com/creack/pty
32+
- golang.org/x/sync
33+
- golang.org/x/term
34+
- gotest.tools/v3
35+
staticcheck:
36+
checks:
37+
- all
38+
exclusions:
39+
generated: disable
3940

40-
depguard:
41-
rules:
42-
main:
43-
files:
44-
- "$all"
45-
allow:
46-
- $gostd
47-
- "github.com/containerd/nerdctl/mod/tigron"
48-
# WATCHOUT! https://github.com/OpenPeeDeeP/depguard/issues/108
49-
# Currently, depguard will fail detecting any dependency starting with a standard package name as third-party.
50-
# Thus, the following three are allowed provisionally, though currently not "necessary".
51-
- "golang.org/x/sync"
52-
- "golang.org/x/term"
53-
- "gotest.tools"
54-
- "github.com/creack/pty"
41+
formatters:
42+
settings:
43+
gci:
44+
sections:
45+
- standard
46+
- default
47+
- prefix(github.com/containerd)
48+
- localmodule
49+
no-inline-comments: true
50+
no-prefix-comments: true
51+
custom-order: true
52+
gofumpt:
53+
extra-rules: true
54+
golines:
55+
max-len: 100
56+
tab-len: 4
57+
shorten-comments: true
58+
enable:
59+
- gci
60+
- gofumpt
61+
- golines
62+
exclusions:
63+
generated: disable

mod/tigron/Makefile

+24-33
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ endef
5757
##########################
5858
# High-level tasks definitions
5959
##########################
60-
lint: lint-go-all lint-imports lint-yaml lint-shell lint-commits lint-headers lint-mod lint-licenses-all
60+
lint: lint-go-all lint-yaml lint-shell lint-commits lint-headers lint-mod lint-licenses-all
6161
test: test-unit test-unit-race test-unit-bench
6262
unit: test-unit test-unit-race test-unit-bench
63-
fix: fix-mod fix-imports fix-go-all
63+
fix: fix-mod fix-go-all
6464

6565
##########################
6666
# Linting tasks
6767
##########################
6868
lint-go:
69-
$(call title, $@)
69+
$(call title, $@: $(GOOS))
7070
@cd $(MAKEFILE_DIR) \
7171
&& golangci-lint run $(VERBOSE_FLAG_LONG) ./...
7272
$(call footer, $@)
@@ -80,12 +80,6 @@ lint-go-all:
8080
&& GOOS=windows make lint-go
8181
$(call footer, $@)
8282

83-
lint-imports:
84-
$(call title, $@)
85-
@cd $(MAKEFILE_DIR) \
86-
&& goimports-reviser -recursive -list-diff -set-exit-status -output stdout -company-prefixes "$(ORG_PREFIXES)" ./...
87-
$(call footer, $@)
88-
8983
lint-yaml:
9084
$(call title, $@)
9185
@cd $(MAKEFILE_DIR) \
@@ -115,10 +109,15 @@ lint-mod:
115109
&& go mod tidy --diff
116110
$(call footer, $@)
117111

112+
# FIXME: go-licenses cannot find LICENSE from root of repo when submodule is imported:
113+
# https://github.com/google/go-licenses/issues/186
114+
# This is impacting gotest.tools
118115
lint-licenses:
119-
$(call title, $@)
116+
$(call title, $@: $(GOOS))
120117
@cd $(MAKEFILE_DIR) \
121-
&& ./hack/make-lint-licenses.sh
118+
&& go-licenses check --include_tests --allowed_licenses=Apache-2.0,BSD-2-Clause,BSD-3-Clause,MIT,MPL-2.0 \
119+
--ignore gotest.tools \
120+
./...
122121
$(call footer, $@)
123122

124123
lint-licenses-all:
@@ -134,7 +133,7 @@ lint-licenses-all:
134133
# Automated fixing tasks
135134
##########################
136135
fix-go:
137-
$(call title, $@)
136+
$(call title, $@: $(GOOS))
138137
@cd $(MAKEFILE_DIR) \
139138
&& golangci-lint run --fix
140139
$(call footer, $@)
@@ -148,12 +147,6 @@ fix-go-all:
148147
&& GOOS=windows make fix-go
149148
$(call footer, $@)
150149

151-
fix-imports:
152-
$(call title, $@)
153-
@cd $(MAKEFILE_DIR) \
154-
&& goimports-reviser -company-prefixes $(ORG_PREFIXES) ./...
155-
$(call footer, $@)
156-
157150
fix-mod:
158151
$(call title, $@)
159152
@cd $(MAKEFILE_DIR) \
@@ -171,18 +164,16 @@ up:
171164
##########################
172165
install-dev-tools:
173166
$(call title, $@)
174-
# golangci: v1.64.5
175-
# git-validation: main from 2023/11
176-
# ltag: v0.2.5
177-
# go-licenses: v2.0.0-alpha.1
178-
# goimports-reviser: v3.9.0
167+
# golangci: v2.0.2 (2024-03-26)
168+
# git-validation: main (2025-02-25)
169+
# ltag: main (2025-03-04)
170+
# go-licenses: v2.0.0-alpha.1 (2024-06-27)
179171
@cd $(MAKEFILE_DIR) \
180-
&& go install github.com/golangci/golangci-lint/cmd/golangci-lint@0a603e49e5e9870f5f9f2035bcbe42cd9620a9d5 \
181-
&& go install github.com/vbatts/git-validation@679e5cad8c50f1605ab3d8a0a947aaf72fb24c07 \
182-
&& go install github.com/kunalkushwaha/ltag@b0cfa33e4cc9383095dc584d3990b62c95096de0 \
183-
&& go install github.com/google/go-licenses/v2@d01822334fba5896920a060f762ea7ecdbd086e8 \
184-
&& go install github.com/incu6us/goimports-reviser/v3@698f92d226d50a01731ca8551993ebc1bb7fc788
185-
@echo "Remember to add GOROOT/bin to your path"
172+
&& go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@2b224c2cf4c9f261c22a16af7f8ca6408467f338 \
173+
&& go install github.com/vbatts/git-validation@7b60e35b055dd2eab5844202ffffad51d9c93922 \
174+
&& go install github.com/containerd/ltag@66e6a514664ee2d11a470735519fa22b1a9eaabd \
175+
&& go install github.com/google/go-licenses/v2@d01822334fba5896920a060f762ea7ecdbd086e8
176+
@echo "Remember to add \$$HOME/go/bin to your path"
186177
$(call footer, $@)
187178

188179
##########################
@@ -200,7 +191,7 @@ test-unit-bench:
200191

201192
test-unit-race:
202193
$(call title, $@)
203-
@go test $(VERBOSE_FLAG) $(MAKEFILE_DIR)/... -race
194+
@CGO_ENABLED=1 go test $(VERBOSE_FLAG) $(MAKEFILE_DIR)/... -race
204195
$(call footer, $@)
205196

206197
.PHONY: \
@@ -210,6 +201,6 @@ test-unit-race:
210201
up \
211202
unit \
212203
install-dev-tools \
213-
lint-commits lint-go lint-go-all lint-headers lint-imports lint-licenses lint-licenses-all lint-mod lint-shell lint-yaml \
214-
fix-go fix-go-all fix-imports fix-mod \
215-
test-unit test-unit-race test-unit-bench
204+
lint-commits lint-go lint-go-all lint-headers lint-licenses lint-licenses-all lint-mod lint-shell lint-yaml \
205+
fix-go fix-go-all fix-mod \
206+
test-unit test-unit-race test-unit-bench

mod/tigron/expect/comparators.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
// All can be used as a parameter for expected.Output to group a set of comparators.
3131
func All(comparators ...test.Comparator) test.Comparator {
3232
//nolint:thelper
33-
return func(stdout string, info string, t *testing.T) {
33+
return func(stdout, info string, t *testing.T) {
3434
t.Helper()
3535

3636
for _, comparator := range comparators {
@@ -43,17 +43,18 @@ func All(comparators ...test.Comparator) test.Comparator {
4343
// is found contained in the output.
4444
func Contains(compare string) test.Comparator {
4545
//nolint:thelper
46-
return func(stdout string, info string, t *testing.T) {
46+
return func(stdout, info string, t *testing.T) {
4747
t.Helper()
4848
assert.Check(t, strings.Contains(stdout, compare),
4949
fmt.Sprintf("Output does not contain: %q", compare)+info)
5050
}
5151
}
5252

53-
// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output.
53+
// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in
54+
// the output.
5455
func DoesNotContain(compare string) test.Comparator {
5556
//nolint:thelper
56-
return func(stdout string, info string, t *testing.T) {
57+
return func(stdout, info string, t *testing.T) {
5758
t.Helper()
5859
assert.Check(t, !strings.Contains(stdout, compare),
5960
fmt.Sprintf("Output does contain: %q", compare)+info)
@@ -63,7 +64,7 @@ func DoesNotContain(compare string) test.Comparator {
6364
// Equals is to be used for expected.Output to ensure it is exactly the output.
6465
func Equals(compare string) test.Comparator {
6566
//nolint:thelper
66-
return func(stdout string, info string, t *testing.T) {
67+
return func(stdout, info string, t *testing.T) {
6768
t.Helper()
6869
assert.Equal(t, compare, stdout, info)
6970
}
@@ -73,7 +74,7 @@ func Equals(compare string) test.Comparator {
7374
// Provisional - expected use, but have not seen it so far.
7475
func Match(reg *regexp.Regexp) test.Comparator {
7576
//nolint:thelper
76-
return func(stdout string, info string, t *testing.T) {
77+
return func(stdout, info string, t *testing.T) {
7778
t.Helper()
7879
assert.Check(t, reg.MatchString(stdout), "Output does not match: "+reg.String(), info)
7980
}

mod/tigron/expect/consts.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
package expect
1818

1919
const (
20-
ExitCodeSuccess = 0
20+
// ExitCodeSuccess will ensure that the command effectively ran returned with exit code zero.
21+
ExitCodeSuccess = 0
22+
// ExitCodeGenericFail will verify that the command ran and exited with a non-zero error code.
23+
// This does NOT include timeouts, cancellation, or signals.
2124
ExitCodeGenericFail = -1
22-
ExitCodeNoCheck = -2
23-
ExitCodeTimeout = -3
25+
// ExitCodeNoCheck does not enforce any check at all on the function.
26+
ExitCodeNoCheck = -2
27+
// ExitCodeTimeout verifies that the command was cancelled on timeout.
28+
ExitCodeTimeout = -3
2429
)

mod/tigron/expect/doc.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package expect provides a set of simple concrete test.Comparator implementations to use by tests
18+
// on stdout, along with exit code expectations.
19+
package expect

mod/tigron/hack/make-lint-licenses.sh

-30
This file was deleted.

mod/tigron/require/doc.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package require provides a set of concrete test.Requirements to express the need for a specific
18+
// architecture, OS, or binary, along with Not() and All() which allow Requirements composition.
19+
package require

0 commit comments

Comments
 (0)