-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
51 lines (41 loc) · 1.86 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
# Ref: https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications
BUILD_FLAGS=-X 'main.GitCommitHash=`git rev-parse --short HEAD`' -X 'main.BuiltAt=`date +%FT%T%z`'
BUILD_WIN=@env GOOS=windows GOARCH=amd64 go build -o probr.exe
BUILD_LINUX=@env GOOS=linux GOARCH=amd64 go build -o probr
BUILD_MAC=@env GOOS=darwin GOARCH=amd64 go build -o probr-darwin
binary: go-tidy go-test go-build
quick: go-build
testcov: go-test go-test-cov
release: go-tidy go-test release-nix release-win release-mac
go-build:
@echo " > Building binary ..."
go build -o probr -ldflags="$(BUILD_FLAGS)"
go-test:
@echo " > Validating code ..."
@golint ./...
@go vet ./...
@go test ./...
go-tidy:
@echo " > Tidying go.mod ..."
@go mod tidy
go-test-cov:
@echo "Running tests and generating coverage output ..."
@go test ./... -coverprofile coverage.out -covermode count
@sleep 2 # Sleeping to allow for coverage.out file to get generated
@echo "Current test coverage : $(shell go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+') %"
release-candidate: go-tidy go-test
@echo " > Building release candidate for Linux..."
$(BUILD_LINUX) -ldflags="$(BUILD_FLAGS) -X 'main.VersionPostfix=nix-rc'"
@echo " > Building release candidate for Windows..."
$(BUILD_WIN) -ldflags="$(BUILD_FLAGS) -X 'main.VersionPostfix=win-rc'"
@echo " > Building release for Darwin..."
$(BUILD_MAC) -ldflags="$(BUILD_FLAGS) -X 'main.VersionPostfix=darwin'"
release-nix:
@echo " > Building release for Linux..."
$(BUILD_LINUX) -ldflags="$(BUILD_FLAGS) -X 'main.VersionPostfix=linux'"
release-win:
@echo " > Building release for Windows..."
$(BUILD_WIN) -ldflags="$(BUILD_FLAGS) -X 'main.VersionPostfix=windows'"
release-mac:
@echo " > Building release for Darwin..."
$(BUILD_MAC) -ldflags="$(BUILD_FLAGS) -X 'main.VersionPostfix=darwin'"