-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·116 lines (92 loc) · 3.11 KB
/
Makefile
File metadata and controls
executable file
·116 lines (92 loc) · 3.11 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
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (c) The Kowabunga Project
# Apache License, Version 2.0 (see LICENSE or https://www.apache.org/licenses/LICENSE-2.0.txt)
# SPDX-License-Identifier: Apache-2.0
#export GOOS=linux
#export GOARCH=amd64
# Make sure GOPATH is NOT set to this folder or we'll get an error "$GOPATH/go.mod exists but should not"
#export GOPATH = ""
export GO111MODULE = on
BINDIR = bin
GOLINT = $(BINDIR)/golangci-lint
GOVULNCHECK = $(BINDIR)/govulncheck
GOSEC = $(BINDIR)/gosec
PKGS = $(shell go list ./...)
PKGS_SHORT = $(shell go list ./... | sed 's%github.com/kowabunga-cloud/kiwi/%%')
V = 0
Q = $(if $(filter 1,$V),,@)
PROD = 0
ifeq ($(PROD),1)
DEBUG = -w -s
endif
M = $(shell printf "\033[34;1m▶\033[0m")
ifeq ($(V), 1)
OUT = ""
else
OUT = ">/dev/null"
endif
# This is our default target
# it does not build/run the tests
.PHONY: all
all: mod fmt vet lint build ; @ ## Do all
$Q echo "done"
# This target grabs the necessary go modules
.PHONY: mod
mod: ; $(info $(M) collecting modules…) @
$Q go mod download
$Q go mod tidy
# Updates all go modules
update: ; $(info $(M) updating modules…) @
$Q go get -u ./...
$Q go mod tidy
# Makes sure bin directory is created
.PHONY: bin
bin: ; $(info $(M) create local bin directory) @
$Q mkdir -p $(BINDIR)
.PHONY: build
build: ; $(info $(M) building Kiwi agent…) @
$Q go build \
-gcflags="internal/...=-e" \
-ldflags='$(DEBUG)' \
-o $(BINDIR) ./cmd/kiwi
.PHONY: tests
tests: ; $(info $(M) test suite…) @
$Q go test ./... -count=1 -coverprofile=coverage.txt
.PHONY: deb
deb: ; $(info $(M) building debian package…) @
$Q ./debian.sh
.PHONY: get-lint
get-lint: ; $(info $(M) downloading go-lint…) @
$Q test -x $(GOLINT) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s
.PHONY: lint
lint: get-lint ; $(info $(M) running go-lint…) @
$Q $(GOLINT) run ./... ; exit 0
.PHONY: get-govulncheck
get-govulncheck: ; $(info $(M) downloading govulncheck…) @
$Q test -x $(GOVULNCHECK) || GOBIN="$(PWD)/$(BINDIR)/" go install golang.org/x/vuln/cmd/govulncheck@latest
.PHONY: vuln
vuln: get-govulncheck ; $(info $(M) running govulncheck…) @ ## Check for known vulnerabilities
$Q $(GOVULNCHECK) ./... ; exit 0
.PHONY: get-gosec
get-gosec: ; $(info $(M) downloading gosec…) @
$Q test -x $(GOSEC) || GOBIN="$(PWD)/$(BINDIR)/" go install github.com/securego/gosec/v2/cmd/gosec@latest
.PHONY: sec
sec: get-gosec ; $(info $(M) running gosec…) @ ## AST / SSA code checks
$Q $(GOSEC) -terse -exclude=G101,G115 ./... ; exit 0
.PHONY: vet
vet: ; $(info $(M) running go vet…) @
$Q go vet $(PKGS) ; exit 0
.PHONY: fmt
fmt: ; $(info $(M) running go fmt…) @
$Q gofmt -w -s $(PKGS_SHORT)
.PHONY: clean
clean: ; $(info $(M) cleaning…) @ ## Cleanup everything
$Q rm -rf $(BINDIR)
# This target count all the lines of .go files (no matter if empty lines or comments)
.PHONY: lc
lc: ; @ ## Count lines
@find . -name "*.go" -exec cat {} \; | wc -l | awk '{print $$1}'
# This target count the lines of go code only (ignore empty lines, comments, etc.)
# it requires gosloc
.PHONY: sloc
sloc: ; @ ## Count GO lines
@find . -name "*.go" -exec cat {} \; | gosloc