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