forked from jbott/gollum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
206 lines (165 loc) · 7.73 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
.DEFAULT_GOAL := help
GOLLUM_TAG := $(shell git describe --always --tags --match "v*" | sed -E 's/^v([0-9\.]+)(-[0-9]+){0,1}((-)g([a-f0-9]+)){0,1}.*/\1\2\4\5/')
GOLLUM_DIRTY := $(if $(shell git status --porcelain),-dirty)
GOLLUM_VERSION := $(join $(GOLLUM_TAG),$(GOLLUM_DIRTY))
GO_ENV := GORACE="halt_on_error=0" GO111MODULE="on"
GO_FLAGS := -ldflags="-s -X 'github.com/trivago/gollum/core.versionString=$(GOLLUM_VERSION)'"
GO_FLAGS_DEBUG := $(GO_FLAGS) -ldflags='-linkmode=internal' -gcflags='-N -l'
TAGS_GOLLUM=netgo
TAGS_UNIT=unit
TAGS_INTEGRATION=integration
#############################################################################################################
# Build related targets
.PHONY: freebsd # Build gollum zip-file for FreeBSD (x64)
freebsd:
@echo "\033[0;33mBuilding for FreeBSD/x64\033[0;0m"
@GOOS=freebsd GOARCH=amd64 $(GO_ENV) go build $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -o gollum
@zip dist/gollum-$(GOLLUM_VERSION)-FreeBSD_x64.zip gollum
.PHONY: linux # Build gollum zip-file for Linux (x64)
linux:
@echo "\033[0;33mBuilding for Linux/x64\033[0;0m"
@GOOS=linux GOARCH=amd64 $(GO_ENV) go build $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -o gollum
@zip dist/gollum-$(GOLLUM_VERSION)-Linux_x64.zip gollum
.PHONY: mac # Build gollum zip-file for MacOS X (x64)
mac:
@echo "\033[0;33mBuilding for MacOS X (MacOS/x64)\033[0;0m"
@GOOS=darwin GOARCH=amd64 $(GO_ENV) go build $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -o gollum
@zip dist/gollum-$(GOLLUM_VERSION)-MacOS_x64.zip gollum
.PHONY: pi # Build gollum zip-file for Raspberry Pi / Linux (ARMv6)
pi:
@echo "\033[0;33mBuilding for Raspberry Pi (Linux/ARMv6)\033[0;0m"
@GOOS=linux GOARCH=arm GOARM=6 $(GO_ENV) go build $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -o gollum
@zip dist/gollum-$(GOLLUM_VERSION)-Linux_Arm6.zip gollum
.PHONY: bbb # Build gollum zip-file for BeagleBone Black / Linux (ARMv7)
bbb:
@echo "\033[0;33mBuilding for BeagleBone Black (Linux/ARMv7)\033[0;0m"
@GOOS=linux GOARCH=arm GOARM=7 $(GO_ENV) go build $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -o gollum
@zip dist/gollum-$(GOLLUM_VERSION)-Linux_Arm7.zip gollum
.PHONY: upload_dyno
upload_dyno:
@echo "\033[0;33mUploading to dyno\033[0;0m"
@rsync -av --progress gollum 'dyno:~/'
.PHONY: upload_daq
upload_daq:
@echo "\033[0;33mUploading to daq\033[0;0m"
@rsync -av --progress gollum 'daq:~/'
.PHONY: win # Build gollum zip-file for Windows (x64)
win:
@echo "\033[0;33mBuilding for Windows/x64\033[0;0m"
@GOOS=windows GOARCH=amd64 $(GO_ENV) go build $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -o gollum.exe
@zip dist/gollum-$(GOLLUM_VERSION)-Windows_x64.zip gollum
.PHONY: docker # Build the gollum docker image
docker:
@echo "\033[0;33mBuilding docker image\033[0;0m"
@docker build -t trivago/gollum:$(GOLLUM_VERSION) .
.PHONY: docker-dev # Build the gollum docker development image
docker-dev:
@echo "\033[0;33mBuilding development docker image\033[0;0m"
@docker build -t trivago/gollum:$(GOLLUM_VERSION)-dev -f Dockerfile-dev .
.PHONY: build # Build the gollum binary for the current platform
build:
@$(GO_ENV) go build $(GO_FLAGS) -tags="$(TAGS_GOLLUM)"
.PHONY: debug # Build the gollum binary for the current platform with additional debugging flags
debug:
@$(GO_ENV) go build $(GO_FLAGS_DEBUG) -tags="$(TAGS_GOLLUM)"
.PHONY: all # Test and build all distributions of gollum
all: clean test freebsd linux docker mac pi win
.PHONY: install # Install the current gollum build to the system
install: build
@go install
.PHONY: clean # Remove all files created by build and distribution targets
clean:
@rm -f ./gollum
@rm -f ./dist/gollum_*.zip
@go clean
#############################################################################################################
# Vendor related targets
.PHONY: vendor # Generate the vendor folder
vendor:
@$(GO_ENV) go mod vendor
.PHONY: vendor-clean # Removes files & directories under ./vendor that are ignored by git
vendor-clean:
@find vendor | git check-ignore --stdin | while read f ; do rm -vrf "$$f" ; done
#############################################################################################################
# Test related targets
.PHONY: test # Run all relevant tests (no native tests)
test: test-unit test-integration
.PHONY: test-unit # Run all unit tests
test-unit:
@echo "\033[0;33mRunning unit tests\033[0;0m"
@$(GO_ENV) go test $(GO_FLAGS) -v -cover -timeout 10s -race -tags="$(TAGS_GOLLUM) $(TAGS_UNIT)" ./...
.PHONY: test-native # Run all unit tests for native plugins
test-native:
@echo "\033[0;33mRunning unit tests for native plugins\033[0;0m"
@$(GO_ENV) go test $(GO_FLAGS) -v -cover -timeout 10s -race -tags="$(TAGS_GOLLUM)" ./contrib/native/...
.PHONY: test-integration # Run all integration tests
test-integration:: build
@echo "\033[0;33mRunning integration tests\033[0;0m"
@$(GO_ENV) go test $(GO_FLAGS) -v -race -tags="$(TAGS_GOLLUM) $(TAGS_INTEGRATION)" ./testing/integration
#############################################################################################################
# Linter related targets
.PHONY: lint # Run all linters
lint: lint-fmt lint-meta
.PHONY: lint-meta # Run the go meta linter
lint-meta:
@echo "\033[0;33mRunning go linters\033[0;0m"
@gometalinter.v2 --vendor --cyclo-over=20 \
--disable=goconst \
--disable=gas \
--disable=maligned \
--disable=gocyclo \
--disable=errcheck \
--disable=gosec \
--exclude="\.[cC]lose[^ ]*\(.*\) \(errcheck\)" \
--skip=contrib \
--skip=docs \
--skip=testing \
--deadline=5m \
--concurrency=4 \
./...
@echo "\033[0;32mDone\033[0;0m"
.PHONY: lint-fmt # Run go fmt and see if anything would be changed
lint-fmt:
@echo "\033[0;33mRunning go fmt\033[0;0m"
ifneq ($(shell go list -f '"cd {{.Dir}}; gofmt -s -l {{join .GoFiles " "}}"' ./... | xargs sh -c), )
@go list -f '"cd {{.Dir}}; gofmt -s -l {{join .GoFiles " "}}"' ./... | xargs sh -c
@echo "\033[0;31mFAILED\033[0;0m"
@exit 1
else
@echo "\033[0;32mOK\033[0;0m"
endif
#############################################################################################################
# Build pipeline targets
.PHONY: pipeline-tools # Go get required tools
pipeline-tools:
@echo "\033[0;33mInstalling required go tools ...\033[0;0m"
@go get -u github.com/mattn/goveralls
@go get -u gopkg.in/alecthomas/gometalinter.v2
@gometalinter.v2 --install
@echo "\033[0;32mDone\033[0;0m"
.PHONY: pipeline-accept # Accept runs all targets required for PR acceptance
pipeline-accept: | lint test
.PHONY: pipeline-build # Run all relevant platform builds required for PR acceptance
pipeline-build: mac linux win freebsd
.PHONY: pipeline-coverage # Generate cover profiles files required for PR acceptance
pipeline-coverage:
@echo "\033[0;33mGenerating cover profiles\033[0;0m"
@$(GO_ENV) go test $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -covermode=count -coverprofile=core.cov ./core
@$(GO_ENV) go test $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -covermode=count -coverprofile=format.cov ./format
@$(GO_ENV) go test $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -covermode=count -coverprofile=filter.cov ./filter
@$(GO_ENV) go test $(GO_FLAGS) -tags="$(TAGS_GOLLUM)" -covermode=count -coverprofile=router.cov ./router
@echo "INFO: start generating profile.cov"
@rm -f profile.tmp profile.cov
@echo "mode: count" > profile.tmp
@for cov_file in $$( ls -f *.cov ); do cat $${cov_file} | grep -v "mode: " >> profile.tmp ; done
@mv profile.tmp profile.cov
@echo "INFO: profile.cov successfully generated"
@rm core.cov format.cov filter.cov router.cov
#############################################################################################################
.PHONY: help # Print the make help screen
help:
@echo "GOLLUM v$(GOLLUM_VERSION)"
@echo "Make targets overview"
@echo
@echo "\033[0;33mAvailable targets:"
@grep '^.PHONY: .* #' makefile | sed -E 's/\.PHONY: (.*) # (.*)/"\1" "\2"/g' | xargs printf " \033[0;32m%-25s \033[0;0m%s\n"