github.com/akamai/AkamaiOPEN-edgegrid-golang/v2@v2.17.0/Makefile (about) 1 MODULE = $(shell $(GO) list -m) 2 COMMIT_SHA=$(shell git rev-parse --short HEAD) 3 VERSION ?= $(shell git describe --tags --always | grep '^v\d' || \ 4 echo $(FILEVERSION)-$(COMMIT_SHA)) 5 BIN = $(CURDIR)/bin 6 GOLANGCI_LINT_VERSION = v1.41.1 7 GO = go 8 TIMEOUT = 15 9 V = 0 10 Q = $(if $(filter 1,$V),,@) 11 M = $(shell echo ">") 12 13 clean-tools: 14 @rm -rf $(BIN)/go* 15 16 $(BIN): 17 @mkdir -p $@ 18 $(BIN)/%: | $(BIN) ; $(info $(M) Building $(PACKAGE)...) 19 $Q tmp=$$(mktemp -d); \ 20 env GO111MODULE=off GOPATH=$$tmp GOBIN=$(BIN) $(GO) get $(PACKAGE) \ 21 || ret=$$?; \ 22 rm -rf $$tmp ; exit $$ret 23 24 GOLINT = $(BIN)/golint 25 $(BIN)/golint: PACKAGE=golang.org/x/lint/golint 26 27 GOCOV = $(BIN)/gocov 28 $(BIN)/gocov: PACKAGE=github.com/axw/gocov/... 29 30 GOCOVXML = $(BIN)/gocov-xml 31 $(BIN)/gocov-xml: PACKAGE=github.com/AlekSi/gocov-xml 32 33 GOJUNITREPORT = $(BIN)/go-junit-report 34 $(BIN)/go-junit-report: PACKAGE=github.com/jstemmer/go-junit-report 35 36 GOIMPORTS = $(BIN)/goimports 37 $(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports 38 39 GOLANGCILINT = $(BIN)/golangci-lint 40 $(BIN)/golangci-lint: ; $(info $(M) Installing golangci-lint...) @ 41 $Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) $(GOLANGCI_LINT_VERSION) 42 43 44 .PHONY: all 45 all: clean fmt-check lint test-verbose create-junit-report create-coverage-files clean-tools 46 47 # Tests 48 49 TEST_TARGETS := test-default test-bench test-short test-verbose test-race 50 .PHONY: $(TEST_TARGETS) check test tests 51 test-bench: ARGS=-run=__absolutelynothing__ -bench=. ## Run benchmarks 52 test-short: ARGS=-short ## Run only short tests 53 test-verbose: ARGS=-v ## Run tests in verbose mode with coverage reporting 54 test-race: ARGS=-race ## Run tests with race detector 55 56 COVERAGE_MODE = atomic 57 COVERAGE_PROFILE = $(COVERAGE_DIR)/profile.out 58 COVERAGE_XML = $(COVERAGE_DIR)/coverage.xml 59 COVERAGE_HTML = $(COVERAGE_DIR)/index.html 60 61 $(TEST_TARGETS): COVERAGE_DIR := $(CURDIR)/test/coverage 62 $(TEST_TARGETS): SHELL = /bin/bash 63 $(TEST_TARGETS): ; $(info $(M) Running tests with coverage...) @ ## Run coverage tests 64 $Q mkdir -p $(COVERAGE_DIR) 65 $Q mkdir -p test 66 $Q set -o pipefail && $(GO) test -timeout $(TIMEOUT)s $(ARGS) \ 67 -coverpkg=./... \ 68 -covermode=$(COVERAGE_MODE) \ 69 -coverprofile="$(COVERAGE_PROFILE)" ./... | tee test/tests.output 70 71 .PHONY: create-junit-report 72 create-junit-report: | $(GOJUNITREPORT) ; $(info $(M) Creating junit xml report) @ 73 $Q cat $(CURDIR)/test/tests.output | $(GOJUNITREPORT) > $(CURDIR)/test/tests.xml 74 $Q sed -i -e 's/skip=/skipped=/g' $(CURDIR)/test/tests.xml 75 76 .PHONY: create-coverage-files 77 create-coverage-files: COVERAGE_DIR := $(CURDIR)/test/coverage 78 create-coverage-files: | $(GOCOV) $(GOCOVXML); $(info $(M) Creating coverage files...) @ ## Run coverage tests 79 $Q $(GO) tool cover -html=$(COVERAGE_PROFILE) -o $(COVERAGE_HTML) 80 $Q $(GOCOV) convert $(COVERAGE_PROFILE) | $(GOCOVXML) > $(COVERAGE_XML) 81 82 .PHONY: lint 83 lint: | $(GOLANGCILINT) ; $(info $(M) Running golangci-lint...) @ 84 $Q $(BIN)/golangci-lint run 85 86 .PHONY: fmt 87 fmt: | $(GOIMPORTS); $(info $(M) Running goimports...) @ ## Run goimports on all source files 88 $Q $(GOIMPORTS) -w . 89 90 .PHONY: fmt-check 91 fmt-check: | $(GOIMPORTS); $(info $(M) Running format and imports check...) @ ## Run goimports on all source files 92 $(eval OUTPUT = $(shell $(GOIMPORTS) -l .)) 93 @if [ "$(OUTPUT)" != "" ]; then\ 94 echo "Found following files with incorrect format and/or imports:";\ 95 echo "$(OUTPUT)";\ 96 false;\ 97 fi 98 99 # Misc 100 101 .PHONY: clean 102 clean: ; $(info $(M) Cleaning...) @ ## Cleanup everything 103 @rm -rf $(BIN) 104 @rm -rf test/tests.* test/coverage 105 106 .PHONY: help 107 help: 108 @grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ 109 awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' 110 111 .PHONY: version 112 version: 113 @echo $(VERSION)