-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
92 lines (81 loc) · 2.89 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
90
91
92
.PHONY: test ctest covdir coverage docs linter qtest clean dep
APP_VERSION:=$(shell cat VERSION | head -1)
GIT_COMMIT:=$(shell git describe --dirty --always)
GIT_BRANCH:=$(shell git rev-parse --abbrev-ref HEAD -- | head -1)
BUILD_USER:=$(shell whoami)
BUILD_DATE:=$(shell date +"%Y-%m-%d")
PROJECT:="github.com/greenpau/go-ansible-db"
BINARY:="go-ansible-db-client"
VERBOSE:=-v
ifdef TEST
TEST:="-run ${TEST}"
endif
all:
@echo "Version: $(APP_VERSION), Branch: $(GIT_BRANCH), Revision: $(GIT_COMMIT)"
@echo "Build on $(BUILD_DATE) by $(BUILD_USER)"
@mkdir -p bin/
@CGO_ENABLED=0 go build -o bin/$(BINARY) $(VERBOSE) \
-ldflags="-w -s \
-X main.appName=$(BINARY) \
-X main.appVersion=$(APP_VERSION) \
-X main.gitBranch=$(GIT_BRANCH) \
-X main.gitCommit=$(GIT_COMMIT) \
-X main.buildUser=$(BUILD_USER) \
-X main.buildDate=$(BUILD_DATE)" \
-gcflags="all=-trimpath=$(GOPATH)/src" \
-asmflags="all=-trimpath $(GOPATH)/src" cmd/client/*
@echo "Done!"
linter:
@golint pkg/db/*.go
@golint cmd/client/*.go
@echo "PASS: golint"
test: covdir linter
@go test $(VERBOSE) -coverprofile=.coverage/coverage.out ./pkg/db/*.go
@bin/$(BINARY) -log.level debug -inventory ./testdata/inventory/hosts \
-vault ./testdata/inventory/vault.yml -vault.key.file ./testdata/inventory/vault.key
ctest: covdir linter
@#richgo version || go get -u github.com/kyoh86/richgo
@time richgo test $(VERBOSE) -coverprofile=.coverage/coverage.out ./pkg/db/*.go
covdir:
@mkdir -p .coverage
coverage:
@go tool cover -html=.coverage/coverage.out -o .coverage/coverage.html
docs:
@rm -rf .doc/
@mkdir -p .doc/
@godoc -html $(PROJECT)/pkg/db > .doc/index.html
@echo "Run to serve docs:"
@echo " godoc -goroot .doc/ -html -http \":8080\""
clean:
@rm -rf .doc
@rm -rf .coverage
@rm -rf bin/
qtest:
@#go test -v -run TestNewInventory ./pkg/db/*.go
@#go test -v -run TestNewVault ./pkg/db/*.go
@#go test -v -run TestGetHost ./pkg/db/*.go
@richgo test -v -run GetHostsWithFilter ./pkg/...
dep:
@echo "Making dependencies check ..."
@go install golang.org/x/lint/golint@latest
@go install github.com/kyoh86/richgo@latest
@go install github.com/greenpau/versioned/cmd/versioned@latest
@go install github.com/greenpau/gorpm/cmd/gorpm@latest
@pip3 install yamllint --user
@pip3 install yq --user
release:
@echo "Making release"
@go mod tidy
@go mod verify
@if [ $(GIT_BRANCH) != "main" ]; then echo "cannot release to non-main branch $(GIT_BRANCH)" && false; fi
@git diff-index --quiet HEAD -- || ( echo "git directory is dirty, commit changes first" && git status && false )
@versioned -patch
@echo "Patched version"
@git add VERSION
@git commit -m "released v`cat VERSION | head -1`"
@git tag -a v`cat VERSION | head -1` -m "v`cat VERSION | head -1`"
@git push
@git push --tags
@@echo "If necessary, run the following commands:"
@echo " git push --delete origin v$(APP_VERSION)"
@echo " git tag --delete v$(APP_VERSION)"