1515
1616SHELL =/bin/bash -o pipefail
1717
18- # The binary to build (just the basename).
18+ GO_PKG := github.com/appscode
19+ REPO := $(notdir $(shell pwd) )
1920BIN := osm
2021COMPRESS ?= no
2122
4647# ## These variables should not need tweaking.
4748# ##
4849
49- SRC_DIRS := cmds context *.go # directories which hold app source (not vendored)
50+ SRC_PKGS := cmds context
51+ SRC_DIRS := $(SRC_PKGS ) *.go hack/gendocs # directories which hold app source (not vendored)
5052
5153DOCKER_PLATFORMS := linux/amd64 linux/arm linux/arm64
5254BIN_PLATFORMS := $(DOCKER_PLATFORMS ) windows/amd64 darwin/amd64
@@ -68,9 +70,10 @@ TAG_DBG := $(VERSION)-dbg_$(OS)_$(ARCH)
6870GO_VERSION ?= 1.14
6971BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION )
7072
71- OUTBIN = bin/$(OS ) _ $( ARCH ) / $( BIN )
73+ OUTBIN = bin/$(BIN ) - $( OS ) - $( ARCH )
7274ifeq ($(OS ) ,windows)
73- OUTBIN = bin/$(OS ) _$(ARCH ) /$(BIN ) .exe
75+ OUTBIN := bin/$(BIN ) -$(OS ) -$(ARCH ) .exe
76+ BIN := $(BIN ) .exe
7477endif
7578
7679# Directories that we need created to build/test.
@@ -81,6 +84,8 @@ BUILD_DIRS := bin/$(OS)_$(ARCH) \
8184DOCKERFILE_PROD = hack/docker/Dockerfile.in
8285DOCKERFILE_DBG = hack/docker/Dockerfile.dbg
8386
87+ DOCKER_REPO_ROOT := /go/src/$(GO_PKG ) /$(REPO )
88+
8489# If you want to build all binaries, see the 'all-build' rule.
8590# If you want to build all containers, see the 'all-container' rule.
8691# If you want to build AND push all containers, see the 'all-push' rule.
@@ -114,13 +119,14 @@ all-container: $(addprefix container-, $(subst /,_, $(DOCKER_PLATFORMS)))
114119all-push : $(addprefix push-, $(subst /,_, $(DOCKER_PLATFORMS ) ) )
115120
116121version :
117- @echo version=$(VERSION )
118- @echo version_strategy=$(version_strategy )
119- @echo git_tag=$(git_tag )
120- @echo git_branch=$(git_branch )
121- @echo commit_hash=$(commit_hash )
122- @echo commit_timestamp=$(commit_timestamp )
123-
122+ @echo ::set-output name=version::$(VERSION )
123+ @echo ::set-output name=version_strategy::$(version_strategy )
124+ @echo ::set-output name=git_tag::$(git_tag )
125+ @echo ::set-output name=git_branch::$(git_branch )
126+ @echo ::set-output name=commit_hash::$(commit_hash )
127+ @echo ::set-output name=commit_timestamp::$(commit_timestamp )
128+
129+ .PHONY : gen
124130gen :
125131 @true
126132
@@ -137,7 +143,10 @@ fmt: $(BUILD_DIRS)
137143 --env HTTP_PROXY=$(HTTP_PROXY ) \
138144 --env HTTPS_PROXY=$(HTTPS_PROXY ) \
139145 $(BUILD_IMAGE ) \
140- ./hack/fmt.sh $(SRC_DIRS )
146+ /bin/bash -c " \
147+ REPO_PKG=$(GO_PKG ) \
148+ ./hack/fmt.sh $(SRC_DIRS ) \
149+ "
141150
142151build : $(OUTBIN )
143152
@@ -189,27 +198,27 @@ $(OUTBIN): .go/$(OUTBIN).stamp
189198 --env HTTP_PROXY=$(HTTP_PROXY ) \
190199 --env HTTPS_PROXY=$(HTTPS_PROXY ) \
191200 $(BUILD_IMAGE ) \
192- upx --brute /go/$( OUTBIN ) ; \
201+ upx --brute /go/bin/ $( BIN ) ; \
193202 fi
194- @if ! cmp -s .go/$( OUTBIN ) $(OUTBIN ) ; then \
195- mv .go/$( OUTBIN ) $(OUTBIN ) ; \
196- date > $@ ; \
203+ @if ! cmp -s .go/bin/ $( OS ) _ $( ARCH ) / $( BIN ) $(OUTBIN ) ; then \
204+ mv .go/bin/ $( OS ) _ $( ARCH ) / $( BIN ) $(OUTBIN ) ; \
205+ date > $@ ; \
197206 fi
198207 @echo
199208
200209# Used to track state in hidden files.
201210DOTFILE_IMAGE = $(subst /,_,$(IMAGE ) ) -$(TAG )
202211
203212container : bin/.container-$(DOTFILE_IMAGE ) -PROD bin/.container-$(DOTFILE_IMAGE ) -DBG
204- bin/.container-$(DOTFILE_IMAGE ) -% : bin/ $( OS ) _ $( ARCH ) / $( BIN ) $(DOCKERFILE_% )
213+ bin/.container-$(DOTFILE_IMAGE ) -% : $( OUTBIN ) $(DOCKERFILE_% )
205214 @echo " container: $( IMAGE) :$( TAG_$* ) "
206215 @sed \
207- -e ' s|{ARG_BIN}|$(BIN)|g' \
208- -e ' s|{ARG_ARCH}|$(ARCH)|g' \
209- -e ' s|{ARG_OS}|$(OS)|g' \
210- -e ' s|{ARG_FROM}|$(BASEIMAGE_$*)|g' \
211- $(DOCKERFILE_$* ) > bin/.dockerfile-$* -$(OS ) _$(ARCH )
212- @docker build --pull -t $(IMAGE ) :$(TAG_$* ) -f bin/.dockerfile-$* -$(OS ) _$(ARCH ) .
216+ -e ' s|{ARG_BIN}|$(BIN)|g' \
217+ -e ' s|{ARG_ARCH}|$(ARCH)|g' \
218+ -e ' s|{ARG_OS}|$(OS)|g' \
219+ -e ' s|{ARG_FROM}|$(BASEIMAGE_$*)|g' \
220+ $(DOCKERFILE_$* ) > bin/.dockerfile-$* -$(OS ) _$(ARCH )
221+ @DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform $( OS ) / $( ARCH ) --load --pull -t $(IMAGE ) :$(TAG_$* ) -f bin/.dockerfile-$* -$(OS ) _$(ARCH ) .
213222 @docker images -q $(IMAGE ) :$(TAG_$* ) > $@
214223 @echo
215224
@@ -225,7 +234,10 @@ docker-manifest-%:
225234 DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a $(IMAGE ) :$(VERSION_$* ) $(foreach PLATFORM,$(DOCKER_PLATFORMS ) ,$(IMAGE ) :$(VERSION_$* ) _$(subst /,_,$(PLATFORM ) ) )
226235 DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(IMAGE ) :$(VERSION_$* )
227236
228- test : $(BUILD_DIRS )
237+ .PHONY : test
238+ test : unit-tests e2e-tests
239+
240+ unit-tests : $(BUILD_DIRS )
229241 @docker run \
230242 -i \
231243 --rm \
@@ -237,12 +249,12 @@ test: $(BUILD_DIRS)
237249 -v $$(pwd ) /.go/cache:/.cache \
238250 --env HTTP_PROXY=$(HTTP_PROXY ) \
239251 --env HTTPS_PROXY=$(HTTPS_PROXY ) \
240- $(BUILD_IMAGE ) \
252+ $(BUILD_IMAGE ) \
241253 /bin/bash -c " \
242254 ARCH=$(ARCH ) \
243255 OS=$(OS ) \
244256 VERSION=$(VERSION ) \
245- ./hack/test.sh $(SRC_DIRS ) \
257+ ./hack/test.sh $(SRC_PKGS ) \
246258 "
247259
248260ADDTL_LINTERS := goconst,gofmt,goimports,unparam
@@ -264,16 +276,59 @@ lint: $(BUILD_DIRS)
264276 --env GO111MODULE=on \
265277 --env GOFLAGS=" -mod=vendor" \
266278 $(BUILD_IMAGE ) \
267- golangci-lint run --enable $(ADDTL_LINTERS )
279+ golangci-lint run --enable $(ADDTL_LINTERS ) --deadline=10m --skip-files= " generated.*\.go$ \" --skip-dirs-use-default --skip-dirs=client,vendor
268280
269281$(BUILD_DIRS ) :
270282 @mkdir -p $@
271283
272284.PHONY : dev
273285dev : gen fmt push
274286
287+ .PHONY : verify
288+ verify : verify-modules verify-gen
289+
290+ .PHONY : verify-modules
291+ verify-modules :
292+ GO111MODULE=on go mod tidy
293+ GO111MODULE=on go mod vendor
294+ @if ! (git diff --exit-code HEAD); then \
295+ echo " go module files are out of date" ; exit 1; \
296+ fi
297+
298+ .PHONY : verify-gen
299+ verify-gen : gen fmt
300+ @if ! (git diff --exit-code HEAD); then \
301+ echo " files are out of date, run make gen fmt" ; exit 1; \
302+ fi
303+
304+ .PHONY : add-license
305+ add-license :
306+ @echo " Adding license header"
307+ @docker run --rm \
308+ -u $$(id -u ) :$$(id -g ) \
309+ -v /tmp:/.cache \
310+ -v $$(pwd ) :$(DOCKER_REPO_ROOT ) \
311+ -w $(DOCKER_REPO_ROOT ) \
312+ --env HTTP_PROXY=$(HTTP_PROXY ) \
313+ --env HTTPS_PROXY=$(HTTPS_PROXY ) \
314+ $(BUILD_IMAGE ) \
315+ ltag -t " ./hack/license" --excludes " vendor contrib" -v
316+
317+ .PHONY : check-license
318+ check-license :
319+ @echo " Checking files for license header"
320+ @docker run --rm \
321+ -u $$(id -u ) :$$(id -g ) \
322+ -v /tmp:/.cache \
323+ -v $$(pwd ) :$(DOCKER_REPO_ROOT ) \
324+ -w $(DOCKER_REPO_ROOT ) \
325+ --env HTTP_PROXY=$(HTTP_PROXY ) \
326+ --env HTTPS_PROXY=$(HTTPS_PROXY ) \
327+ $(BUILD_IMAGE ) \
328+ ltag -t " ./hack/license" --excludes " vendor contrib" --check -v
329+
275330.PHONY : ci
276- ci : lint test build # cover
331+ ci : verify check-license lint build unit-tests # cover
277332
278333.PHONY : qa
279334qa :
0 commit comments