|
1 | | -SOURCE_FILES?=$$(go list ./... | grep -v /vendor/) |
2 | | -TEST_PATTERN?=. |
3 | | -TEST_OPTIONS?= |
4 | | -VERSION?=$$(cat VERSION) |
5 | | -LINTER?=$$(which golangci-lint) |
6 | | -LINTER_VERSION=1.50.0 |
7 | | - |
8 | | -ifeq ($(OS),Windows_NT) |
9 | | - LINTER_FILE=golangci-lint-$(LINTER_VERSION)-windows-amd64.zip |
10 | | - LINTER_UNPACK= >| app.zip; unzip -j app.zip -d $$GOPATH/bin; rm app.zip |
11 | | -else ifeq ($(OS), Darwin) |
12 | | - LINTER_FILE=golangci-lint-$(LINTER_VERSION)-darwin-amd64.tar.gz |
13 | | - LINTER_UNPACK= | tar xzf - -C $$GOPATH/bin --wildcards --strip 1 "**/golangci-lint" |
14 | | -else |
15 | | - LINTER_FILE=golangci-lint-$(LINTER_VERSION)-linux-amd64.tar.gz |
16 | | - LINTER_UNPACK= | tar xzf - -C $$GOPATH/bin --wildcards --strip 1 "**/golangci-lint" |
17 | | -endif |
18 | | - |
19 | | -setup: |
20 | | - go install github.com/pierrre/gotestcover@latest |
21 | | - go install golang.org/x/tools/cmd/cover@latest |
22 | | - go mod download |
23 | | - |
24 | | -test: test_and_cover_report lint |
25 | | - |
26 | | -test_and_cover_report: |
27 | | - gotestcover $(TEST_OPTIONS) -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=2m |
28 | | - |
29 | 1 | cover: test ## Run all the tests and opens the coverage report |
30 | 2 | go tool cover -html=coverage.txt |
31 | 3 |
|
| 4 | +test: |
| 5 | + go test ./... |
| 6 | + |
32 | 7 | fmt: ## gofmt and goimports all go files |
33 | 8 | find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done |
34 | 9 |
|
35 | | -lint: ## Run all the linters |
36 | | - @if [ "$(LINTER)" = "" ]; then\ |
37 | | - curl -L https://github.com/golangci/golangci-lint/releases/download/v$(LINTER_VERSION)/$(LINTER_FILE) $(LINTER_UNPACK) ;\ |
38 | | - chmod +x $$GOPATH/bin/golangci-lint;\ |
39 | | - fi |
40 | | - |
41 | | - golangci-lint run |
42 | | - |
43 | | -ci: test_and_cover_report ## Run all the tests but no linters - use https://golangci.com integration instead |
44 | | - |
45 | 10 | build: |
46 | 11 | go build |
47 | 12 |
|
48 | | -release: ## Release new version |
49 | | - git tag | grep -q $(VERSION) && echo This version was released! Increase VERSION! || git tag $(VERSION) && git push origin $(VERSION) && git tag v$(VERSION) && git push origin v$(VERSION) |
50 | | - |
51 | | -# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html |
52 | 13 | help: |
53 | 14 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
54 | 15 |
|
55 | 16 | .DEFAULT_GOAL := build |
| 17 | + |
| 18 | +# BEGIN: lint-install . |
| 19 | +# http://github.com/codeGROOVE-dev/lint-install |
| 20 | + |
| 21 | +.PHONY: lint |
| 22 | +lint: _lint |
| 23 | + |
| 24 | +LINT_ARCH := $(shell uname -m) |
| 25 | +LINT_OS := $(shell uname) |
| 26 | +LINT_OS_LOWER := $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]') |
| 27 | +LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) |
| 28 | + |
| 29 | +# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation |
| 30 | +ifeq ($(LINT_OS),Darwin) |
| 31 | + ifeq ($(LINT_ARCH),arm64) |
| 32 | + LINT_ARCH=x86_64 |
| 33 | + endif |
| 34 | +endif |
| 35 | + |
| 36 | +LINTERS := |
| 37 | +FIXERS := |
| 38 | + |
| 39 | +GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml |
| 40 | +GOLANGCI_LINT_VERSION ?= v2.3.0 |
| 41 | +GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) |
| 42 | +$(GOLANGCI_LINT_BIN): |
| 43 | + mkdir -p $(LINT_ROOT)/out/linters |
| 44 | + rm -rf $(LINT_ROOT)/out/linters/golangci-lint-* |
| 45 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LINT_ROOT)/out/linters $(GOLANGCI_LINT_VERSION) |
| 46 | + mv $(LINT_ROOT)/out/linters/golangci-lint $@ |
| 47 | + |
| 48 | +LINTERS += golangci-lint-lint |
| 49 | +golangci-lint-lint: $(GOLANGCI_LINT_BIN) |
| 50 | + find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" \; |
| 51 | + |
| 52 | +FIXERS += golangci-lint-fix |
| 53 | +golangci-lint-fix: $(GOLANGCI_LINT_BIN) |
| 54 | + find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" --fix \; |
| 55 | + |
| 56 | +YAMLLINT_VERSION ?= 1.37.1 |
| 57 | +YAMLLINT_ROOT := $(LINT_ROOT)/out/linters/yamllint-$(YAMLLINT_VERSION) |
| 58 | +YAMLLINT_BIN := $(YAMLLINT_ROOT)/dist/bin/yamllint |
| 59 | +$(YAMLLINT_BIN): |
| 60 | + mkdir -p $(LINT_ROOT)/out/linters |
| 61 | + rm -rf $(LINT_ROOT)/out/linters/yamllint-* |
| 62 | + curl -sSfL https://github.com/adrienverge/yamllint/archive/refs/tags/v$(YAMLLINT_VERSION).tar.gz | tar -C $(LINT_ROOT)/out/linters -zxf - |
| 63 | + cd $(YAMLLINT_ROOT) && pip3 install --target dist . || pip install --target dist . |
| 64 | + |
| 65 | +LINTERS += yamllint-lint |
| 66 | +yamllint-lint: $(YAMLLINT_BIN) |
| 67 | + PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_ROOT)/dist/bin/yamllint . |
| 68 | + |
| 69 | +.PHONY: _lint $(LINTERS) |
| 70 | +_lint: $(LINTERS) |
| 71 | + |
| 72 | +.PHONY: fix $(FIXERS) |
| 73 | +fix: $(FIXERS) |
| 74 | + |
| 75 | +# END: lint-install . |
0 commit comments