Skip to content

Commit cc3327f

Browse files
authored
Merge pull request kubernetes-sigs#821 from vincepri/add-verifications-tools
🏃 Add verification tools, linter and modules
2 parents b82a7ea + 814d2ab commit cc3327f

File tree

10 files changed

+539
-40
lines changed

10 files changed

+539
-40
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919

2020
# Vscode files
2121
.vscode
22+
23+
# Tools binaries.
24+
hack/tools/bin

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ linters:
44
- misspell
55
- structcheck
66
- golint
7+
- govet
78
- deadcode
89
- errcheck
910
- varcheck

Makefile

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Copyright 2019 The Kubernetes Authors.
3+
# Copyright 2020 The Kubernetes Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -14,11 +14,30 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
#
18-
# Makefile with some common workflow for dev, build and test
19-
#
17+
# If you update this file, please follow
18+
# https://suva.sh/posts/well-documented-makefiles
19+
20+
## --------------------------------------
21+
## General
22+
## --------------------------------------
23+
24+
SHELL:=/usr/bin/env bash
25+
.DEFAULT_GOAL:=help
2026

21-
##@ General
27+
# Use GOPROXY environment variable if set
28+
GOPROXY := $(shell go env GOPROXY)
29+
ifeq ($(GOPROXY),)
30+
GOPROXY := https://proxy.golang.org
31+
endif
32+
export GOPROXY
33+
34+
# Active module mode, as we use go modules to manage dependencies
35+
export GO111MODULE=on
36+
37+
# Tools.
38+
TOOLS_DIR := hack/tools
39+
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
40+
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
2241

2342
# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
2443
# The awk commands is responsible to read the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help. Then, if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -28,9 +47,52 @@
2847
help: ## Display this help
2948
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
3049

31-
##@ Tests
50+
## --------------------------------------
51+
## Testing
52+
## --------------------------------------
3253

3354
.PHONY: test
34-
test: ## Run the script check-everything.sh which will check all
35-
GO111MODULE=on TRACE=1 ./hack/check-everything.sh
55+
test: ## Run the script check-everything.sh which will check all.
56+
TRACE=1 ./hack/check-everything.sh
57+
58+
## --------------------------------------
59+
## Binaries
60+
## --------------------------------------
61+
62+
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Build golangci-lint from tools folder.
63+
cd $(TOOLS_DIR); go build -tags=tools -o bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
64+
65+
## --------------------------------------
66+
## Linting
67+
## --------------------------------------
68+
69+
.PHONY: lint
70+
lint: $(GOLANGCI_LINT) ## Lint codebase.
71+
$(GOLANGCI_LINT) run -v
72+
73+
## --------------------------------------
74+
## Generate
75+
## --------------------------------------
76+
77+
.PHONY: modules
78+
modules: ## Runs go mod to ensure modules are up to date.
79+
go mod tidy
80+
cd $(TOOLS_DIR); go mod tidy
81+
82+
## --------------------------------------
83+
## Cleanup / Verification
84+
## --------------------------------------
85+
86+
.PHONY: clean
87+
clean: ## Cleanup.
88+
$(MAKE) clean-bin
89+
90+
.PHONY: clean-bin
91+
clean-bin: ## Remove all generated binaries.
92+
rm -rf hack/tools/bin
3693

94+
.PHONY: verify-modules
95+
verify-modules: modules
96+
@if !(git diff --quiet HEAD -- go.sum go.mod); then \
97+
echo "go module files are out of date"; exit 1; \
98+
fi

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@ require (
66
github.com/evanphx/json-patch v4.5.0+incompatible
77
github.com/go-logr/logr v0.1.0
88
github.com/go-logr/zapr v0.1.0
9-
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
9+
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
1010
github.com/googleapis/gnostic v0.3.1 // indirect
1111
github.com/imdario/mergo v0.3.6 // indirect
1212
github.com/onsi/ginkgo v1.11.0
1313
github.com/onsi/gomega v1.8.1
1414
github.com/prometheus/client_golang v1.0.0
1515
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
16+
go.uber.org/atomic v1.4.0 // indirect
1617
go.uber.org/zap v1.10.0
18+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
19+
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 // indirect
1720
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
1821
gomodules.xyz/jsonpatch/v2 v2.0.1
22+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
1923
gopkg.in/fsnotify.v1 v1.4.7
24+
gopkg.in/yaml.v2 v2.2.7 // indirect
2025
k8s.io/api v0.17.2
2126
k8s.io/apiextensions-apiserver v0.17.2
2227
k8s.io/apimachinery v0.17.2

0 commit comments

Comments
 (0)