-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
103 lines (83 loc) · 2.35 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
# Makefile
ifeq ($(CI),)
# Not in CI
VERSION := dev-$(USER)
VERSION_HASH := $(shell git rev-parse HEAD | cut -b1-8)
else
# In CI
ifneq ($(RELEASE_VERSION),)
VERSION := $(RELEASE_VERSION)
else
# No tag, so make one
VERSION := $(shell git describe --tags 2>/dev/null)
endif
VERSION_HASH := $(shell echo "$(GITHUB_SHA)" | cut -b1-8)
endif
GO_FLAGS := -ldflags "-X main.Version=$(VERSION) -X main.VersionHash=$(VERSION_HASH)"
.PHONY: all
default: deps build test lint vet
.PHONY: coverage
coverage:
@go test -covermode=count -coverprofile="coverage.txt" ./...
@go tool cover -func="coverage.txt"
.PHONY: coveragehtml
coveragehtml: coverage
@go tool cover -html=coverage.txt -o coverage.html
.PHONY: deps
deps:
@go get -t -d ./...
.PHONY: gosec
gosec:
@gosec ./...
.PHONY: mocks
mocks:
@find -name '*_mock.go' -print0 | xargs -0r rm
@go generate ./...
.PHONY: build
build:
@mkdir -p build
@go build $(GO_FLAGS) -o build/liqbot ./cmd/liqbot
.PHONY: install
install:
@go install $(GO_FLAGS) ./cmd/liqbot
.PHONY: release-ubuntu-latest
release-ubuntu-latest:
@mkdir -p build
@env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -v -o build/liqbot-linux-amd64 $(GO_FLAGS) ./cmd/liqbot
@cd build && zip liqbot-linux-amd64.zip liqbot-linux-amd64
.PHONY: release-macos-latest
release-macos-latest:
@mkdir -p build
@env GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -v -o build/liqbot-darwin-amd64 $(GO_FLAGS) ./cmd/liqbot
@cd build && zip liqbot-darwin-amd64.zip liqbot-darwin-amd64
.PHONY: release-windows-latest
release-windows-latest:
@env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build -v -o build/liqbot-amd64.exe $(GO_FLAGS) ./cmd/liqbot
@cd build && 7z a -tzip liqbot-windows-amd64.zip liqbot-amd64.exe
.PHONY: lint
lint:
@go install golang.org/x/lint/golint
@outputfile="$$(mktemp)" ; \
go list ./... | xargs golint 2>&1 | \
sed -e "s#^$$GOPATH/src/##" | tee "$$outputfile" ; \
lines="$$(wc -l <"$$outputfile")" ; \
rm -f "$$outputfile" ; \
exit "$$lines"
.PHONY: race
race: ## Run data race detector
@env CGO_ENABLED=1 go test -race ./...
.PHONY: retest
retest: ## Force re-run of all tests
@go test -count=1 ./...
.PHONY: staticcheck
staticcheck: ## Run statick analysis checks
@staticcheck ./...
.PHONY: test
test: ## Run tests
@go test ./...
.PHONY: vet
vet: deps
@go vet ./...
.PHONY: clean
clean:
@rm -rf ./build ./cmd/liqbot/liqbot