-
Notifications
You must be signed in to change notification settings - Fork 215
/
Makefile
196 lines (156 loc) · 5.86 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
VERSION ?= $(shell git describe --tags)
COMMIT = $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GOLANGCI_LINT_VERSION := v1.61.0
GOTESTSUM_VERSION := v1.12.0
GOSCALE_VERSION := v1.2.0
MOCKGEN_VERSION := v0.5.0
# Add an indicator to the branch name if dirty and use commithash if running in detached mode
ifeq ($(BRANCH),HEAD)
BRANCH = $(SHA)
endif
$(shell git diff --quiet)
ifneq ($(.SHELLSTATUS),0)
BRANCH := $(BRANCH)-dirty
endif
SHA = $(shell git rev-parse --short HEAD)
DOCKER_HUB ?= spacemeshos
DOCKER_IMAGE_REPO ?= go-spacemesh-dev
DOCKER_IMAGE_VERSION ?= $(SHA)
C_LDFLAGS = -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH}
ifneq (,$(findstring nomain,$(VERSION)))
C_LDFLAGS += -X main.noMainNet=true
endif
LDFLAGS = -ldflags "$(C_LDFLAGS)"
include Makefile-libs.Inc
# Set the correct extension for the executable based on the OS
# and set the correct ulimit command for the OS
ifeq ($(OS),Windows_NT)
EXE := .exe
else
ULIMIT := ulimit -n 4096;
endif
UNIT_TESTS ?= $(shell go list ./... | grep -v systest/tests | grep -v genvm/cmd)
export CGO_ENABLED := 1
export CGO_CFLAGS := $(CGO_CFLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
# setting extra command line params for the CI tests pytest commands
ifdef namespace
EXTRA_PARAMS:=$(EXTRA_PARAMS) --namespace=$(namespace)
endif
ifdef delns
EXTRA_PARAMS:=$(EXTRA_PARAMS) --delns=$(delns)
endif
ifdef dump
EXTRA_PARAMS:=$(EXTRA_PARAMS) --dump=$(dump)
endif
FUZZTIME ?= "10s"
all: install build
.PHONY: all
install:
git lfs install
go mod download
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
go install github.com/spacemeshos/go-scale/scalegen@$(GOSCALE_VERSION)
go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
.PHONY: install
build: go-spacemesh get-profiler get-postrs-service
.PHONY: build
get-libs: get-postrs-lib get-postrs-service
get-profiler: get-postrs-profiler
merge-nodes: get-libs
cd cmd/merge-nodes ; go build -o $(BIN_DIR)$@$(EXE) -ldflags "-X main.version=${VERSION}" .
.PHONY: merge-nodes
gen-p2p-identity:
cd cmd/gen-p2p-identity ; go build -o $(BIN_DIR)$@$(EXE) .
.PHONY: gen-p2p-identity
go-spacemesh: get-libs
cd cmd/node ; go build -o $(BIN_DIR)$@$(EXE) $(LDFLAGS) .
.PHONY: go-spacemesh gen-p2p-identity
bootstrapper:
cd cmd/bootstrapper ; go build -o $(BIN_DIR)go-$@$(EXE) .
.PHONY: bootstrapper
tidy:
go mod tidy
.PHONY: tidy
# Clear tests cache
clear-test-cache:
go clean -testcache
.PHONY: clear-test-cache
test: get-libs
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" gotestsum -- -race -p 1 -timeout 8m $(UNIT_TESTS)
.PHONY: test
generate: get-libs
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go generate ./...
.PHONY: generate
test-generate:
# Working directory must be clean, or this test would be destructive
@git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
# We expect `go generate` not to change anything, the test should fail otherwise
@make generate
@git diff --name-only --diff-filter=AM --exit-code . || { echo "\nPlease rerun 'make generate' and commit changes.\n"; exit 1; }
.PHONY: test-generate
test-tidy:
# Working directory must be clean, or this test would be destructive
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
# We expect `go mod tidy` not to change anything, the test should fail otherwise
make tidy
git diff --exit-code || (git --no-pager diff && git checkout . && exit 1)
.PHONY: test-tidy
test-fmt:
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
# We expect `go fmt` not to change anything, the test should fail otherwise
go fmt ./...
git diff --exit-code || (git --no-pager diff && git checkout . && exit 1)
.PHONY: test-fmt
lint: get-libs
./bin/golangci-lint run --config .golangci.yml
.PHONY: lint
# Auto-fixes golangci-lint issues where possible.
lint-fix: get-libs
./bin/golangci-lint run --config .golangci.yml --fix
.PHONY: lint-fix
cover: get-libs
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" gotestsum --junitfile junit.xml -- -coverprofile=cover.out -p 1 -timeout 30m -coverpkg=./... $(UNIT_TESTS)
.PHONY: cover
list-versions:
@echo "Latest 5 tagged versions:\n"
@git for-each-ref --sort=-creatordate --count=5 --format '%(creatordate:short): %(refname:short)' refs/tags
.PHONY: list-versions
dockerbuild-go:
DOCKER_BUILDKIT=1 docker build \
--secret id=mynetrc,src=$(HOME)/.netrc \
--build-arg VERSION=${VERSION} \
-t go-spacemesh:$(SHA) \
-t $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_VERSION) \
.
.PHONY: dockerbuild-go
dockerpush: dockerbuild-go dockerpush-only
.PHONY: dockerpush
dockerpush-only:
ifneq ($(DOCKER_USERNAME):$(DOCKER_PASSWORD),:)
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
endif
docker tag go-spacemesh:$(SHA) $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_VERSION)
docker push $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_VERSION)
.PHONY: dockerpush-only
dockerbuild-bs:
DOCKER_BUILDKIT=1 docker build \
--secret id=mynetrc,src=$(HOME)/.netrc \
-t go-spacemesh-bs:$(SHA) \
-t $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO)-bs:$(DOCKER_IMAGE_VERSION) \
-f ./bootstrap.Dockerfile \
.
.PHONY: dockerbuild-bs
dockerpush-bs: dockerbuild-bs dockerpush-bs-only
.PHONY: dockerpush-bs
dockerpush-bs-only:
ifneq ($(DOCKER_USERNAME):$(DOCKER_PASSWORD),:)
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
endif
docker tag go-spacemesh-bs:$(SHA) $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO)-bs:$(DOCKER_IMAGE_VERSION)
docker push $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO)-bs:$(DOCKER_IMAGE_VERSION)
.PHONY: dockerpush-bs-only
fuzz:
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" ./scripts/fuzz.sh $(FUZZTIME)
.PHONY: fuzz