-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
74 lines (53 loc) · 1.9 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
SHELL := $(shell which bash)
CONTAINER_USER ?= kwatchman
VERSION ?= master
BUILD_DATE = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
COMMIT = $(shell git rev-parse --short HEAD)
STABLE_VERSION_REGEX := ^v([0-9]{1,}\.){2}[0-9]{1,}$$
REPOSITORY = github.com/snebel29/kwatchman
PKG = ${REPOSITORY}/internal/pkg
COVERAGE_FILE=/tmp/coverage.out
LD_FLAGS = "-X ${PKG}/version.Version=$(VERSION) \
-X ${PKG}/version.BuildDate=$(BUILD_DATE) \
-X ${PKG}/version.Commit=$(COMMIT) \
-w -extldflags -static"
# To ensure that all built code and potentially non tested is covered by the race detector
report-race-conditions:
go build -race cmd/*.go
build:
CGO_ENABLED=0 go build -ldflags $(LD_FLAGS) cmd/*.go
test:
go test -race ./... -coverprofile=coverage.txt -covermode=atomic
test-coverage-report:
go test ./... -coverprofile=$(COVERAGE_FILE)
go tool cover -html=$(COVERAGE_FILE)
file: {{ coverage_report_filepath }}
clean:
go clean
deps:
dep ensure -v
docker-image:
docker build -f build/Dockerfile \
--build-arg VERSION=$(VERSION) \
--build-arg REPOSITORY=$(REPOSITORY) \
--build-arg PKG=$(PKG) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg COMMIT=$(COMMIT) \
--build-arg CONTAINER_USER=$(CONTAINER_USER) \
-t snebel29/kwatchman:$(VERSION) .
ifeq ($(shell echo $(VERSION) | egrep "$(STABLE_VERSION_REGEX)"),)
@echo "Version $(VERSION) is not stable"
else
@echo "Version $(VERSION) is stable therefore tag latest"
docker tag snebel29/kwatchman:$(VERSION) snebel29/kwatchman:latest
endif
docker image prune -f
push-docker-image:
ifeq ($(shell echo $(VERSION) | egrep "$(STABLE_VERSION_REGEX)"),)
@echo "Version $(VERSION) is not stable"
else
@echo "Version $(VERSION) is stable therefore push latest tag"
docker push snebel29/kwatchman:latest
endif
docker push snebel29/kwatchman:$(VERSION)
.PHONY: build test clean docker-image publish-docker-image test-coverage-report