-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
213 lines (163 loc) · 8.57 KB
/
Makefile
File metadata and controls
213 lines (163 loc) · 8.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/make -f
###############################################################################
### Go Modules ###
###############################################################################
verify:
@echo "Verifying all go module dependencies..."
@find . -name 'go.mod' -type f -execdir go mod verify \;
tidy:
@echo "Cleaning up all go module dependencies..."
@find . -name 'go.mod' -type f -execdir go mod tidy \;
.PHONY: verify tidy
###############################################################################
### Lint / Format ###
###############################################################################
lint:
@echo "Linting all go modules..."
@find . -name 'go.mod' -type f -execdir golangci-lint run --out-format=tab \;
lint-fix: format
@echo "Attempting to fix lint errors in all go modules..."
@find . -name 'go.mod' -type f -execdir golangci-lint run --fix --out-format=tab --issues-exit-code=0 \;
format_filter = \
-type f \
-name '*.go' \
! -path '*/mocks/*' \
! -name '*.cosmos_orm.go' \
! -name '*.pb.go' \
! -name '*.pb.gw.go' \
! -name '*.pulsar.go' \
! -name 'statik.go'
format:
@echo "Formatting all go modules..."
@find . $(format_filter) | xargs gofmt -s -w
@find . $(format_filter) | xargs goimports -w -local github.com/chora-io/mods
@find . $(format_filter) | xargs misspell -w
.PHONY: lint lint-fix format
###############################################################################
### Go Version ###
###############################################################################
GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MIN_GO_MAJOR_VERSION = 1
MIN_GO_MINOR_VERSION = 22
GO_VERSION_ERROR = Golang version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, \
please update to at least $(MIN_GO_MAJOR_VERSION).$(MIN_GO_MINOR_VERSION)
go-version:
@echo "Verifying go version..."
@if [ $(GO_MAJOR_VERSION) -gt $(MIN_GO_MAJOR_VERSION) ]; then \
exit 0; \
elif [ $(GO_MAJOR_VERSION) -lt $(MIN_GO_MAJOR_VERSION) ]; then \
echo $(GO_VERSION_ERROR); \
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MIN_GO_MINOR_VERSION) ]; then \
echo $(GO_VERSION_ERROR); \
exit 1; \
fi
.PHONY: go-version
###############################################################################
### Tools ###
###############################################################################
tools: go-version
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/client9/misspell/cmd/misspell@latest
go install golang.org/x/tools/cmd/goimports@latest
.PHONY: tools
###############################################################################
### Protobuf ###
###############################################################################
protoVersion=0.14.0
protoImage=ghcr.io/cosmos/proto-builder:$(protoVersion)
containerProtoFmt=chora-mods-proto-fmt-$(protoVersion)
containerProtoGen=chora-mods-proto-gen-$(protoVersion)
proto-all: proto-lint-fix proto-format proto-gen-admin proto-gen-content proto-gen-governor proto-gen-subject proto-gen-validator proto-gen-voucher proto-check-breaking
proto-lint:
@protolint .
proto-lint-fix:
@protolint -fix .
proto-format:
@echo "Formatting protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoFmt}$$"; then docker start -a $(containerProtoFmt); else docker run --name $(containerProtoFmt) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find . -name "*.proto" -exec clang-format -i {} \; ; fi
proto-gen-admin:
@echo "Generating protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}-admin$$"; then docker start -a $(containerProtoGen)-admin; else docker run --name $(containerProtoGen)-admin -v $(CURDIR):/workspace --workdir /workspace $(protoImage) \
sh -c 'cd admin; ./scripts/protocgen.sh'; fi
proto-gen-content:
@echo "Generating protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}-content$$"; then docker start -a $(containerProtoGen)-content; else docker run --name $(containerProtoGen)-content -v $(CURDIR):/workspace --workdir /workspace $(protoImage) \
sh -c 'cd content; ./scripts/protocgen.sh'; fi
proto-gen-governor:
@echo "Generating protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}-governor$$"; then docker start -a $(containerProtoGen)-governor; else docker run --name $(containerProtoGen)-governor -v $(CURDIR):/workspace --workdir /workspace $(protoImage) \
sh -c 'cd governor; ./scripts/protocgen.sh'; fi
proto-gen-subject:
@echo "Generating protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}-subject$$"; then docker start -a $(containerProtoGen)-subject; else docker run --name $(containerProtoGen)-subject -v $(CURDIR):/workspace --workdir /workspace $(protoImage) \
sh -c 'cd subject; ./scripts/protocgen.sh'; fi
proto-gen-validator:
@echo "Generating protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}-validator$$"; then docker start -a $(containerProtoGen)-validator; else docker run --name $(containerProtoGen)-validator -v $(CURDIR):/workspace --workdir /workspace $(protoImage) \
sh -c 'cd validator; ./scripts/protocgen.sh'; fi
proto-gen-voucher:
@echo "Generating protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}-voucher$$"; then docker start -a $(containerProtoGen)-voucher; else docker run --name $(containerProtoGen)-voucher -v $(CURDIR):/workspace --workdir /workspace $(protoImage) \
sh -c 'cd voucher; ./scripts/protocgen.sh'; fi
proto-check-breaking:
@docker run -v $(shell pwd):/workspace --workdir /workspace bufbuild/buf:1.9.0 breaking --against https://github.com/chora-io/mods.git#branch=main
.PHONY: proto-all proto-lint proto-lint-fix proto-format proto-gen-admin proto-gen-content proto-gen-governor proto-gen-subject proto-gen-validator proto-gen-voucher proto-check-breaking
###############################################################################
### Tests ###
###############################################################################
CURRENT_DIR=$(shell pwd)
GO_MODULES=$(shell find . -type f -name 'go.mod' -print0 | xargs -0 -n1 dirname | sort)
test: test-all
test-all:
@for module in $(GO_MODULES); do \
echo "Testing Module $$module"; \
cd ${CURRENT_DIR}/$$module; \
go test ./...; \
done
test-admin:
@echo "Testing Module admin"
@cd admin && go test ./... \
-coverprofile=../coverage-admin.out -covermode=atomic
test-content:
@echo "Testing Module content"
@cd content && go test ./... \
-coverprofile=../coverage-content.out -covermode=atomic
test-governor:
@echo "Testing Module governor"
@cd governor && go test ./... \
-coverprofile=../coverage-governor.out -covermode=atomic
test-subject:
@echo "Testing Module subject"
@cd subject && go test ./... \
-coverprofile=../coverage-subject.out -covermode=atomic
test-validator:
@echo "Testing Module validator"
@cd validator && go test ./... \
-coverprofile=../coverage-validator.out -covermode=atomic
test-voucher:
@echo "Testing Module voucher"
@cd voucher && go test ./... \
-coverprofile=../coverage-voucher.out -covermode=atomic
test-coverage:
@cat coverage*.out | grep -v "mode: atomic" >> coverage.txt
test-clean:
@go clean -testcache
@find . -name 'coverage.txt' -delete
@find . -name 'coverage*.out' -delete
.PHONY: test test-all test-admin test-content test-governor test-subject test-validator test-voucher test-coverage test-clean
###############################################################################
### Documentation ###
###############################################################################
docs:
@echo "Wait a few seconds and then visit http://localhost:6060/pkg/github.com/chora-io/mods/"
godoc -http=:6060
.PHONY: docs
###############################################################################
### Clean ###
###############################################################################
clean: test-clean
@rm -rf $(BUILD_DIR)
.PHONY: clean