Makefile raw

   1  # A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
   2  
   3  OS = $(shell uname | tr A-Z a-z)
   4  export PATH := $(abspath bin/):${PATH}
   5  
   6  # Build variables
   7  BUILD_DIR ?= build
   8  export CGO_ENABLED ?= 0
   9  export GOOS = $(shell go env GOOS)
  10  ifeq (${VERBOSE}, 1)
  11  ifeq ($(filter -v,${GOARGS}),)
  12  	GOARGS += -v
  13  endif
  14  TEST_FORMAT = short-verbose
  15  endif
  16  
  17  # Dependency versions
  18  GOTESTSUM_VERSION = 1.9.0
  19  GOLANGCI_VERSION = 1.53.3
  20  
  21  # Add the ability to override some variables
  22  # Use with care
  23  -include override.mk
  24  
  25  .PHONY: clear
  26  clear: ## Clear the working area and the project
  27  	rm -rf bin/
  28  
  29  .PHONY: check
  30  check: test lint ## Run tests and linters
  31  
  32  
  33  TEST_PKGS ?= ./...
  34  .PHONY: test
  35  test: TEST_FORMAT ?= short
  36  test: SHELL = /bin/bash
  37  test: export CGO_ENABLED=1
  38  test: bin/gotestsum ## Run tests
  39  	@mkdir -p ${BUILD_DIR}
  40  	bin/gotestsum --no-summary=skipped --junitfile ${BUILD_DIR}/coverage.xml --format ${TEST_FORMAT} -- -race -coverprofile=${BUILD_DIR}/coverage.txt -covermode=atomic $(filter-out -v,${GOARGS}) $(if ${TEST_PKGS},${TEST_PKGS},./...)
  41  
  42  .PHONY: lint
  43  lint: lint-go lint-yaml
  44  lint: ## Run linters
  45  
  46  .PHONY: lint-go
  47  lint-go:
  48  	golangci-lint run $(if ${CI},--out-format github-actions,)
  49  
  50  .PHONY: lint-yaml
  51  lint-yaml:
  52  	yamllint $(if ${CI},-f github,) --no-warnings .
  53  
  54  .PHONY: fmt
  55  fmt: ## Format code
  56  	golangci-lint run --fix
  57  
  58  deps: bin/golangci-lint bin/gotestsum yamllint
  59  deps: ## Install dependencies
  60  
  61  bin/gotestsum:
  62  	@mkdir -p bin
  63  	curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_${OS}_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum && chmod +x ./bin/gotestsum
  64  
  65  bin/golangci-lint:
  66  	@mkdir -p bin
  67  	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_VERSION}
  68  
  69  .PHONY: yamllint
  70  yamllint:
  71  	pip3 install --user yamllint
  72  
  73  # Add custom targets here
  74  -include custom.mk
  75  
  76  .PHONY: list
  77  list: ## List all make targets
  78  	@${MAKE} -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
  79  
  80  .PHONY: help
  81  .DEFAULT_GOAL := help
  82  help:
  83  	@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  84  
  85  # Variable outputting/exporting rules
  86  var-%: ; @echo $($*)
  87  varexport-%: ; @echo $*=$($*)
  88