forked from ethersphere/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
161 lines (132 loc) · 5.81 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
GO ?= go
GOBIN ?= $$($(GO) env GOPATH)/bin
GOLANGCI_LINT ?= $(GOBIN)/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.43.0
GOGOPROTOBUF ?= protoc-gen-gogofaster
GOGOPROTOBUF_VERSION ?= v1.3.1
BEEKEEPER_INSTALL_DIR ?= $(GOBIN)
BEEKEEPER_USE_SUDO ?= false
BEEKEEPER_CLUSTER ?= local
BEELOCAL_BRANCH ?= main
BEEKEEPER_BRANCH ?= master
REACHABILITY_OVERRIDE_PUBLIC ?= false
BATCHFACTOR_OVERRIDE_PUBLIC ?= 5
GO_MIN_VERSION ?= "1.17"
GO_BUILD_VERSION ?= "1.17.2"
GO_MOD_ENABLED_VERSION ?= "1.12"
GO_MOD_VERSION ?= "$(shell go mod edit -print | awk '/^go[ \t]+[0-9]+\.[0-9]+(\.[0-9]+)?[ \t]*$$/{print $$2}')"
GO_SYSTEM_VERSION ?= "$(shell go version | awk '{ gsub(/go/, "", $$3); print $$3 }')"
BEE_API_VERSION ?= "$(shell grep '^ version:' openapi/Swarm.yaml | awk '{print $$2}')"
BEE_DEBUG_API_VERSION ?= "$(shell grep '^ version:' openapi/SwarmDebug.yaml | awk '{print $$2}')"
COMMIT_HASH ?= "$(shell git describe --long --dirty --always --match "" || true)"
CLEAN_COMMIT ?= "$(shell git describe --long --always --match "" || true)"
COMMIT_TIME ?= "$(shell git show -s --format=%ct $(CLEAN_COMMIT) || true)"
LDFLAGS ?= -s -w \
-X github.com/ethersphere/bee.commitHash="$(COMMIT_HASH)" \
-X github.com/ethersphere/bee.commitTime="$(COMMIT_TIME)" \
-X github.com/ethersphere/bee/pkg/api.Version="$(BEE_API_VERSION)" \
-X github.com/ethersphere/bee/pkg/debugapi.Version="$(BEE_DEBUG_API_VERSION)" \
-X github.com/ethersphere/bee/pkg/p2p/libp2p.reachabilityOverridePublic="$(REACHABILITY_OVERRIDE_PUBLIC)" \
-X github.com/ethersphere/bee/pkg/postage/listener.batchFactorOverridePublic="$(BATCHFACTOR_OVERRIDE_PUBLIC)"
.PHONY: all
all: build lint vet test-race binary
.PHONY: binary
binary: CGO_ENABLED=0
binary: dist FORCE
$(GO) version
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o dist/bee ./cmd/bee
dist:
mkdir $@
.PHONY: beekeeper
beekeeper:
ifeq ($(BEEKEEPER_BRANCH), master)
curl -sSfL https://raw.githubusercontent.com/ethersphere/beekeeper/master/scripts/install.sh | BEEKEEPER_INSTALL_DIR=$(BEEKEEPER_INSTALL_DIR) USE_SUDO=$(BEEKEEPER_USE_SUDO) bash
else
git clone -b $(BEEKEEPER_BRANCH) https://github.com/ethersphere/beekeeper.git && cd beekeeper && mkdir -p $(BEEKEEPER_INSTALL_DIR) && make binary
ifeq ($(BEEKEEPER_USE_SUDO), true)
sudo mv beekeeper/dist/beekeeper $(BEEKEEPER_INSTALL_DIR)
else
mv beekeeper/dist/beekeeper $(BEEKEEPER_INSTALL_DIR)
endif
rm -rf beekeeper
endif
test -f ~/.beekeeper.yaml || curl -sSfL https://raw.githubusercontent.com/ethersphere/beekeeper/$(BEEKEEPER_BRANCH)/config/beekeeper-local.yaml -o ~/.beekeeper.yaml
mkdir -p ~/.beekeeper && curl -sSfL https://raw.githubusercontent.com/ethersphere/beekeeper/$(BEEKEEPER_BRANCH)/config/local.yaml -o ~/.beekeeper/local.yaml
.PHONY: beelocal
beelocal:
curl -sSfL https://raw.githubusercontent.com/ethersphere/beelocal/$(BEELOCAL_BRANCH)/beelocal.sh | bash
.PHONY: deploylocal
deploylocal:
beekeeper create bee-cluster --cluster-name $(BEEKEEPER_CLUSTER)
.PHONY: testlocal
testlocal:
export PATH=${PATH}:$(GOBIN)
beekeeper check --cluster-name local --checks=ci-full-connectivity,ci-gc,ci-manifest,ci-pingpong,ci-pss,ci-pushsync-chunks,ci-retrieval,ci-content-availability,ci-settlements,ci-soc
.PHONY: testlocal-all
testlocal-all: beekeeper beelocal deploylocal testlocal
.PHONY: install-formatters
install-formatters:
$(GO) get github.com/daixiang0/gci
$(GO) install mvdan.cc/gofumpt@latest
FOLDER=$(shell pwd)
.PHONY: format
format:
$(GOBIN)/gofumpt -l -w $(FOLDER)
$(GOBIN)/gci -w -local $(go list -m) `find $(FOLDER) -type f \! -name "*.pb.go" -name "*.go" \! -path \*/\.git/\* -exec echo {} \;`
.PHONY: lint
lint: linter
$(GOLANGCI_LINT) run
TREE=$$(git hash-object -t tree /dev/null); \
TW=$$(git diff-index --cached --check --diff-filter=d "$${TREE}"); \
[ "$${TW}" != "" ] && echo "Trailing whitespaces found:\n $${TW}" && exit 1; exit 0
.PHONY: lint-local
lint-local: linter
$(GOLANGCI_LINT) -c .golangci.local.yml run
.PHONY: lint-style
lint-style: linter
$(GOLANGCI_LINT) -c .golangci.style.yml run
.PHONY: linter
linter:
test -f $(GOLANGCI_LINT) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$($(GO) env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
.PHONY: vet
vet:
$(GO) vet ./...
.PHONY: test-race
test-race:
ifdef cover
$(GO) test -race -failfast -coverprofile=cover.out -v ./...
else
$(GO) test -race -failfast -v ./...
endif
.PHONY: test-integration
test-integration:
$(GO) test -tags=integration -v ./...
.PHONY: test
test:
$(GO) test -v -failfast ./...
.PHONY: build
build: CGO_ENABLED=0
build: check-version
build:
$(GO) build -trimpath -ldflags "$(LDFLAGS)" ./...
.PHONY: check-version
check-version:
[ ${GO_SYSTEM_VERSION} \< ${GO_MOD_ENABLED_VERSION} ] && echo "The version of Golang on the system (${GO_SYSTEM_VERSION}) is too old and does not support go modules. Please use at least ${GO_MIN_VERSION}." && exit 1; exit 0
[ ${GO_SYSTEM_VERSION} \< ${GO_MIN_VERSION} ] && echo "The version of Golang on the system (${GO_SYSTEM_VERSION}) is below the minimum required version (${GO_MIN_VERSION}) and therefore will not build correctly." && exit 1; exit 0
if ! expr ${GO_BUILD_VERSION} : ^${GO_MOD_VERSION} 1>/dev/null; then echo "The version of Golang mod (${GO_MOD_VERSION}) does not match required version (${GO_BUILD_VERSION})." && exit 1; fi
.PHONY: githooks
githooks:
ln -f -s ../../.githooks/pre-push.bash .git/hooks/pre-push
.PHONY: protobuftools
protobuftools:
which protoc || ( echo "install protoc for your system from https://github.com/protocolbuffers/protobuf/releases" && exit 1)
which $(GOGOPROTOBUF) || ( cd /tmp && GO111MODULE=on $(GO) get -u github.com/gogo/protobuf/$(GOGOPROTOBUF)@$(GOGOPROTOBUF_VERSION) )
.PHONY: protobuf
protobuf: GOFLAGS=-mod=mod # use modules for protobuf file include option
protobuf: protobuftools
$(GO) generate -run protoc ./...
.PHONY: clean
clean:
$(GO) clean
rm -rf dist/
FORCE: