-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
138 lines (97 loc) · 4.14 KB
/
Makefile
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
#!/usr/bin/make -f
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
BUILDDIR ?= $(CURDIR)/build
# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --tags)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif
export GO111MODULE = on
# Build target
BINARY_NAME = opinitd
build_tags = netgo
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
ldflags = -X github.com/initia-labs/opinit-bots/version.Version=$(VERSION) \
-X github.com/initia-labs/opinit-bots/version.GitCommit=$(COMMIT)
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
ldflags += -w -s
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
all: install test
build: go.sum
ifeq ($(OS),Windows_NT)
exit 1
else
go build -mod=readonly $(BUILD_FLAGS) -o build/$(BINARY_NAME) ./cmd/$(BINARY_NAME)
endif
install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/$(BINARY_NAME)
.PHONY: build install
########################################
### Tools & dependencies
go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify
draw-deps:
@# requires brew install graphviz or apt-get install graphviz
go install github.com/RobotsAndPencils/goviz
@goviz -i ./cmd/initiad -d 2 | dot -Tpng -o dependency-graph.png
clean:
rm -rf \
$(BUILDDIR)/
.PHONY: clean
###############################################################################
### Linting ###
###############################################################################
lint:
golangci-lint run --out-format=tab --timeout=15m
lint-fix:
golangci-lint run --fix --out-format=tab --timeout=15m
.PHONY: lint lint-fix
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk
.PHONY: format
###############################################################################
### Tests
###############################################################################
test: test-unit test-e2e
test-all: test-unit test-race test-cover
test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./...
test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' ./...
test-cover:
@go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./...
test-e2e:
cd e2e && go test -v . -timeout 30m
benchmark:
@go test -timeout 20m -mod=readonly -bench=. ./...
.PHONY: test test-all test-cover test-unit test-race test-e2e benchmark
###############################################################################
### Protobuf ###
###############################################################################
DOCKER := $(shell which docker)
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
proto-all: proto-format proto-lint proto-gen
proto-gen:
@echo "Generating Protobuf files"
@$(protoImage) sh ./scripts/protocgen.sh
proto-format:
@$(protoImage) find ./proto -name "*.proto" -exec clang-format -i {} \;
proto-lint:
@$(protoImage) buf lint --error-format=json ./proto
proto-check-breaking:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main
.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking