-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathMakefile
60 lines (49 loc) · 1.79 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
VERSION := $(shell cat VERSION)
BUILD_DIR = .build
GO := $(GOROOT)/bin/go
ifeq (, $(GOROOT))
GO := go
endif
GOFILES_NOVENDOR := $(shell find . -type f -name '*.go' -not -path "*/vendor/*" 2>/dev/null)
GOPACKAGES := $(shell $(GO) list ./...)
GOIMPORTS_REPO := golang.org/x/tools/cmd/goimports
GOIMPORTS := $(GOPATH)/bin/goimports
DOCKER_IMAGE ?= ahutsunshine/dingdong-grapper:latest
.PHONY: fmt
fmt: ## Ensures all go files are properly formatted.
@echo "Formatting..."
@GO111MODULE=off $(GO) get -u ${GOIMPORTS_REPO}
@$(GOIMPORTS) -l -w ${GOFILES_NOVENDOR}
.PHONY: vendor
vendor: export GO111MODULE=on
vendor: export GOPRIVATE=github.corp.ebay.com
vendor: # Ensures all go module dependencies are synced and copied to vendor
@echo "Updating module dependencies..."
@$(GO) mod tidy
@$(GO) mod vendor
.PHONY: check
check: ## Performs code hygiene checks and runs tests.
@echo "Checking for suspicious constructs..."
@$(GO) vet ${GOPACKAGES}
@echo "Checking formatting..."
@GO111MODULE=off $(GO) get -u ${GOIMPORTS_REPO}
@$(GOIMPORTS) -l ${GOFILES_NOVENDOR} | (! grep .) || (echo "Code differs from goimports' style ^" && false)
@$(MAKE) test-local
.PHONY: test-local # Run local go test
test-local: ## Runs tests.
@echo "Running tests..."
@$(GO) test -short -race -gcflags=-l ${GOPACKAGES}
.PHONY: coverage
coverage: ## Runs tests with coverage.
@echo "Running tests with coverage..."
@echo ${GOPACKAGES} | xargs $(GO) test -short -race -coverprofile=coverage.txt -covermode=atomic && $(GO) tool cover -html=coverage.txt -o coverage.html
.PHONY: clean
clean:
@rm -rf ${BUILD_DIR}
.PHONY: docker-image
docker-image:
@DOCKER_BUILDKIT=1 docker build --ssh default --target image -t "${DOCKER_IMAGE}" .
.PHONY: docker-push
docker-push: docker-image
docker-push:
docker push ${DOCKER_IMAGE}