Makefile 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
  2. OS = $(shell uname | tr A-Z a-z)
  3. export PATH := $(abspath bin/):${PATH}
  4. # Build variables
  5. BUILD_DIR ?= build
  6. export CGO_ENABLED ?= 0
  7. export GOOS = $(shell go env GOOS)
  8. ifeq (${VERBOSE}, 1)
  9. ifeq ($(filter -v,${GOARGS}),)
  10. GOARGS += -v
  11. endif
  12. TEST_FORMAT = short-verbose
  13. endif
  14. # Dependency versions
  15. GOTESTSUM_VERSION = 0.4.0
  16. GOLANGCI_VERSION = 1.21.0
  17. # Add the ability to override some variables
  18. # Use with care
  19. -include override.mk
  20. .PHONY: clear
  21. clear: ## Clear the working area and the project
  22. rm -rf bin/
  23. .PHONY: check
  24. check: test lint ## Run tests and linters
  25. bin/gotestsum: bin/gotestsum-${GOTESTSUM_VERSION}
  26. @ln -sf gotestsum-${GOTESTSUM_VERSION} bin/gotestsum
  27. bin/gotestsum-${GOTESTSUM_VERSION}:
  28. @mkdir -p bin
  29. curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_${OS}_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum-${GOTESTSUM_VERSION} && chmod +x ./bin/gotestsum-${GOTESTSUM_VERSION}
  30. TEST_PKGS ?= ./...
  31. .PHONY: test
  32. test: TEST_FORMAT ?= short
  33. test: SHELL = /bin/bash
  34. test: export CGO_ENABLED=1
  35. test: bin/gotestsum ## Run tests
  36. @mkdir -p ${BUILD_DIR}
  37. 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},./...)
  38. bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
  39. @ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
  40. bin/golangci-lint-${GOLANGCI_VERSION}:
  41. @mkdir -p bin
  42. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ./bin/ v${GOLANGCI_VERSION}
  43. @mv bin/golangci-lint $@
  44. .PHONY: lint
  45. lint: bin/golangci-lint ## Run linter
  46. bin/golangci-lint run
  47. .PHONY: fix
  48. fix: bin/golangci-lint ## Fix lint violations
  49. bin/golangci-lint run --fix
  50. # Add custom targets here
  51. -include custom.mk
  52. .PHONY: list
  53. list: ## List all make targets
  54. @${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
  55. .PHONY: help
  56. .DEFAULT_GOAL := help
  57. help:
  58. @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  59. # Variable outputting/exporting rules
  60. var-%: ; @echo $($*)
  61. varexport-%: ; @echo $*=$($*)