This repository has been archived by the owner on Sep 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (44 loc) · 1.51 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
SHELL := /bin/bash
GO_PROJECT := github.com/djeeno/utils-go
REPOSITORY_ROOT := ~/go/src/${GO_PROJECT}
VERSION := v0.3.1
REVISION := $(shell git rev-parse HEAD)
BUILD_DATE := $(shell TZ=UTC date +%Y%m%d%H%M%S)
GO_VERSION := $(shell go version)
BUILD_OPTS := -ldflags '-X "main.version=${VERSION}" -X "main.hash=${REVISION}" -X "main.builddate=${BUILD_DATE}" -X "main.goversion=${GO_VERSION}"'
OPEN_CMD := $(shell if command -v explorer.exe; then true; elif command -v open; then true; else echo echo; fi)
##
# targets
##
.PHONY: help
.DEFAULT_GOAL := help
help: ## display help docs
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}'
init: ## init
if ! command -v golangci-lint 1>/dev/null; then\
go install github.com/golangci/golangci-lint/cmd/golangci-lint;\
fi
lint: init ## run lint
# go fmt
go fmt ./...
# run lint
golangci-lint run
test: lint ## run test
# run test
go test -race -covermode=atomic ./...
test-v: lint ## run test
# run test
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
go tool cover -html=coverage.txt -o coverage.html
${OPEN_CMD} coverage.html
check-uncommitted:
@if [ "`git diff; git diff --staged`" != "" ]; then\
echo "Uncommitted changes. Execute the following command:";\
echo "git commit -m 'release ${VERSION}'";\
false;\
fi
release: test check-uncommitted ## release as ${VERSION}
# release ${VERSION}
git tag -a "${VERSION}" -m "release ${VERSION}"
git push
git push --tags