github.com/simonferquel/app@v0.6.1-0.20181012141724-68b7cccf26ac/Makefile (about)

     1  include vars.mk
     2  
     3  ifeq ($(BUILDTIME),)
     4    BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" 2> /dev/null)
     5  endif
     6  ifeq ($(BUILDTIME),)
     7    BUILDTIME := unknown
     8    $(warning unable to set BUILDTIME. Set the value manually)
     9  endif
    10  
    11  BUILDTAGS=""
    12  ifeq ($(EXPERIMENTAL),on)
    13    BUILDTAGS="experimental"
    14  endif
    15  
    16  LDFLAGS := "-s -w \
    17    -X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \
    18    -X $(PKG_NAME)/internal.Version=$(TAG)      \
    19    -X $(PKG_NAME)/internal.Experimental=$(EXPERIMENTAL) \
    20    -X $(PKG_NAME)/internal.BuildTime=$(BUILDTIME)"
    21  
    22  EXEC_EXT :=
    23  ifeq ($(OS),Windows_NT)
    24    EXEC_EXT := .exe
    25  endif
    26  
    27  GO_BUILD := CGO_ENABLED=0 go build -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
    28  GO_TEST := CGO_ENABLED=0 go test -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
    29  
    30  all: bin/$(BIN_NAME) test
    31  
    32  check_go_env:
    33  	@test $$(go list) = "$(PKG_NAME)" || \
    34  		(echo "Invalid Go environment - The local directory structure must match:  $(PKG_NAME)" && false)
    35  
    36  cross: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe ## cross-compile binaries (linux, darwin, windows)
    37  
    38  e2e-cross: bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-windows.exe
    39  
    40  .PHONY: bin/$(BIN_NAME)-e2e-windows
    41  bin/$(BIN_NAME)-e2e-%.exe bin/$(BIN_NAME)-e2e-%: e2e bin/$(BIN_NAME)-%
    42  	GOOS=$* $(GO_TEST) -c -o $@ ./e2e/
    43  
    44  .PHONY: bin/$(BIN_NAME)-windows
    45  bin/$(BIN_NAME)-%.exe bin/$(BIN_NAME)-%: cmd/$(BIN_NAME) check_go_env
    46  	GOOS=$* $(GO_BUILD) -o $@ ./$<
    47  
    48  bin/%: cmd/% check_go_env
    49  	$(GO_BUILD) -o $@$(EXEC_EXT) ./$<
    50  
    51  check: lint test
    52  
    53  test: test-unit test-e2e ## run all tests
    54  
    55  lint: ## run linter(s)
    56  	@echo "Linting..."
    57  	@gometalinter --config=gometalinter.json ./...
    58  
    59  test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
    60  	@echo "Running e2e tests..."
    61  	$(GO_TEST) -v ./e2e/
    62  
    63  test-unit: ## run unit tests
    64  	@echo "Running unit tests..."
    65  	$(GO_TEST) $(shell go list ./... | grep -vE '/e2e')
    66  
    67  coverage-bin:
    68  	CGO_ENABLED=0 go test -tags="$(BUILDTAGS) testrunmain" -ldflags=$(LDFLAGS) -coverpkg="./..." -c -o _build/$(BIN_NAME).cov ./cmd/docker-app
    69  
    70  coverage-test-unit:
    71  	@echo "Running unit tests (coverage)..."
    72  	@$(call mkdir,_build/cov)
    73  	$(GO_TEST) -cover -test.coverprofile=_build/cov/unit.out $(shell go list ./... | grep -vE '/e2e')
    74  
    75  coverage-test-e2e: coverage-bin
    76  	@echo "Running e2e tests (coverage)..."
    77  	@$(call mkdir,_build/cov)
    78  	DOCKERAPP_BINARY=../e2e/coverage-bin $(GO_TEST) -v ./e2e
    79  
    80  coverage: coverage-test-unit coverage-test-e2e ## run tests with coverage
    81  	go install ./vendor/github.com/wadey/gocovmerge/
    82  	gocovmerge _build/cov/*.out > _build/cov/all.out
    83  	go tool cover -func _build/cov/all.out
    84  	go tool cover -html _build/cov/all.out -o _build/cov/coverage.html
    85  
    86  clean: ## clean build artifacts
    87  	$(call rmdir,bin)
    88  	$(call rmdir,_build)
    89  	$(call rm,docker-app-*.tar.gz)
    90  
    91  vendor: ## update vendoring
    92  	$(call rmdir,vendor)
    93  	dep ensure -v
    94  
    95  specification/bindata.go: specification/schemas/*.json
    96  	go generate github.com/docker/app/specification
    97  
    98  schemas: specification/bindata.go ## generate specification/bindata.go from json schemas
    99  
   100  help: ## this help
   101  	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
   102  
   103  .PHONY: cross e2e-cross test check lint test-unit test-e2e coverage coverage-bin coverage-test-unit coverage-test-e2e clean vendor schemas help
   104  .DEFAULT: all