forked from openshift/configuration-anomaly-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
104 lines (78 loc) · 3.46 KB
/
Makefile
File metadata and controls
104 lines (78 loc) · 3.46 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
include project.mk
include boilerplate/generated-includes.mk
# Binaries used in Makefile
bin/cobra:
GOBIN=$(PWD)/bin go install -mod=readonly $(shell go list -m -f '{{ .Path}}/cobra@{{ .Version }}' github.com/spf13/cobra)
bin/embedmd:
GOBIN=$(PWD)/bin go install -mod=readonly github.com/campoy/embedmd@v1.0.0
bin/golangci-lint:
GOBIN=$(PWD)/bin go install -mod=readonly github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
bin/gosec:
GOBIN=$(PWD)/bin go install -mod=readonly github.com/securego/gosec/v2/cmd/gosec@v2.10.0
bin/mockgen:
GOBIN=$(PWD)/bin go install -mod=readonly github.com/golang/mock/mockgen@v1.6.0
cadctl/cadctl: cadctl/**/*.go pkg/**/*.go go.mod go.sum
GOBIN=$(PWD)/cadctl go install -ldflags="-s -w" -mod=readonly -trimpath $(PWD)/cadctl
## make all binaries be used before any other commands
# Required as mockgen is running without a relative path
export PATH := $(PWD)/bin:$(PATH)
# Actions
.DEFAULT_GOAL := all
.PHONY: all
all: build lint test generate-markdown
# build uses the following Go flags:
# -s -w for stripping the binary (making it smaller)
# -mod=readonly and -trimpath are for generating reproducible/verifiable binaries. See also: https://reproducible-builds.org/
.PHONY: build
build: cadctl-install-local-force
go build -ldflags="-s -w" -mod=readonly -trimpath ./...
.PHONY: test
test:
go test -race -mod=readonly ./...
.PHONY: lint
lint: bin/golangci-lint lint-only-hack
GOLANGCI_LINT_CACHE=$(shell mktemp -d) ./bin/golangci-lint run
.PHONY: lint-only-hack
lint-only-hack: bin/golangci-lint
cd hack/update-template/ && GOLANGCI_LINT_CACHE=$(shell mktemp -d) ../../bin/golangci-lint run -c ../../.golangci.yml
.PHONY: test-with-race
test-with-race:
go test -race ./...
.PHONY: generate
generate: bin/mockgen generate-template-file generate-markdown
go generate -mod=readonly ./...
.PHONY: test-with-coverage
test-with-coverage:
go test -cover -mod=readonly ./...
.PHONY: cadctl-install-local
cadctl-install-local: cadctl/cadctl
.PHONY: cadctl-install-local-force
cadctl-install-local-force:
rm cadctl/cadctl >/dev/null 2>&1 || true
make cadctl-install-local
# generate-markdown will update the existing markdown files with the contents of the embededed files.
# -w will write the changes to disk instead of presenting them.
MARKDOWN_SOURCES := $(shell find $(SOURCEDIR) -name '*.md')
.PHONY: generate-markdown
generate-markdown: $(MARKDOWN_SOURCES) bin/embedmd
./bin/embedmd -w $(MARKDOWN_SOURCES)
## CI actions
.PHONY: coverage
coverage: hack/codecov.sh
.PHONY: generate-template-file
generate-template-file:
cd ./hack/update-template/ && go build -mod=readonly . && ./update-template
# not using the 'all' target to make the target independent
.PHONY: validate
validate: build generate checks isclean
# will hold all of the checks that will run on the repo. this can be extracted to a script if need be
.PHONY: checks
checks: check-duplicate-error-messages
# check-duplicate-error-messages will conform with
.PHONY: check-duplicate-error-messages
check-duplicate-error-messages:
@(test $$(grep -Ir errors.New . | grep -v -e .*.md | wc -l) -eq 0) || (echo "please use fmt.Errorf and not errors.New" >&2 && exit 1)
@(test $$(grep -Ir 'fmt.Errorf("' . | grep -v -e './.git' -e .*.md | sed 's/\(.*\)\(fmt.Errorf.*\)/\2/' | sort | uniq -c | awk '$$1 != "1"' | wc -l) -eq 0) || (echo "There are duplicate error values, please consolidate them or make them unique" >&2 && exit 1)
.PHONY: boilerplate-update
boilerplate-update:
@boilerplate/update