68
68
ifdef GOPKG
69
69
GO ?= go
70
70
GOPATH ?= $(HOME ) /go
71
- GOLIBS ?= $(shell find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]* $$@ @' | sort | uniq)
72
71
GO_INSTALL_OPTS ?=
73
72
GO_TEST_OPTS ?= -test.timeout=30s
73
+ GOMOD_DIR ?= .
74
74
75
75
ifdef GOBINS
76
76
.PHONY : go.install
@@ -89,12 +89,10 @@ go.release:
89
89
RELEASE_STEPS += go.release
90
90
endif
91
91
92
- .PHONY : go.unittest coverage.txt
93
- go.unittest : coverage.txt
94
- coverage.txt :
95
- @rm -f /tmp/coverage.txt
96
- @touch /tmp/coverage.txt
97
- @set -e; for dir in $( GOLIBS) ; do ( set -xe; \
92
+ .PHONY : go.unittest
93
+ go.unittest :
94
+ echo " " > /tmp/coverage.txt
95
+ @set -e; for dir in ` find $( GOMOD_DIR) -type f -name " go.mod" | grep -v /vendor/ | sed ' s@/[^/]*$$@@' | sort | uniq` ; do ( set -xe; \
98
96
cd $$ dir; \
99
97
$(GO ) test $(GO_TEST_OPTS ) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \
100
98
if [ -f /tmp/profile.out ]; then \
@@ -103,44 +101,40 @@ coverage.txt:
103
101
fi); done
104
102
mv /tmp/coverage.txt .
105
103
106
- .PHONY : go.coverfunc
107
- go.coverfunc : coverage.txt
108
- go tool cover -func=./coverage.txt | grep -v .pb.go: | grep -v .pb.gw.go:
109
-
110
104
.PHONY : go.lint
111
105
go.lint :
112
- @set -e; for dir in $( GOLIBS ) ; do ( set -xe; \
106
+ @set -e; for dir in ` find $( GOMOD_DIR ) -type f -name " go.mod " | grep -v /vendor/ | sed ' s@/[^/]*$$@@ ' | sort | uniq ` ; do ( set -xe; \
113
107
cd $$ dir; \
114
108
golangci-lint run --verbose ./...; \
115
109
); done
116
110
117
111
.PHONY : go.tidy
118
112
go.tidy :
119
- @set -e; for dir in $( GOLIBS ) ; do ( set -xe; \
113
+ @set -e; for dir in ` find $( GOMOD_DIR ) -type f -name " go.mod " | grep -v /vendor/ | sed ' s@/[^/]*$$@@ ' | sort | uniq ` ; do ( set -xe; \
120
114
cd $$ dir; \
121
115
$(GO ) mod tidy; \
122
116
); done
123
117
124
118
.PHONY : go.build
125
119
go.build :
126
- @set -e; for dir in $( GOLIBS ) ; do ( set -xe; \
120
+ @set -e; for dir in ` find $( GOMOD_DIR ) -type f -name " go.mod " | grep -v /vendor/ | sed ' s@/[^/]*$$@@ ' | sort | uniq ` ; do ( set -xe; \
127
121
cd $$ dir; \
128
122
$(GO ) build ./...; \
129
123
); done
130
124
131
125
.PHONY : go.bump-deps
132
126
go.bumpdeps :
133
- @set -e; for dir in $( GOLIBS ) ; do ( set -xe; \
127
+ @set -e; for dir in ` find $( GOMOD_DIR ) -type f -name " go.mod " | grep -v /vendor/ | sed ' s@/[^/]*$$@@ ' | sort | uniq ` ; do ( set -xe; \
134
128
cd $$ dir; \
135
129
$(GO ) get -u ./...; \
136
130
); done
137
131
138
132
.PHONY : go.bump-deps
139
133
go.fmt :
140
134
if ! command -v goimports & > /dev/null; then GO111MODULE=off go get golang.org/x/tools/cmd/goimports; fi
141
- @set -e; for dir in $( GOLIBS ) ; do ( set -xe; \
135
+ @set -e; for dir in ` find $( GOMOD_DIR ) -type f -name " go.mod " | grep -v /vendor/ | sed ' s@/[^/]*$$@@ ' | sort | uniq ` ; do ( set -xe; \
142
136
cd $$ dir; \
143
- goimports -w . \
137
+ goimports -w ` go list -f ' {{.Dir}} ' ./...) ` \
144
138
); done
145
139
146
140
BUILD_STEPS += go.build
@@ -177,6 +171,9 @@ endif
177
171
# # Docker
178
172
# #
179
173
174
+ ifndef DOCKERFILE_PATH
175
+ DOCKERFILE_PATH = ./Dockerfile
176
+ endif
180
177
ifndef DOCKER_IMAGE
181
178
ifneq ($(wildcard Dockerfile) ,)
182
179
DOCKER_IMAGE = $(notdir $(PWD ) )
@@ -190,7 +187,7 @@ docker.build:
190
187
--build-arg VCS_REF=` git rev-parse --short HEAD` \
191
188
--build-arg BUILD_DATE=` date -u +" %Y-%m-%dT%H:%M:%SZ" ` \
192
189
--build-arg VERSION=` git describe --tags --always` \
193
- -t $(DOCKER_IMAGE ) .
190
+ -t $(DOCKER_IMAGE ) -f $( DOCKERFILE_PATH ) $( dir $( DOCKERFILE_PATH ) )
194
191
195
192
BUILD_STEPS += docker.build
196
193
endif
0 commit comments