# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html OS = $(shell uname) # Build variables BUILD_DIR ?= build export CGO_ENABLED ?= 0 export GOOS = $(shell go env GOOS) ifeq (${VERBOSE}, 1) ifeq ($(filter -v,${GOARGS}),) GOARGS += -v endif TEST_FORMAT = short-verbose endif GOTESTSUM_VERSION = 0.3.3 GOLANGCI_VERSION = 1.15.0 # Add the ability to override some variables # Use with care -include override.mk .PHONY: clear clear: ## Clear the working area and the project rm -rf bin/ .PHONY: check check: test lint ## Run tests and linters bin/gotestsum: bin/gotestsum-${GOTESTSUM_VERSION} @ln -sf gotestsum-${GOTESTSUM_VERSION} bin/gotestsum bin/gotestsum-${GOTESTSUM_VERSION}: @mkdir -p bin ifeq (${OS}, Darwin) curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_darwin_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum-${GOTESTSUM_VERSION} && chmod +x ./bin/gotestsum-${GOTESTSUM_VERSION} endif ifeq (${OS}, Linux) curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum-${GOTESTSUM_VERSION} && chmod +x ./bin/gotestsum-${GOTESTSUM_VERSION} endif TEST_PKGS ?= ./... TEST_REPORT_NAME ?= results.xml .PHONY: test test: TEST_REPORT ?= main test: TEST_FORMAT ?= short test: SHELL = /bin/bash test: bin/gotestsum ## Run tests @mkdir -p ${BUILD_DIR}/test_results/${TEST_REPORT} bin/gotestsum --no-summary=skipped --junitfile ${BUILD_DIR}/test_results/${TEST_REPORT}/${TEST_REPORT_NAME} --format ${TEST_FORMAT} -- $(filter-out -v,${GOARGS}) $(if ${TEST_PKGS},${TEST_PKGS},./...) bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION} @ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint bin/golangci-lint-${GOLANGCI_VERSION}: @mkdir -p bin curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ./bin/ v${GOLANGCI_VERSION} @mv bin/golangci-lint $@ .PHONY: lint lint: bin/golangci-lint ## Run linter bin/golangci-lint run release-%: TAG_PREFIX = v release-%: ifneq (${DRY}, 1) @sed -e "s/^## \[Unreleased\]$$/## [Unreleased]\\"$$'\n'"\\"$$'\n'"\\"$$'\n'"## [$*] - $$(date +%Y-%m-%d)/g; s|^\[Unreleased\]: \(.*\/compare\/\)\(.*\)...HEAD$$|[Unreleased]: \1${TAG_PREFIX}$*...HEAD\\"$$'\n'"[$*]: \1\2...${TAG_PREFIX}$*|g" CHANGELOG.md > CHANGELOG.md.new @mv CHANGELOG.md.new CHANGELOG.md ifeq (${TAG}, 1) git add CHANGELOG.md git commit -m 'Prepare release $*' git tag -m 'Release $*' ${TAG_PREFIX}$* ifeq (${PUSH}, 1) git push; git push origin ${TAG_PREFIX}$* endif endif endif @echo "Version updated to $*!" ifneq (${PUSH}, 1) @echo @echo "Review the changes made by this script then execute the following:" ifneq (${TAG}, 1) @echo @echo "git add CHANGELOG.md && git commit -m 'Prepare release $*' && git tag -m 'Release $*' ${TAG_PREFIX}$*" @echo @echo "Finally, push the changes:" endif @echo @echo "git push; git push origin ${TAG_PREFIX}$*" endif .PHONY: patch patch: ## Release a new patch version @${MAKE} release-$(shell (git describe --abbrev=0 --tags 2> /dev/null || echo "0.0.0") | sed 's/^v//' | awk -F'[ .]' '{print $$1"."$$2"."$$3+1}') .PHONY: minor minor: ## Release a new minor version @${MAKE} release-$(shell (git describe --abbrev=0 --tags 2> /dev/null || echo "0.0.0") | sed 's/^v//' | awk -F'[ .]' '{print $$1"."$$2+1".0"}') .PHONY: major major: ## Release a new major version @${MAKE} release-$(shell (git describe --abbrev=0 --tags 2> /dev/null || echo "0.0.0") | sed 's/^v//' | awk -F'[ .]' '{print $$1+1".0.0"}') .PHONY: list list: ## List all make targets @${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 .PHONY: help .DEFAULT_GOAL := help help: @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' # Variable outputting/exporting rules var-%: ; @echo $($*) varexport-%: ; @echo $*=$($*)