-
Notifications
You must be signed in to change notification settings - Fork 117
/
Makefile
210 lines (165 loc) · 5.71 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
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
CHAINNET ?= mainnet
BINARY ?= sifnoded
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(GOPATH)/bin
NOW = $(shell date +'%Y-%m-%d_%T')
COMMIT := $(shell git log -1 --format='%H')
VERSION := $(shell git describe --match 'v*' --abbrev=8 --tags | sed 's/-g/-/' | sed 's/-[0-9]*-/-/')
IMAGE_TAG ?= latest
HTTPS_GIT := https://github.com/sifchain/sifnode.git
DOCKER ?= docker
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
GOFLAGS := ""
GOTAGS := ledger
GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
LDFLAGS = -X github.com/cosmos/cosmos-sdk/version.Name=sifchain \
-X github.com/cosmos/cosmos-sdk/version.ServerName=sifnoded \
-X github.com/cosmos/cosmos-sdk/version.ClientName=sifnoded \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/cosmos/cosmos-sdk/version.BuildTags=$(GOTAGS)
BUILD_FLAGS := -ldflags '$(LDFLAGS)' -tags '$(GOTAGS)'
BINARIES = ./cmd/sifnoded ./cmd/sifgen ./cmd/ebrelayer ./cmd/siftest
all: lint install
build-config:
echo $(CHAINNET)
echo $(BUILD_FLAGS)
init:
./scripts/init.sh
start:
sifnoded start
lint-pre:
@test -z $(gofmt -l .)
@GOFLAGS=$(GOFLAGS) go mod verify
lint: lint-pre
@golangci-lint run
lint-verbose: lint-pre
@golangci-lint run -v --timeout=5m
install: go.sum
GOFLAGS=$(GOFLAGS) go install $(BUILD_FLAGS) $(BINARIES)
build-sifd: go.sum
GOFLAGS=$(GOFLAGS) go build $(BUILD_FLAGS) ./cmd/sifnoded
clean:
@rm -rf $(GOBIN)/sif*
coverage:
@GOFLAGS=$(GOFLAGS) go test -v ./... -coverprofile=coverage.txt -covermode=atomic
tests:
@GOFLAGS=$(GOFLAGS) go test -v -coverprofile .testCoverage.txt ./...
feature-tests:
@GOFLAGS=$(GOFLAGS) go test -v ./test/bdd --godog.format=pretty --godog.random -race -coverprofile=.coverage.txt
mocks:
@echo "Generating mocks"
# Check if mockery is available in $PATH, install it if not.
@if ! which mockery > /dev/null; then \
echo "mockery not found, installing version v2..."; \
go install github.com/vektra/mockery/v2; \
fi
# Check if mockgen is available in $PATH, install it if not.
@if ! which mockgen > /dev/null; then \
echo "mockgen not found, installing latest version..."; \
go install go.uber.org/mock/mockgen@latest; \
fi
# Check again if mockery is installed, fail if not found.
@if ! which mockery > /dev/null; then \
echo "Error: mockery could not be found or installed"; \
exit 1; \
fi
# Check again if mockgen is installed, fail if not found.
@if ! which mockgen > /dev/null; then \
echo "Error: mockgen could not be found or installed"; \
exit 1; \
fi
# Run go generate on all packages.
@go generate ./...
run:
GOFLAGS=$(GOFLAGS) go run ./cmd/sifnoded start
build-image:
docker build -t sifchain/$(BINARY):$(IMAGE_TAG) -f ./cmd/$(BINARY)/Dockerfile .
run-image: build-image
docker run sifchain/$(BINARY):$(IMAGE_TAG)
sh-image: build-image
docker run -it sifchain/$(BINARY):$(IMAGE_TAG) sh
init-run:
./scripts/init.sh && ./scripts/run.sh
init-run-noInstall:
./scripts/init-noInstall.sh && ./scripts/run.sh
rollback:
./scripts/rollback.sh
###############################################################################
### Protobuf ###
###############################################################################
protoVer = v0.3
protoImageName = tendermintdev/sdk-proto-gen:$(protoVer)
proto-all: proto-format proto-lint proto-gen
proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) sh ./scripts/protocgen.sh
.PHONY: proto-gen
proto-format:
@echo "Formatting Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace \
--workdir /workspace $(protoImageName) \
find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;
.PHONY: proto-format
# This generates the SDK's custom wrapper for google.protobuf.Any. It should only be run manually when needed
proto-gen-any:
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) sh ./scripts/protocgen-any.sh
.PHONY: proto-gen-any
proto-swagger-gen:
@./scripts/protoc-swagger-gen.sh
.PHONY: proto-swagger-gen
proto-lint:
$(DOCKER_BUF) lint --error-format=json
.PHONY: proto-lint
proto-check-breaking:
# we should turn this back on after our first release
# $(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=master
.PHONY: proto-check-breaking
GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GO_VERSION)
## release: Build binaries for all platforms and generate checksums
ifdef GITHUB_TOKEN
release:
docker run \
--rm \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-e LDFLAGS="$(LDFLAGS)" \
-e GOTAGS="$(GOTAGS)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/sifnoded \
-w /go/src/sifnoded \
$(GORELEASER_IMAGE) \
release \
--clean
else
release:
@echo "Error: GITHUB_TOKEN is not defined. Please define it before running 'make release'."
endif
## release-dry-run: Dry-run build process for all platforms and generate checksums
release-dry-run:
docker run \
--rm \
-e LDFLAGS="$(LDFLAGS)" \
-e GOTAGS="$(GOTAGS)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/sifnoded \
-w /go/src/sifnoded \
$(GORELEASER_IMAGE) \
release \
--clean \
--skip-publish
## release-snapshot: Build snapshots for all platforms and generate checksums
release-snapshot:
docker run \
--rm \
-e LDFLAGS="$(LDFLAGS)" \
-e GOTAGS="$(GOTAGS)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/sifnoded \
-w /go/src/sifnoded \
$(GORELEASER_IMAGE) \
release \
--clean \
--snapshot \
--skip-validate \
--skip-publish
.PHONY: release release-dry-run release-snapshot