forked from zalando/skipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
196 lines (160 loc) · 7.76 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
SOURCES = $(shell find . -name '*.go' -not -path "./vendor/*" -and -not -path "./_test_plugins" -and -not -path "./_test_plugins_fail" )
PACKAGES = $(shell go list ./...)
CURRENT_VERSION = $(shell git describe --tags --always --dirty)
VERSION ?= $(CURRENT_VERSION)
COMMIT_HASH = $(shell git rev-parse --short HEAD)
LIMIT_FDS = $(shell ulimit -n)
TEST_ETCD_VERSION ?= v2.3.8
TEST_PLUGINS = _test_plugins/filter_noop.so \
_test_plugins/predicate_match_none.so \
_test_plugins/dataclient_noop.so \
_test_plugins/multitype_noop.so \
_test_plugins_fail/fail.so
GO111 ?= on
default: build
lib: $(SOURCES)
GO111MODULE=$(GO111) go build $(PACKAGES)
bindir:
mkdir -p bin
skipper: $(SOURCES) bindir
GO111MODULE=$(GO111) go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" -o bin/skipper ./cmd/skipper/*.go
eskip: $(SOURCES) bindir
GO111MODULE=$(GO111) go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" -o bin/eskip ./cmd/eskip/*.go
fixlimits:
ifeq (LIMIT_FDS, 256)
ulimit -n 1024
endif
build: $(SOURCES) lib skipper eskip
build.linux.armv8:
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 GO111MODULE=$(GO111) go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.linux.armv7:
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 GO111MODULE=$(GO111) go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=$(GO111) go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.osx:
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=$(GO111) go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.windows:
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=$(GO111) go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
install: $(SOURCES)
GO111MODULE=$(GO111) go install -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
GO111MODULE=$(GO111) go install -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/eskip
check: build check-plugins
# go test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do GO111MODULE=$(GO111) go test $$p || break; done
shortcheck: build check-plugins fixlimits
# go test -test.short -run ^Test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do GO111MODULE=$(GO111) go test -test.short -run ^Test $$p || break -1; done
cicheck: build check-plugins
# go test -test.short -run ^Test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do GO111MODULE=$(GO111) go test -tags=redis -test.short -run ^Test $$p || break -1; done
check-race: build
# go test -race -test.short -run ^Test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do GO111MODULE=$(GO111) go test -race -test.short -run ^Test $$p || break -1; done
check-plugins: $(TEST_PLUGINS)
GO111MODULE=$(GO111) go test -run LoadPlugins
_test_plugins/%.so: _test_plugins/%.go
GO111MODULE=$(GO111) go build -buildmode=plugin -o $@ $<
_test_plugins_fail/%.so: _test_plugins_fail/%.go
GO111MODULE=$(GO111) go build -buildmode=plugin -o $@ $<
bench: build $(TEST_PLUGINS)
# go test -bench . $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do GO111MODULE=$(GO111) go test -bench . $$p; done
lint: build staticcheck
clean:
go clean -i -cache -testcache ./...
rm -rf .coverprofile-all .cover
rm -f ./_test_plugins/*.so
rm -f ./_test_plugins_fail/*.so
deps:
go env
./etcd/install.sh $(TEST_ETCD_VERSION)
@curl -o /tmp/staticcheck_linux_amd64.tar.gz -LO https://github.com/dominikh/go-tools/releases/download/2020.1.3/staticcheck_linux_amd64.tar.gz
@sha256sum /tmp/staticcheck_linux_amd64.tar.gz | grep -q 0f6fab088826fb6d52a5aa4986b39790b795ff37d5319dc605a98be919fdd070
@tar -C /tmp -xzf /tmp/staticcheck_linux_amd64.tar.gz
@mkdir -p $(GOPATH)/bin
@mv /tmp/staticcheck/staticcheck $(GOPATH)/bin/
@chmod +x $(GOPATH)/bin/staticcheck
@curl -o /tmp/gosec.tgz -LO https://github.com/securego/gosec/releases/download/2.0.0/gosec_2.0.0_linux_amd64.tar.gz
@sha256sum /tmp/gosec.tgz | grep -q 490c2a0434b2b9cbb2f4c5031eafe228023f1ac41b36dddd757bff9e1de76a2b
@tar -C /tmp -xzf /tmp/gosec.tgz
@mkdir -p $(GOPATH)/bin
@mv /tmp/gosec $(GOPATH)/bin/
@chmod +x $(GOPATH)/bin/gosec
@which gosec || cp -a $(GOPATH)/bin/gosec $(GOBIN)/gosec
vet: $(SOURCES)
GO111MODULE=$(GO111) go vet $(PACKAGES)
# TODO(sszuecs) review disabling these checks, f.e.:
# -ST1000 missing package doc in many packages
# -ST1003 wrong naming convention Api vs API, Id vs ID
# -ST1012 too many error variables are not having prefix "err"
# -ST1020 too many wrong comments on exported functions to fix right away
# -ST1021 too many wrong comments on exported functions to fix right away
# -ST1022 too many wrong comments on exported functions to fix right away
staticcheck: $(SOURCES)
GO111MODULE=$(GO111) staticcheck -checks "all,-ST1000,-ST1003,-ST1012,-ST1020,-ST1021,-ST1022" $(PACKAGES)
# TODO(sszuecs) review disabling these checks, f.e.:
# G101 find by variable name match "oauth" are not hardcoded credentials
# G104 ignoring errors are in few cases fine
# G304 reading kubernetes secret filepaths are not a file inclusions
gosec: $(SOURCES)
GO111MODULE=$(GO111) gosec -quiet -exclude="G101,G104,G304" ./...
fmt: $(SOURCES)
@gofmt -w -s $(SOURCES)
check-fmt: $(SOURCES)
@if [ "$$(gofmt -s -d $(SOURCES))" != "" ]; then false; else true; fi
precommit: fmt build vet staticcheck check-race shortcheck
check-precommit: check-fmt build vet staticcheck check-race cicheck gosec
.coverprofile-all: $(SOURCES) $(TEST_PLUGINS)
# go list -f \
# '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' \
# $(PACKAGES) | xargs -i sh -c {}
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do \
go list -f \
'{{if len .TestGoFiles}}"GO111MODULE=on go test -tags=redis -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' \
$$p | xargs -i sh -c {}; \
done
go get github.com/modocache/gover
gover . .coverprofile-all
cover: .coverprofile-all
go tool cover -func .coverprofile-all
show-cover: .coverprofile-all
go tool cover -html .coverprofile-all
publish-coverage: .coverprofile-all
curl -s https://codecov.io/bash -o codecov
bash codecov -f .coverprofile-all
ci-trigger:
ifeq ($(TRAVIS_BRANCH)_$(TRAVIS_PULL_REQUEST)_$(findstring major-release,$(TRAVIS_COMMIT_MESSAGE)), master_false_major-release)
make deps publish-coverage
else ifeq ($(TRAVIS_BRANCH)_$(TRAVIS_PULL_REQUEST)_$(findstring minor-release,$(TRAVIS_COMMIT_MESSAGE)), master_false_minor-release)
make deps publish-coverage
else ifeq ($(TRAVIS_BRANCH)_$(TRAVIS_PULL_REQUEST), master_false)
make deps publish-coverage
else ifeq ($(TRAVIS_BRANCH), master)
make deps check-precommit
else
make deps check-race cicheck check-plugins
endif