11# GOLOOP
22#
33# Load data about the package:
4- # REPOSITORY_NAME
4+ # NAME
5+ # Name of the GoLang's module;
6+ # VERSION
7+ # Current version.
8+ # REPOSITORY
59# The name of the repository where the package is stored,
610# for example: github.com/goloop;
7- # MODULE_NAME
8- # Name of the GoLang's pakcage.
9- #
10- # The REPOSITORY_NAME and MODULE_NAME create a path to import the package
11- # (save the source code in GOPATH as $GOPATH/src/REPOSITORY_NAME/MODULE_NAME)
12- SRC_PATH: =$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
13- include $(SRC_PATH ) /.module
14-
15- ifndef MODULE_NAME
16- $(error Add PAKCAGE_NAME in .module)
17- endif
18-
19- ifndef REPOSITORY_NAME
20- $(error Add REPOSITORY_NAME in .module)
21- endif
22-
11+ MODULE_NAME: =$(shell cat go.mod | grep module | awk '{split($$2,v,"/") ; print v[3]}')
12+ MODULE_VERSION: =$(shell cat doc.go | grep "const version" | awk '{gsub(/"/, "", $$4) ; print $$4}')
13+ MODULE_MAJOR_VERSION: =$(shell cat doc.go | grep "const version" | awk '{gsub(/"/, "", $$4) ; print $$4}' | awk '{split($$0,r,"."); print r[1]}')
14+ REPOSITORY_NAME: =$(shell cat go.mod | grep module | awk '{split($$2,v,"/") ; print v[1] "/" v[2]}')
15+
2316# Help information.
2417define MSG_HELP
25- Go-package manager.
18+ Go-package's manager of
19+ ${MODULE_NAME} v${MODULE_VERSION}
2620
2721Commands:
2822 help
2923 Show this help information
30- go. test
24+ test
3125 Run tests
32- go.test. cover
26+ cover
3327 Check test coverage
34- go.lint
35- Check cod with GoLints
36-
37- Requires `golangci-lint`, install as:
38- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH ) /bin v1.24.0
3928 readme
4029 Create readme from the GoLang code
4130
4231 Requires `godocdown`, install as:
4332 go get github.com/robertkrimen/godocdown/godocdown
44- git.commit
45- Update readme, create commit and update tag from the .module file.
46-
47- Usage as: make git.commit am="Commit message"
33+ tag
34+ Create git-tag with current version of package
4835endef
4936
5037# Constants.
@@ -54,35 +41,19 @@ REPOSITORY_PATH=${REPOSITORY_NAME}/${MODULE_NAME}
5441all : help
5542help :
5643 @echo " $$ MSG_HELP"
57- go.test :
58- @go clean -testcache; go test ${REPOSITORY_PATH}
59- go.test.cover :
44+ test :
45+ @go clean -testcache; \
46+ go test ${REPOSITORY_PATH}
47+ cover :
6048 @go test -cover ${REPOSITORY_PATH} && \
6149 go test -coverprofile=/tmp/coverage.out ${REPOSITORY_PATH} && \
6250 go tool cover -func=/tmp/coverage.out && \
6351 go tool cover -html=/tmp/coverage.out
64- go.lint :
65- ifeq (, $(shell which golangci-lint) )
66- @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
67- endif
68- golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \
69- --disable-all --enable=deadcode --enable=gocyclo --enable=golint \
70- --enable=varcheck --enable=structcheck --enable=maligned \
71- --enable=gosec --enable=megacheck --enable=ineffassign \
72- --enable=interfacer --enable=unconvert \
73- --enable=goconst # --enable=errcheck --enable=dupl
7452readme :
7553ifeq (, $(shell which godocdown) )
7654 @go get github.com/robertkrimen/godocdown/godocdown
7755endif
7856 @godocdown -plain=true -template=.godocdown.md ./ | \
79- sed -e 's/\.VERSION/${VERSION}/g' > README.md
80- git.commit : readme
81- ifeq ($(am ) ,)
82- @echo "You must provide a message to commit as: make commit am='Commit message'"
83- else
84- @git add . && git commit -am "${am}" && \
85- git tag v${VERSION} && \
86- git push -u origin --all && \
87- git push -u origin --tag
88- endif
57+ sed -e 's/\.ModuleVersion/v${MODULE_VERSION}/g' > README.md
58+ tag :
59+ @bash -c ' read -p "Do you want to create v${MODULE_VERSION} tag [y/n]?: " yn; case $${yn} in "y") git tag "v${MODULE_VERSION}"; exit 0;; *) exit 0;; esac'
0 commit comments