Skip to content

Commit 5ff39c7

Browse files
authored
Merge pull request #13 from wk8/wk8/basic_linux_tests
Adding a Makefile for code generation and linting
2 parents 28e6078 + 51e8e6f commit 5ff39c7

File tree

17 files changed

+193
-52
lines changed

17 files changed

+193
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/

.golangci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
run:
2+
skip-dirs:
3+
- release-tools
4+
linters:
5+
fast: false
6+
enable:
7+
- deadcode
8+
- errcheck
9+
- gocognit
10+
- gocyclo
11+
- gofmt
12+
- goimports
13+
- golint
14+
- govet
15+
- gosec
16+
- ineffassign
17+
- misspell
18+
- staticcheck
19+
- stylecheck
20+
- typecheck
21+
- unconvert
22+
- varcheck
23+
- whitespace
24+
25+
linters-settings:
26+
govet:
27+
# report about shadowed variables
28+
check-shadowing: true
29+
30+
issues:
31+
exclude:
32+
# conversion function names use underscores, and may be unused
33+
- "`convert_[a-z]+_[A-Z][a-zA-Z0-9]+_To_[a-z]+_[A-Z][a-zA-Z0-9]+` is unused"
34+
- "(don't|should not) use underscores in Go names; func convert_[a-z]+_[A-Z][a-zA-Z0-9]+_To_[a-z]+_[A-Z][a-zA-Z0-9]+ should be"
35+
36+
exclude-rules:
37+
# this file uses MD5 to compare files efficiently
38+
- path: integrationtests/utils.go
39+
text: "weak cryptographic primitive"
40+
linters:
41+
- gosec

Makefile

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
## This Makefile is meant to be run on Unix hosts - as such, it only supports the few
2+
## operations that don't require on a Windows host, mostly code generation and linting.
3+
4+
.DEFAULT_GOAL := all
5+
SHELL := /bin/bash
6+
7+
ifeq ($(GOPATH),)
8+
$(error "GOPATH env variable not defined")
9+
endif
10+
11+
REPO_ROOT = $(CURDIR)
12+
BUILD_DIR = build
13+
BUILD_TOOLS_DIR = $(BUILD_DIR)/tools
14+
15+
GO_ENV_VARS = GO111MODULE=on GOOS=windows
16+
17+
.PHONY: all
18+
all: generate compile lint
19+
20+
.PHONY: compile
21+
compile: compile-client compile-server compile-csi-proxy-api-gen
22+
23+
.PHONY: compile-client
24+
compile-client:
25+
$(GO_ENV_VARS) go build ./client/...
26+
27+
.PHONY: compile-server
28+
compile-server:
29+
$(GO_ENV_VARS) go build -o $(BUILD_DIR)/server.exe ./cmd/server
30+
31+
CSI_PROXY_API_GEN = $(BUILD_DIR)/csi-proxy-api-gen
32+
33+
.PHONY: compile-csi-proxy-api-gen
34+
compile-csi-proxy-api-gen:
35+
GO111MODULE=on go build -o $(CSI_PROXY_API_GEN) ./cmd/csi-proxy-api-gen
36+
37+
.PHONY: generate
38+
generate: generate-protobuf generate-csi-proxy-api-gen
39+
40+
# using xargs instead of -exec since the latter doesn't propagate exit statuses
41+
.PHONY: generate-protobuf
42+
generate-protobuf:
43+
@ if ! which protoc > /dev/null 2>&1; then echo 'Unable to find protoc binary' ; exit 1; fi
44+
@ generate_protobuf_for() { \
45+
local FILE="$$1"; \
46+
local FILE_DIR="$$(dirname "$$FILE")"; \
47+
echo "Generating protobuf file from $$FILE"; \
48+
protoc -I "$$FILE_DIR" -I "$$GOPATH/src" -I '$(REPO_ROOT)/client/api' "$$FILE" --go_out=plugins="grpc:$$FILE_DIR"; \
49+
} ; \
50+
export -f generate_protobuf_for; \
51+
find '$(REPO_ROOT)' -name '*.proto' -print0 | xargs -0 -n1 $(SHELL) -c 'generate_protobuf_for "$$0"'
52+
53+
.PHONY: generate-csi-proxy-api-gen
54+
generate-csi-proxy-api-gen: compile-csi-proxy-api-gen
55+
$(CSI_PROXY_API_GEN) -i github.com/kubernetes-csi/csi-proxy/client/api,github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/api/dummy
56+
57+
.PHONY: clean
58+
clean: clean-protobuf clean-generated
59+
60+
.PHONY: clean-protobuf
61+
clean-protobuf:
62+
find '$(REPO_ROOT)' -name '*.proto' -exec $(SHELL) -c 'rm -vf "$$(dirname {})/$$(basename {} .proto).pb.go"' \;
63+
64+
.PHONY: clean-generated
65+
clean-generated:
66+
find '$(REPO_ROOT)' -name '*_generated.go' -exec $(SHELL) -c '[[ "$$(head -n 1 "{}")" == "// Code generated by csi-proxy-api-gen"* ]] && rm -v {}' \;
67+
68+
# see https://github.com/golangci/golangci-lint/releases
69+
GOLANGCI_LINT_VERSION = v1.21.0
70+
GOLANGCI_LINT = $(BUILD_TOOLS_DIR)/golangci-lint/$(GOLANGCI_LINT_VERSION)/golangci-lint
71+
72+
.PHONY: lint
73+
lint: $(GOLANGCI_LINT)
74+
$(GO_ENV_VARS) $(GOLANGCI_LINT) run
75+
git --no-pager diff --exit-code
76+
77+
# see https://github.com/golangci/golangci-lint#binary-release
78+
$(GOLANGCI_LINT):
79+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$$(dirname '$(GOLANGCI_LINT)')" '$(GOLANGCI_LINT_VERSION)'

client/api/filesystem/v1alpha1/api.pb.go

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/api/filesystem/v1alpha1/api.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "github.com/kubernetes-csi/csi-proxy/client/api/errors.proto";
88
// here as an example of what API group and versions will look like. It will actually
99
// be implemented in a later patch.
1010

11-
service FileSystem {
11+
service Filesystem {
1212
// PathExists checks if the given path exists on the host.
1313
rpc PathExists(PathExistsRequest) returns (PathExistsResponse) {}
1414
}

client/groups/filesystem/v1alpha1/client_generated.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/csi-proxy-api-gen/generators/execute.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"strings"
55

66
goflag "flag"
7+
78
"github.com/spf13/pflag"
89
"k8s.io/gengo/args"
910
"k8s.io/klog"
@@ -32,7 +33,9 @@ func buildArgs(executableName string, cliArgs []string) *args.GeneratorArgs {
3233
pflagFlagSet := pflag.NewFlagSet(executableName, pflag.ExitOnError)
3334
genericArgs.AddFlags(pflagFlagSet)
3435
pflagFlagSet.AddGoFlagSet(goFlagSet)
35-
pflagFlagSet.Parse(cliArgs)
36+
if err := pflagFlagSet.Parse(cliArgs); err != nil {
37+
klog.Fatalf("Unable to parse CLI args: %v", err)
38+
}
3639

3740
klog.Infof("Verbosity level set to %d", verbosityLevel())
3841

cmd/csi-proxy-api-gen/generators/groups_and_versions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (d *groupDefinition) addVersion(versionPkg *types.Package) {
121121
}
122122
}
123123
errorMsg += fmt.Sprintf("\nYields 2 different signatures for the internal server callback:\n%s\nand\n%s",
124-
previousCallback, namedServerCallback.callback)
124+
previousCallback.callback, namedServerCallback.callback)
125125
klog.Fatalf(errorMsg)
126126
}
127127
}

integrationtests/api_groups_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/assert"
99
"github.com/stretchr/testify/require"
1010

11-
"github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/api/dummy/v1"
11+
v1 "github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/api/dummy/v1"
1212
"github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/api/dummy/v1alpha1"
1313
"github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/api/dummy/v1alpha2"
1414
v1client "github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/client/dummy/v1"

integrationtests/apigroups/server/dummy/internal/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package internal
22

3+
// ComputeDoubleRequest is the internal representation of requests to the ComputeDouble endpoint.
34
type ComputeDoubleRequest struct {
45
Input64 int64
56
}
67

8+
// ComputeDoubleResponse is the internal representation of responses from the ComputeDouble endpoint.
79
type ComputeDoubleResponse struct {
810
Response int64
911
}
1012

13+
// TellMeAPoemRequest is the internal representation of requests to the TellMeAPoem endpoint.
1114
type TellMeAPoemRequest struct {
1215
IWantATitle bool
1316
}
1417

18+
// TellMeAPoemResponse is the internal representation of responses from the TellMeAPoem endpoint.
1519
type TellMeAPoemResponse struct {
1620
Title string
1721
Lines []string

0 commit comments

Comments
 (0)