forked from spacemeshos/go-spacemesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
180 lines (142 loc) · 5.33 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
VERSION ?= $(shell git describe --tags)
LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH}"
include Makefile-libs.Inc
DOCKER_HUB ?= spacemeshos
UNIT_TESTS ?= $(shell go list ./... | grep -v systest/tests | grep -v cmd/node | grep -v cmd/gen-p2p-identity | grep -v cmd/trace | grep -v genvm/cmd)
COMMIT = $(shell git rev-parse HEAD)
SHA = $(shell git rev-parse --short HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
export CGO_ENABLED := 1
export CGO_CFLAGS := $(CGO_CFLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
# 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
ifeq ($(BRANCH),develop)
DOCKER_IMAGE_REPO := go-spacemesh
else
DOCKER_IMAGE_REPO := go-spacemesh-dev
endif
DOCKER_IMAGE = $(DOCKER_IMAGE_REPO):$(SHA)
DOCKER_BS_IMAGE = $(DOCKER_IMAGE_REPO)-bs:$(SHA)
# 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 v1.53.3
go install github.com/spacemeshos/go-scale/[email protected]
go install github.com/golang/mock/mockgen
go install gotest.tools/[email protected]
go install honnef.co/go/tools/cmd/[email protected]
.PHONY: install
build: go-spacemesh get-profiler
.PHONY: build
get-libs: get-postrs-lib
.PHONY: get-libs
get-profiler: get-postrs-profiler
.PHONY: get-profiler
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 -timeout 5m -p 1 $(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
staticcheck: get-libs
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" staticcheck ./...
.PHONY: staticcheck
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
lint-github-action: get-libs
./bin/golangci-lint run --config .golangci.yml --out-format=github-actions
.PHONY: lint-github-action
cover: get-libs
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -coverprofile=cover.out -timeout 0 -p 1 -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 -t $(DOCKER_IMAGE) .
.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 $(DOCKER_IMAGE) $(DOCKER_HUB)/$(DOCKER_IMAGE)
docker push $(DOCKER_HUB)/$(DOCKER_IMAGE)
.PHONY: dockerpush-only
dockerbuild-bs:
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_BS_IMAGE) -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 $(DOCKER_BS_IMAGE) $(DOCKER_HUB)/$(DOCKER_BS_IMAGE)
docker push $(DOCKER_HUB)/$(DOCKER_BS_IMAGE)
.PHONY: dockerpush-bs-only
fuzz:
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" ./scripts/fuzz.sh $(FUZZTIME)
.PHONY: fuzz