-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
61 lines (48 loc) · 1.4 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
VERSION ?= $(shell git rev-parse --short HEAD)
SERVICE = shipspotter
CGO_ENABLED ?= 0
GO = CGO_ENABLED=$(CGO_ENABLED) go
GO_BUILD_FLAGS = -ldflags "-X main.version=${VERSION}"
# Utility functions
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = $(if $(value $1),, \
$(error undefined '$1' variable: $2))
# Pattern #1 example: "example : description = Description for example target"
# Pattern #2 example: "### Example separator text
help: HELP_SCRIPT = \
if (/^([a-zA-Z0-9-\.\/]+).*?: description\s*=\s*(.+)/) { \
printf "\033[34m%-40s\033[0m %s\n", $$1, $$2 \
} elsif(/^\#\#\#\s*(.+)/) { \
printf "\033[33m>> %s\033[0m\n", $$1 \
}
.PHONY: help
help:
@perl -ne '$(HELP_SCRIPT)' $(MAKEFILE_LIST)
### Dev
.PHONY: run
run: description = Run $(SERVICE)
run:
$(GO) run `ls -1 *.go | grep -v _test.go` -d
### Build
.PHONY: build
build: description = Build $(SERVICE)
build: clean
$(GO) build $(GO_BUILD_FLAGS) -o ./build/$(SERVICE)
.PHONY: release
release: #: Build and upload the release to GitHub
goreleaser --rm-dist
.PHONY: clean
clean: description = Remove existing build artifacts
clean:
$(RM) ./build/$(SERVICE)*
### Test
.PHONY: test
test: description = Run Go unit tests
test: GOFLAGS=
test:
$(GO) test ./...
.PHONY: cover
cover: #: Open coverage report in a browser
go test -coverprofile=coverage.out && go tool cover -html=coverage.out