Skip to content

Commit 3d9e31f

Browse files
alacukupoiana
authored andcommitted
new(Makefile): add new targets to the Makefile
* fmt target: make sure that all files are formatted, have the license header (if not adds it), checks that the package imports are in order and that go mod and sum are tidied. * lint target: runs golangci-lint against the modified files. Handy to check the modified code before pushing it. Signed-off-by: Aldo Lacuku <[email protected]>
1 parent 5d20078 commit 3d9e31f

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

Makefile

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
SHELL=/bin/bash -o pipefail
2+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
3+
ifeq (,$(shell go env GOBIN))
4+
GOBIN=$(shell go env GOPATH)/bin
5+
else
6+
GOBIN=$(shell go env GOBIN)
7+
endif
28

39
GO ?= go
410

@@ -12,4 +18,41 @@ falcoctl:
1218
.PHONY: test
1319
test:
1420
$(GO) vet ./...
15-
$(GO) test ${TEST_FLAGS} ./...
21+
$(GO) test ${TEST_FLAGS} ./...
22+
23+
# Install gci if not available
24+
gci:
25+
ifeq (, $(shell which gci))
26+
@go install github.com/daixiang0/[email protected]
27+
GCI=$(GOBIN)/gci
28+
else
29+
GCI=$(shell which gci)
30+
endif
31+
32+
# Install addlicense if not available
33+
addlicense:
34+
ifeq (, $(shell which addlicense))
35+
@go install github.com/google/[email protected]
36+
ADDLICENSE=$(GOBIN)/addlicense
37+
else
38+
ADDLICENSE=$(shell which addlicense)
39+
endif
40+
41+
# Run go fmt against code and add the licence header
42+
fmt: gci addlicense
43+
go mod tidy
44+
go fmt ./...
45+
find . -type f -name '*.go' -a -exec $(GCI) -local github.com/falcosecurity/falcoctl -w {} \;
46+
find . -type f -name '*.go' -exec $(ADDLICENSE) -l apache -c "The Falco Authors" -y "$(shell date +%Y)" {} \;
47+
48+
# Install golangci-lint if not available
49+
golangci-lint:
50+
ifeq (, $(shell which golangci-lint))
51+
@go install github.com/golangci/golangci-lint/cmd/[email protected]
52+
GOLANGCILINT=$(GOBIN)/golangci-lint
53+
else
54+
GOLANGCILINT=$(shell which golangci-lint)
55+
endif
56+
57+
lint: golangci-lint
58+
$(GOLANGCILINT) run --new

0 commit comments

Comments
 (0)