2021-12-07 15:31:39 +03:00
|
|
|
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
|
|
|
|
|
|
|
OS = $(shell uname | tr A-Z a-z)
|
|
|
|
export PATH := $(abspath bin/):${PATH}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Dependency versions
|
2023-06-05 11:15:05 +03:00
|
|
|
GOTESTSUM_VERSION = 1.9.0
|
2024-01-17 17:54:30 +03:00
|
|
|
GOLANGCI_VERSION = 1.53.3
|
2021-12-07 15:31:39 +03:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
|
|
TEST_PKGS ?= ./...
|
|
|
|
.PHONY: test
|
|
|
|
test: TEST_FORMAT ?= short
|
|
|
|
test: SHELL = /bin/bash
|
|
|
|
test: export CGO_ENABLED=1
|
|
|
|
test: bin/gotestsum ## Run tests
|
|
|
|
@mkdir -p ${BUILD_DIR}
|
|
|
|
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},./...)
|
|
|
|
|
2024-01-17 17:54:30 +03:00
|
|
|
.PHONY: lint
|
|
|
|
lint: lint-go lint-yaml
|
|
|
|
lint: ## Run linters
|
|
|
|
|
|
|
|
.PHONY: lint-go
|
|
|
|
lint-go:
|
|
|
|
golangci-lint run $(if ${CI},--out-format github-actions,)
|
|
|
|
|
|
|
|
.PHONY: lint-yaml
|
|
|
|
lint-yaml:
|
|
|
|
yamllint $(if ${CI},-f github,) --no-warnings .
|
|
|
|
|
|
|
|
.PHONY: fmt
|
|
|
|
fmt: ## Format code
|
|
|
|
golangci-lint run --fix
|
|
|
|
|
|
|
|
deps: bin/golangci-lint bin/gotestsum yamllint
|
|
|
|
deps: ## Install dependencies
|
|
|
|
|
|
|
|
bin/gotestsum:
|
2021-12-07 15:31:39 +03:00
|
|
|
@mkdir -p bin
|
2024-01-17 17:54:30 +03:00
|
|
|
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
|
2021-12-07 15:31:39 +03:00
|
|
|
|
2024-01-17 17:54:30 +03:00
|
|
|
bin/golangci-lint:
|
|
|
|
@mkdir -p bin
|
|
|
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_VERSION}
|
2021-12-07 15:31:39 +03:00
|
|
|
|
2024-01-17 17:54:30 +03:00
|
|
|
.PHONY: yamllint
|
|
|
|
yamllint:
|
|
|
|
pip3 install --user yamllint
|
2021-12-07 15:31:39 +03:00
|
|
|
|
|
|
|
# Add custom targets here
|
|
|
|
-include custom.mk
|
|
|
|
|
|
|
|
.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 $*=$($*)
|