forked from docker/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
104 lines (77 loc) · 3.17 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
include vars.mk
ifeq ($(BUILDTIME),)
BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" 2> /dev/null)
endif
ifeq ($(BUILDTIME),)
BUILDTIME := unknown
$(warning unable to set BUILDTIME. Set the value manually)
endif
BUILDTAGS=""
ifeq ($(EXPERIMENTAL),on)
BUILDTAGS="experimental"
endif
LDFLAGS := "-s -w \
-X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \
-X $(PKG_NAME)/internal.Version=$(TAG) \
-X $(PKG_NAME)/internal.Experimental=$(EXPERIMENTAL) \
-X $(PKG_NAME)/internal.BuildTime=$(BUILDTIME)"
EXEC_EXT :=
ifeq ($(OS),Windows_NT)
EXEC_EXT := .exe
endif
GO_BUILD := CGO_ENABLED=0 go build -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
GO_TEST := CGO_ENABLED=0 go test -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
all: bin/$(BIN_NAME) test
check_go_env:
@test $$(go list) = "$(PKG_NAME)" || \
(echo "Invalid Go environment" && false)
cross: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe ## cross-compile binaries (linux, darwin, windows)
e2e-cross: bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-windows.exe
.PHONY: bin/$(BIN_NAME)-e2e-windows
bin/$(BIN_NAME)-e2e-%.exe bin/$(BIN_NAME)-e2e-%: e2e bin/$(BIN_NAME)-%
GOOS=$* $(GO_TEST) -c -o $@ ./e2e/
.PHONY: bin/$(BIN_NAME)-windows
bin/$(BIN_NAME)-%.exe bin/$(BIN_NAME)-%: cmd/$(BIN_NAME) check_go_env
GOOS=$* $(GO_BUILD) -o $@ ./$<
bin/%: cmd/% check_go_env
$(GO_BUILD) -o $@$(EXEC_EXT) ./$<
check: lint test
test: test-unit test-e2e ## run all tests
lint: ## run linter(s)
@echo "Linting..."
@gometalinter --config=gometalinter.json ./...
test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
@echo "Running e2e tests..."
$(GO_TEST) -v ./e2e/
test-unit: ## run unit tests
@echo "Running unit tests..."
$(GO_TEST) $(shell go list ./... | grep -vE '/e2e')
coverage-bin:
CGO_ENABLED=0 go test -tags="$(BUILDTAGS) testrunmain" -ldflags=$(LDFLAGS) -coverpkg="./..." -c -o _build/$(BIN_NAME).cov ./cmd/docker-app
coverage-test-unit:
@echo "Running unit tests (coverage)..."
@$(call mkdir,_build/cov)
$(GO_TEST) -cover -test.coverprofile=_build/cov/unit.out $(shell go list ./... | grep -vE '/e2e')
coverage-test-e2e: coverage-bin
@echo "Running e2e tests (coverage)..."
@$(call mkdir,_build/cov)
DOCKERAPP_BINARY=../e2e/coverage-bin $(GO_TEST) -v ./e2e
coverage: coverage-test-unit coverage-test-e2e ## run tests with coverage
go install ./vendor/github.com/wadey/gocovmerge/
gocovmerge _build/cov/*.out > _build/cov/all.out
go tool cover -func _build/cov/all.out
go tool cover -html _build/cov/all.out -o _build/cov/coverage.html
clean: ## clean build artifacts
$(call rmdir,bin)
$(call rmdir,_build)
$(call rm,docker-app-*.tar.gz)
vendor: ## update vendoring
$(call rmdir,vendor)
dep ensure -v
specification/bindata.go: specification/schemas/*.json
go generate github.com/docker/app/specification
schemas: specification/bindata.go ## generate specification/bindata.go from json schemas
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
.PHONY: cross e2e-cross test check lint test-unit test-e2e coverage coverage-bin coverage-test-unit coverage-test-e2e clean vendor schemas help
.DEFAULT: all