...

Text file src/github.com/goph/emperror/Makefile

Documentation: github.com/goph/emperror

     1# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
     2
     3OS = $(shell uname)
     4
     5# Build variables
     6BUILD_DIR ?= build
     7export CGO_ENABLED ?= 0
     8export GOOS = $(shell go env GOOS)
     9ifeq (${VERBOSE}, 1)
    10ifeq ($(filter -v,${GOARGS}),)
    11	GOARGS += -v
    12endif
    13TEST_FORMAT = short-verbose
    14endif
    15
    16GOTESTSUM_VERSION = 0.3.3
    17GOLANGCI_VERSION = 1.15.0
    18
    19# Add the ability to override some variables
    20# Use with care
    21-include override.mk
    22
    23.PHONY: clear
    24clear: ## Clear the working area and the project
    25	rm -rf bin/
    26
    27.PHONY: check
    28check: test lint ## Run tests and linters
    29
    30bin/gotestsum: bin/gotestsum-${GOTESTSUM_VERSION}
    31	@ln -sf gotestsum-${GOTESTSUM_VERSION} bin/gotestsum
    32bin/gotestsum-${GOTESTSUM_VERSION}:
    33	@mkdir -p bin
    34ifeq (${OS}, Darwin)
    35	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}
    36endif
    37ifeq (${OS}, Linux)
    38	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}
    39endif
    40
    41TEST_PKGS ?= ./...
    42TEST_REPORT_NAME ?= results.xml
    43.PHONY: test
    44test: TEST_REPORT ?= main
    45test: TEST_FORMAT ?= short
    46test: SHELL = /bin/bash
    47test: bin/gotestsum ## Run tests
    48	@mkdir -p ${BUILD_DIR}/test_results/${TEST_REPORT}
    49	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},./...)
    50
    51bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
    52	@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
    53bin/golangci-lint-${GOLANGCI_VERSION}:
    54	@mkdir -p bin
    55	curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ./bin/ v${GOLANGCI_VERSION}
    56	@mv bin/golangci-lint $@
    57
    58.PHONY: lint
    59lint: bin/golangci-lint ## Run linter
    60	bin/golangci-lint run
    61
    62release-%: TAG_PREFIX = v
    63release-%:
    64ifneq (${DRY}, 1)
    65	@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
    66	@mv CHANGELOG.md.new CHANGELOG.md
    67
    68ifeq (${TAG}, 1)
    69	git add CHANGELOG.md
    70	git commit -m 'Prepare release $*'
    71	git tag -m 'Release $*' ${TAG_PREFIX}$*
    72ifeq (${PUSH}, 1)
    73	git push; git push origin ${TAG_PREFIX}$*
    74endif
    75endif
    76endif
    77
    78	@echo "Version updated to $*!"
    79ifneq (${PUSH}, 1)
    80	@echo
    81	@echo "Review the changes made by this script then execute the following:"
    82ifneq (${TAG}, 1)
    83	@echo
    84	@echo "git add CHANGELOG.md && git commit -m 'Prepare release $*' && git tag -m 'Release $*' ${TAG_PREFIX}$*"
    85	@echo
    86	@echo "Finally, push the changes:"
    87endif
    88	@echo
    89	@echo "git push; git push origin ${TAG_PREFIX}$*"
    90endif
    91
    92.PHONY: patch
    93patch: ## Release a new patch version
    94	@${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}')
    95
    96.PHONY: minor
    97minor: ## Release a new minor version
    98	@${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"}')
    99
   100.PHONY: major
   101major: ## Release a new major version
   102	@${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"}')
   103
   104.PHONY: list
   105list: ## List all make targets
   106	@${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
   107
   108.PHONY: help
   109.DEFAULT_GOAL := help
   110help:
   111	@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
   112
   113# Variable outputting/exporting rules
   114var-%: ; @echo $($*)
   115varexport-%: ; @echo $*=$($*)

View as plain text