-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
62 lines (55 loc) · 2.1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
MAKEFLAGS+=-j --no-print-directory
_SHELL := bash
SHELL=$(if $@,$(info ❱ [1m$@[0m))$(_SHELL)
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
COPY:=The Enterprise Contract Contributors
##@ Information
.PHONY: help
help: ## Display this help
@awk 'function ww(s) {\
if (length(s) < 59) {\
return s;\
}\
else {\
r="";\
l="";\
split(s, arr, " ");\
for (w in arr) {\
if (length(l " " arr[w]) > 59) {\
r=r l "\n ";\
l="";\
}\
l=l " " arr[w];\
}\
r=r l;\
return r;\
}\
} BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9%/_-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", "make " $$1, ww($$2) } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
# The go.work file is git ignored and not checked in. Create one if
# it doesn't exist already. (Note we're using absolute paths.)
go.work:
ROOT=$$(git rev-parse --show-toplevel) && \
cd $${ROOT} && \
go work init && \
go work use -r $${ROOT}
.PHONY: test
test: go.work ## Run all unit tests
@echo "Unit tests:"
@go test -race -covermode=atomic -coverprofile=coverage-unit.out -timeout 1000ms -tags=unit $$(go work edit -json | jq -c -r '[.Use[].DiskPath] | map_values(. + "/...")[]')
.PHONY: lint
lint: go.work go-mod-lint ## Run linter
@golangci-lint run --sort-results -- $$(go work edit -json | jq -c -r '[.Use[].DiskPath] | map_values(. + "/...")[]')
.PHONY: go-mod-lint
go-mod-lint:
@echo "Scanning for go.mod files and performing tidy..."
@find . -name "go.mod" -execdir go mod tidy >/dev/null 2>&1 \;
@echo "Checking for modified go.mod or go.sum files..."
@if git status --porcelain | grep -q -e "go.mod" -e "go.sum"; then \
echo "Ensure the following go.mod or go.sum files are added to the git commit:"; \
git status --porcelain | grep -e "go.mod" -e "go.sum"; \
else \
echo "No go.mod or go.sum files need to be added to the git commit."; \
fi
.PHONY: lint-fix
lint-fix: go.work
@golangci-lint run --sort-results --fix -- $$(go work edit -json | jq -c -r '[.Use[].DiskPath] | map_values(. + "/...")[]')