-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
89 lines (70 loc) · 2.13 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
VERSION=1.0
#tools
GO=go
OUTPUT=dist/service
BUILDTIME=`date +%FT%T%Z`
#grab build infos
GITVERSION :=$(if $(and $(wildcard .git),$(shell which git)),$(shell git describe --tags --abbrev=0))
GITHASH :=$(if $(and $(wildcard .git),$(shell which git)),$(shell git rev-parse HEAD))
#application configuration
COMPILEFLAGS=-ldflags " \
-X github.com/restSampleServices/go-service/BuildInfo.BuildTime=$(BUILDTIME) \
-X github.com/restSampleServices/go-service/BuildInfo.Version=$(GITVERSION) \
-X github.com/restSampleServices/go-service/BuildInfo.Commit=$(GITHASH) \
-X main.test=$(GITHASH) \
"
PKGS=$(go list ./... | grep -v /vendor/)
go-version:
@$(GO) version
@echo "make devenv|run|build|clean|test"
ensureBuildinfo:
ifdef GITHASH
else
@echo "Git not installed or not in a git repository"
#we can reference a environment variable from build pipeline here
$(eval GITHASH=n.a.)
endif
ifdef GITVERSION
else
@echo "Git not installed or not in a git repository or no Tag found"
$(eval GITVERSION=0.0.0)
endif
#used for debugging and in case of errors
versioninfo: ensureBuildinfo
@echo Commit $(GITHASH)
@echo Git based Version $(GITVERSION)
@echo Make based Version $(VERSION)
@echo Build time $(BUILDTIME)
prerequisites:
@echo "install prerequisites ..."
@$(GO) get -u github.com/golang/mock/gomock
@$(GO) get -u github.com/golang/mock/mockgen
@$(GO) get -u github.com/golang/dep/cmd/dep
@$(GO) get -u github.com/golang/lint/golint
dependencies:
@echo "install dependencies..."
@dep ensure
clean:
@echo "clean ..."
@$go clean
@if [ -d mocks ] ; then rm -rf mocks; fi
@if [ -d build ] ; then rm -rf build fi
@if [ -d vendor ] ; then rm -rf vendor; fi
test-mockgen:
@echo "generating mocks ..."
@if [ ! -d mocks ] ; then mkdir -p mocks; fi
@go generate ./...
build: ensureBuildinfo
@echo "start building ..."
@go build -v $(COMPILEFLAGS) -o $(OUTPUT)
run: ensureBuildinfo
@echo "start application ..."
@go run $(COMPILEFLAGS) restSampleService.go
test:
@echo "test ..."
@$(GO) test -cover ./...
checkstyle:
@echo "stylecheck ..."
@golint ./...
devenv: prerequisites dependencies test-mockgen
ci: devenv test checkstyle build