forked from bramp/myip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
114 lines (85 loc) · 3.43 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Helpful Makefile for dealing with vendoring Go adapted from from:
# http://www.compoundtheory.com/configuring-your-gopath-with-go-and-google-app-engine/
#
.PHONY: default install-tools check-update debug-env check imports fmt vet lint clean veryclean test deps serve deploy version
default: test
#Fixes a bug in OSX Make with exporting PATH environment variables
#See: http://stackoverflow.com/questions/11745634/setting-path-variable-from-inside-makefile-does-not-work-for-make-3-81
export SHELL := $(shell echo $$SHELL)
#get the path to this Makefile, its the last in this list
#MAKEFILE_LIST is the list of Makefiles that are executed.
TOP := $(dir $(lastword $(MAKEFILE_LIST)))
ROOT = $(realpath $(TOP))
GOPATH := $(ROOT)/vendor:$(ROOT)
export GOPATH
#Add our vendored GOPATH bin directory to the path as well
PATH := $(ROOT)/vendor/bin:$(PATH)
export PATH
APP_YAML = src/appengine/app.yaml
NODE_MODULES := $(ROOT)/node_modules/.bin
# Prints out all the GO environment variables. Useful to see the state
# of what is going on with the GOPATH
debug-env:
printenv | grep 'GO'
# Only update node_modules if the package.json has changed.
node_modules: package.json
npm install
touch $@
install-tools: node_modules
go get -u github.com/golang/lint/golint
go get -u golang.org/x/tools/cmd/goimports
go get -u github.com/mattn/goveralls
# We don't need the source for the tools
#rm -rf $(ROOT)/vendor/src/golang.org/lint/golint
#rm -rf $(ROOT)/vendor/src/github.com/golang/x/tools/cmd/goimports
check-updates: install-tools
$(NODE_MODULES)/ncu -m npm
cd src/appengine; $(NODE_MODULES)/ncu -m bower
# TODO Write goapp get -u script
deps: node_modules
cd src/appengine; $(NODE_MODULES)/bower install
for pkg in github.com/miekg/dns github.com/domainr/whois \
github.com/gorilla/handlers github.com/gorilla/mux github.com/gorilla/context \
github.com/golang/protobuf/proto google.golang.org/appengine/socket \
github.com/ua-parser/uap-go/uaparser github.com/kylelemons/godebug/pretty; \
do \
if [ ! -d $(ROOT)/vendor/src/$$pkg ]; then \
echo Getting $$pkg; \
goapp get -u $$pkg; \
fi \
done
check: deps fmt vet lint
fmt:
goapp fmt appengine lib/...
vet:
# Due to https://github.com/golang/go/issues/17571 go vet doesn't support vendored directories.
# Disabled until that is fixed (in Go 1.9 most likely)
# go tool vet -v src
lint:
golint -set_exit_status src/...
test: check
# Testing standard go
go test lib/...
# Testing appengine go
goapp test lib/...
coverage: check
#goapp test -covermode=count -coverprofile=profile.cov lib/...
#goveralls -coverprofile=profile.cov -service=travis-ci
cd src; goveralls -service=travis-ci -debug
version: src/lib/myip/version.go
src/lib/myip/version.go: $(shell find src -type f ! -name "version.go")
# -ldflags "-X main.BuildTime `date '+%Y-%m-%d %T %Z'` -X main.Version `git rev-parse HEAD`"
sed -i "" "s/\(Version[^\"]*\"\)[^\"]*/\1`git rev-parse HEAD`/" src/lib/myip/version.go
sed -i "" "s/\(BuildTime[^\"]*\"\)[^\"]*/\1`date '+%Y-%m-%d %T %Z'`/" src/lib/myip/version.go
serve:
goapp serve $(APP_YAML)
deploy: check
# TODO get the version number from the git-hash
#@read -p "What is your Project ID?: " projectID; \
#goapp deploy -application $$projectID $(APP_YAML)
goapp deploy -application myip-158305 -version v3 $(APP_YAML)
clean:
rm -rf vendor/src
rm -rf src/appengine/static/bower_components
veryclean: clean
rm -rf node_modules