1
+ BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
2
+ COMMIT := $(shell git log -1 --format='% H')
3
+ APPNAME := example
4
+
5
+ # don't override user values
6
+ ifeq (,$(VERSION ) )
7
+ VERSION := $(shell git describe --exact-match 2>/dev/null)
8
+ # if VERSION is empty, then populate it with branch's name and raw commit hash
9
+ ifeq (,$(VERSION))
10
+ VERSION := $(BRANCH ) -$(COMMIT )
11
+ endif
12
+ endif
13
+
14
+ # Update the ldflags with the app, client & server names
15
+ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(APPNAME ) \
16
+ -X github.com/cosmos/cosmos-sdk/version.AppName=$(APPNAME ) d \
17
+ -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION ) \
18
+ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT )
19
+
20
+ BUILD_FLAGS := -ldflags '$(ldflags ) '
21
+
22
+ # #############
23
+ # ## Test ###
24
+ # #############
25
+
26
+ test-unit :
27
+ @echo Running unit tests...
28
+ @go test -mod=readonly -v -timeout 30m ./...
29
+
30
+ test-race :
31
+ @echo Running unit tests with race condition reporting...
32
+ @go test -mod=readonly -v -race -timeout 30m ./...
33
+
34
+ test-cover :
35
+ @echo Running unit tests and creating coverage report...
36
+ @go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE ) -covermode=atomic ./...
37
+ @go tool cover -html=$(COVER_FILE ) -o $(COVER_HTML_FILE )
38
+ @rm $(COVER_FILE )
39
+
40
+ bench :
41
+ @echo Running unit tests with benchmarking...
42
+ @go test -mod=readonly -v -timeout 30m -bench=. ./...
43
+
44
+ test : govet govulncheck test-unit
45
+
46
+ .PHONY : test test-unit test-race test-cover bench
47
+
48
+ # ################
49
+ # ## Install ###
50
+ # ################
51
+
52
+ all : install
53
+
54
+ install :
55
+ @echo " --> ensure dependencies have not been modified"
56
+ @go mod verify
57
+ @echo " --> installing $( APPNAME) d"
58
+ @go install $(BUILD_FLAGS ) -mod=readonly ./cmd/$(APPNAME ) d
59
+
60
+ .PHONY : all install
61
+
62
+ # #################
63
+ # ## Protobuf ###
64
+ # #################
65
+
66
+ # Use this proto-image if you do not want to use Ignite for generating proto files
67
+ protoVer =0.15.1
68
+ protoImageName =ghcr.io/cosmos/proto-builder:$(protoVer )
69
+ protoImage =$(DOCKER ) run --rm -v $(CURDIR ) :/workspace --workdir /workspace $(protoImageName )
70
+
71
+ proto-gen :
72
+ @echo " Generating protobuf files..."
73
+ @ignite generate proto-go --yes
74
+
75
+ .PHONY : proto-gen
76
+
77
+ # ################
78
+ # ## Linting ###
79
+ # ################
80
+
81
+ golangci_lint_cmd =golangci-lint
82
+ golangci_version =v1.61.0
83
+
84
+ lint :
85
+ @echo " --> Running linter"
86
+ @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version )
87
+ @$(golangci_lint_cmd ) run ./... --timeout 15m
88
+
89
+ lint-fix :
90
+ @echo " --> Running linter and fixing issues"
91
+ @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version )
92
+ @$(golangci_lint_cmd ) run ./... --fix --timeout 15m
93
+
94
+ .PHONY : lint lint-fix
95
+
96
+ # ##################
97
+ # ## Development ###
98
+ # ##################
99
+
100
+ govet :
101
+ @echo Running go vet...
102
+ @go vet ./...
103
+
104
+ govulncheck :
105
+ @echo Running govulncheck...
106
+ @go install golang.org/x/vuln/cmd/govulncheck@latest
107
+ @govulncheck ./...
108
+
109
+ .PHONY : govet govulncheck
0 commit comments