github.com/greenpau/go-identity@v1.1.6/Makefile (about) 1 .PHONY: test ctest covdir coverage docs linter qtest clean dep release logo license envvar 2 APP_VERSION:=$(shell cat VERSION | head -1) 3 GIT_COMMIT:=$(shell git describe --dirty --always) 4 GIT_BRANCH:=$(shell git rev-parse --abbrev-ref HEAD -- | head -1) 5 BUILD_USER:=$(shell whoami) 6 BUILD_DATE:=$(shell date +"%Y-%m-%d") 7 BINARY:="identity" 8 VERBOSE:=-v 9 ifdef TEST 10 TEST:="-run ${TEST}" 11 endif 12 13 all: envvar build 14 @echo "$@: complete" 15 16 envvar: 17 @echo "Version: $(APP_VERSION), Branch: $(GIT_BRANCH), Revision: $(GIT_COMMIT)" 18 @echo "Build on $(BUILD_DATE) by $(BUILD_USER)" 19 20 build: 21 @mkdir -p bin/ 22 @rm -rf ./bin/* 23 @CGO_ENABLED=0 go build -o ./bin/authdbctl $(VERBOSE) \ 24 -ldflags="-w -s \ 25 -X main.appVersion=$(APP_VERSION) \ 26 -X main.gitBranch=$(GIT_BRANCH) \ 27 -X main.gitCommit=$(GIT_COMMIT) \ 28 -X main.buildUser=$(BUILD_USER) \ 29 -X main.buildDate=$(BUILD_DATE)" \ 30 -gcflags="all=-trimpath=$(GOPATH)/src" \ 31 -asmflags="all=-trimpath $(GOPATH)/src" \ 32 cmd/authdbctl/*.go 33 @./bin/authdbctl --version 34 @./bin/authdbctl --help 35 @echo "$@: complete" 36 37 linter: 38 @echo "Running lint checks" 39 @golint -set_exit_status ./... 40 @echo "$@: complete" 41 42 gtest: 43 @go test $(VERBOSE) -coverprofile=.coverage/coverage.out ./*.go 44 @echo "$@: complete" 45 46 test: envvar covdir linter gtest coverage 47 @echo "$@: complete" 48 49 ctest: covdir linter 50 @richgo version || go get -u github.com/kyoh86/richgo 51 @time richgo test $(VERBOSE) $(TEST) -coverprofile=.coverage/coverage.out ./... 52 @echo "$@: complete" 53 54 covdir: 55 @echo "Creating .coverage/ directory" 56 @mkdir -p .coverage 57 @echo "$@: complete" 58 59 coverage: 60 @#go tool cover -help 61 @go tool cover -html=.coverage/coverage.out -o .coverage/coverage.html 62 @go test -covermode=count -coverprofile=.coverage/coverage.out ./... 63 @go tool cover -func=.coverage/coverage.out | grep -v "100.0" 64 @echo "$@: complete" 65 66 docs: 67 @mkdir -p .doc 68 @go doc -all > .doc/index.txt 69 @cat .doc/index.txt 70 @echo "$@: complete" 71 72 clean: 73 @rm -rf .doc 74 @rm -rf .coverage 75 @rm -rf bin/ 76 @echo "$@: complete" 77 78 qtest: 79 @echo "Perform quick tests ..." 80 @#go test -v -run TestVersioned *.go 81 @#go test -v -run TestNewID *.go 82 @#time richgo test -v -run TestNewPublicKey *.go 83 @#time richgo test -v -run TestNewUser *.go 84 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewPublicKey *.go 85 @time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewAPIKey *.go 86 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewCode pkg/qr/*.go 87 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestDatabaseAuthentication *.go 88 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewMfaToken *.go 89 @#time richgo test -v -coverprofile=.coverage/coverage.out internal/tag/*.go 90 @#time richgo test -v -coverprofile=.coverage/coverage.out -run "Test.*Database.*" *.go 91 @#time richgo test -v -coverprofile=.coverage/coverage.out -run "TestDatabaseGetUsers" *.go 92 @#time richgo test -v -coverprofile=.coverage/coverage.out internal/tag/*.go 93 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewEmailAddress *.go 94 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewRole *.go 95 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewPassword *.go 96 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestNewName *.go 97 @#time richgo test -v -coverprofile=.coverage/coverage.out -run TestDatabasePolicy *.go 98 @go tool cover -html=.coverage/coverage.out -o .coverage/coverage.html 99 @#go tool cover -func=.coverage/coverage.out | grep -v "100.0" 100 @go tool cover -func=.coverage/coverage.out | grep api_key 101 @echo "$@: complete" 102 103 104 dep: 105 @echo "Making dependencies check ..." 106 @golint || go get -u golang.org/x/lint/golint 107 @go get -u github.com/kyoh86/richgo 108 @versioned || go get -u github.com/greenpau/versioned/cmd/versioned 109 @echo "$@: complete" 110 111 license: 112 @versioned || go get -u github.com/greenpau/versioned/cmd/versioned 113 @for f in `find ./ -type f -name '*.go'`; do versioned -addlicense -copyright="Paul Greenberg greenpau@outlook.com" -year=2020 -filepath=$$f; done 114 @echo "$@: complete" 115 116 release: 117 @echo "Making release" 118 @go mod tidy 119 @go mod verify 120 @if [ $(GIT_BRANCH) != "main" ]; then echo "cannot release to non-main branch $(GIT_BRANCH)" && false; fi 121 @git diff-index --quiet HEAD -- || ( echo "git directory is dirty, commit changes first" && false ) 122 @versioned -patch 123 @echo "Patched version" 124 @git add VERSION 125 @git commit -m 'updated VERSION file' 126 @versioned -sync database.go 127 @git add database.go 128 @git commit -m "released v`cat VERSION | head -1`" 129 @git tag -a v`cat VERSION | head -1` -m "v`cat VERSION | head -1`" 130 @git push 131 @git push --tags 132 @#echo "git push --delete origin v$(APP_VERSION)" 133 @#echo "git tag --delete v$(APP_VERSION)" 134 135 logo: 136 @mkdir -p assets/docs/images/ 137 @gm convert -background black -font Bookman-Demi \ 138 -size 640x320 "xc:black" \ 139 -draw "fill white gravity center text 0,0 'Go\nidentity'" \ 140 -pointsize 96 \ 141 assets/docs/images/logo.png 142 @echo "$@: complete"