1
1
# This is the default Clever Golang Makefile.
2
2
# It is stored in the dev-handbook repo, github.com/Clever/dev-handbook
3
3
# Please do not alter this file directly.
4
- GOLANG_MK_VERSION := 1.0 .1
4
+ GOLANG_MK_VERSION := 1.2 .1
5
5
6
6
SHELL := /bin/bash
7
7
SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]')
@@ -47,6 +47,8 @@ golang-ensure-curl-installed:
47
47
# Golint is a tool for linting Golang code for common errors.
48
48
# We pin its version because an update could add a new lint check which would make
49
49
# previously passing tests start failing without changing our code.
50
+ # this package is deprecated and frozen
51
+ # Infra recomendation is to eventaully move to https://github.com/golangci/golangci-lint so don't fail on linting error for now
50
52
GOLINT := $(GOPATH ) /bin/golint
51
53
$(GOLINT ) :
52
54
go install -mod=readonly golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626
74
76
# golang-lint-deps-strict requires the golint tool for golang linting.
75
77
golang-lint-deps-strict : $(GOLINT ) $(FGT )
76
78
77
- # golang-lint-strict calls golint on all golang files in the pkg and fails if any lint
78
- # errors are found.
79
- # arg1: pkg path
80
- define golang-lint-strict
81
- @echo "LINTING $(1 ) ..."
82
- @PKG_PATH=$$(go list -f '{{.Dir}}' $(1 ) ) ; find $${PKG_PATH}/*.go -type f | grep -v gen_ | xargs $(FGT ) $(GOLINT )
83
- endef
84
-
85
79
# golang-test-deps is here for consistency
86
80
golang-test-deps :
87
81
@@ -102,6 +96,21 @@ define golang-test-strict
102
96
@go test -v -race $(1 )
103
97
endef
104
98
99
+ # golang-test-strict-cover-deps is here for consistency
100
+ golang-test-strict-cover-deps :
101
+
102
+ # golang-test-strict-cover uses the Go toolchain to run all tests in the pkg with the race and cover flag.
103
+ # appends coverage results to coverage.txt
104
+ # arg1: pkg path
105
+ define golang-test-strict-cover
106
+ @echo "TESTING $(1 ) ..."
107
+ @go test -v -race -cover -coverprofile=profile.tmp -covermode=atomic $(1 )
108
+ @if [ -f profile.tmp ]; then \
109
+ cat profile.tmp | tail -n +2 >> coverage.txt; \
110
+ rm profile.tmp; \
111
+ fi;
112
+ endef
113
+
105
114
# golang-vet-deps is here for consistency
106
115
golang-vet-deps :
107
116
@@ -132,16 +141,29 @@ golang-test-all-strict-deps: golang-fmt-deps golang-lint-deps-strict golang-test
132
141
# arg1: pkg path
133
142
define golang-test-all-strict
134
143
$(call golang-fmt,$(1 ) )
135
- $(call golang-lint-strict ,$(1 ) )
144
+ $(call golang-lint,$(1 ) )
136
145
$(call golang-vet,$(1 ) )
137
146
$(call golang-test-strict,$(1 ) )
138
147
endef
139
148
149
+ # golang-test-all-strict-cover-deps: installs all dependencies needed for different test cases.
150
+ golang-test-all-strict-cover-deps : golang-fmt-deps golang-lint-deps-strict golang-test-strict-cover-deps golang-vet-deps
151
+
152
+ # golang-test-all-strict-cover calls fmt, lint, vet and test on the specified pkg with strict and cover
153
+ # requirements that no errors are thrown while linting.
154
+ # arg1: pkg path
155
+ define golang-test-all-strict-cover
156
+ $(call golang-fmt,$(1 ) )
157
+ $(call golang-lint,$(1 ) )
158
+ $(call golang-vet,$(1 ) )
159
+ $(call golang-test-strict-cover,$(1 ) )
160
+ endef
161
+
140
162
# golang-build: builds a golang binary. ensures CGO build is done during CI. This is needed to make a binary that works with a Docker alpine image.
141
163
# arg1: pkg path
142
164
# arg2: executable name
143
165
define golang-build
144
- @echo "BUILDING..."
166
+ @echo "BUILDING $( 2 ) ..."
145
167
@if [ -z "$$CI" ]; then \
146
168
go build -o bin/$(2 ) $(1 ) ; \
147
169
else \
@@ -150,6 +172,10 @@ else \
150
172
fi;
151
173
endef
152
174
175
+ # golang-setup-coverage: set up the coverage file
176
+ golang-setup-coverage :
177
+ @echo " mode: atomic" > coverage.txt
178
+
153
179
# golang-update-makefile downloads latest version of golang.mk
154
180
golang-update-makefile :
155
181
@wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang-v1.mk -O /tmp/golang.mk 2> /dev/null
0 commit comments