github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/Makefile (about) 1 include vars.mk 2 3 LDFLAGS := "-s -w \ 4 -X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \ 5 -X $(PKG_NAME)/internal.Version=$(TAG)" 6 7 EXEC_EXT := 8 ifeq ($(OS),Windows_NT) 9 EXEC_EXT := .exe 10 endif 11 12 INCLUDE_E2E := 13 ifneq ($(E2E_TESTS),) 14 INCLUDE_E2E := -run $(E2E_TESTS) 15 endif 16 17 TEST_RESULTS_DIR = _build/test-results 18 STATIC_FLAGS= CGO_ENABLED=0 19 GO_BUILD = $(STATIC_FLAGS) go build -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS) 20 GO_TEST = $(STATIC_FLAGS) go test -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS) 21 GO_TESTSUM = $(STATIC_FLAGS) gotestsum --junitfile $(TEST_RESULTS_DIR)/$(TEST_RESULTS_PREFIX)$(1) -- -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS) 22 23 all: bin/$(BIN_NAME) build-invocation-image test 24 25 check_go_env: 26 @test $$(go list) = "$(PKG_NAME)" || \ 27 (echo "Invalid Go environment - The local directory structure must match: $(PKG_NAME)" && false) 28 29 cross: cross-plugin ## cross-compile binaries (linux, darwin, windows) 30 31 cross-plugin: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe bin/$(BIN_NAME)-linux-arm64 bin/$(BIN_NAME)-linux-arm 32 33 e2e-cross: bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-windows.exe 34 35 .PHONY: dynamic 36 dynamic: STATIC_FLAGS := 37 dynamic: bin/$(BIN_NAME) 38 39 .PHONY: bin/$(BIN_NAME)-e2e-windows 40 bin/$(BIN_NAME)-e2e-%.exe bin/$(BIN_NAME)-e2e-%: e2e bin/$(BIN_NAME)-% 41 GOOS=$* $(GO_TEST) -c -o $@ ./e2e/ 42 43 .PHONY: bin/$(BIN_NAME)-linux-arm64 44 bin/$(BIN_NAME)-linux-arm64: cmd/$(BIN_NAME) check_go_env 45 GOOS=linux GOARCH=arm64 $(GO_BUILD) -o $@ ./$< 46 47 .PHONY: bin/$(BIN_NAME)-linux-arm 48 bin/$(BIN_NAME)-linux-arm: cmd/$(BIN_NAME) check_go_env 49 GOOS=linux GOARCH=arm $(GO_BUILD) -o $@ ./$< 50 51 .PHONY: bin/$(BIN_NAME)-windows 52 bin/$(BIN_NAME)-%.exe bin/$(BIN_NAME)-%: cmd/$(BIN_NAME) check_go_env 53 GOOS=$* $(GO_BUILD) -o $@ ./$< 54 55 bin/%: cmd/% check_go_env 56 $(GO_BUILD) -o $@$(EXEC_EXT) ./$< 57 58 build-invocation-image: ## build invocation image if not present (internal usage, not diplayed in help) 59 @echo "Build invocation image if needed" 60 $(if $(shell docker images -q docker/cnab-app-base:$(TAG)),, \ 61 $(MAKE) -f ./docker.Makefile invocation-image \ 62 ) 63 64 check: lint test 65 66 test: test-unit test-e2e ## run all tests 67 68 lint: ## run linter(s) 69 @echo "Linting..." 70 golangci-lint run --verbose --print-resources-usage --timeout 10m0s ./... 71 72 test-e2e: bin/$(BIN_NAME) ## run end-to-end tests 73 @echo "Running e2e tests..." 74 @$(call mkdir,$(TEST_RESULTS_DIR)) 75 $(call GO_TESTSUM,e2e.xml) -v ./e2e/ $(INCLUDE_E2E) 76 77 test-unit: ## run unit tests 78 @echo "Running unit tests..." 79 @$(call mkdir,$(TEST_RESULTS_DIR)) 80 $(call GO_TESTSUM,unit.xml) $(shell go list ./... | grep -vE '/e2e') 81 82 coverage-bin: 83 CGO_ENABLED=0 go test -tags="$(BUILDTAGS) testrunmain" -ldflags=$(LDFLAGS) -coverpkg="./..." -c -o _build/$(BIN_NAME).cov ./cmd/docker-app 84 85 coverage-test-unit: 86 @echo "Running unit tests (coverage)..." 87 @$(call mkdir,_build/cov) 88 @$(call mkdir,$(TEST_RESULTS_DIR)) 89 $(call GO_TESTSUM,unit-coverage.xml) -cover -test.coverprofile=_build/cov/unit.out $(shell go list ./... | grep -vE '/e2e') 90 91 coverage-test-e2e: coverage-bin 92 @echo "Running e2e tests (coverage)..." 93 @$(call mkdir,_build/cov) 94 @$(call mkdir,$(TEST_RESULTS_DIR)) 95 DOCKERAPP_BINARY=../e2e/coverage-bin $(call GO_TESTSUM,e2e-coverage.xml) -v ./e2e $(INCLUDE_E2E) 96 97 coverage: coverage-test-unit coverage-test-e2e ## run tests with coverage 98 @echo "Fixing coverage files..." 99 find _build/cov/ -type f -name "*.out" -print0 | xargs -0 sed -i '/^coverage/d' 100 grep coverage _build/cov/*.out || true 101 go install ./vendor/github.com/wadey/gocovmerge/ 102 gocovmerge _build/cov/*.out > _build/cov/all.out 103 go tool cover -func _build/cov/all.out 104 go tool cover -html _build/cov/all.out -o _build/cov/coverage.html 105 106 clean: ## clean build artifacts 107 $(call rmdir,bin) 108 $(call rmdir,_build) 109 $(call rm,docker-app-*.tar.gz) 110 111 vendor: ## update vendoring 112 $(call rmdir,vendor) 113 dep ensure -v $(DEP_ARGS) 114 115 specification/bindata.go: specification/schemas/*.json 116 go generate github.com/docker/app/specification 117 118 schemas: specification/bindata.go ## generate specification/bindata.go from json schemas 119 120 help: ## this help 121 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort 122 123 .PHONY: cross e2e-cross test check lint test-unit test-e2e coverage coverage-bin coverage-test-unit coverage-test-e2e clean vendor schemas help fix-coverage 124 .DEFAULT: all 125 126 127 .PHONY: yamldocs 128 yamldocs: ## generate documentation YAML files consumed by docs repo 129 mkdir -p ./_build/docs 130 docker build --output type=local,dest=./_build/ -f docs/yaml/Dockerfile .