-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·110 lines (87 loc) · 3.34 KB
/
Makefile
File metadata and controls
executable file
·110 lines (87 loc) · 3.34 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
# 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
PKG_NAME=github.com/kowabunga-cloud/kobra/kobra
VERSION=$(shell git describe --tags --always --dirty)
# 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
GORELEASER = $(BINDIR)/goreleaser
PKGS = $(shell go list ./...)
V = 0
Q = $(if $(filter 1,$V),,@)
PROD = 0
ifeq ($(PROD),1)
DEBUG = -w -s
endif
M = $(shell printf "\033[34;1m▶\033[0m")
.PHONY: all
all: mod fmt vet fix 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
# This target build the binaries
# its a PHONY because we want to build all the time
.PHONY: build
build: ; $(info $(M) building executables…) @ ## Build binaries
$Q mkdir -p $(BINDIR)
$Q go build \
-gcflags="kobra/...=-e" \
-ldflags='$(DEBUG) -X $(PKG_NAME).version=$(VERSION)' \
-o $(BINDIR) ./...
.PHONY: release
release: mod fmt vet fix lint get-goreleaser ; @
$Q PKG_NAME=$(PKG_NAME) VERSION=$(VERSION) $(GORELEASER) build --snapshot --clean
.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 ./... ; exit 0
.PHONY: get-goreleaser
get-goreleaser: ; $(info $(M) downloading go-releaser…) @
$Q test -x $(GORELEASER) || curl -sL https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_$(shell uname -s)_$(shell uname -m).tar.gz | tar -xz -C "$(PWD)/$(BINDIR)/"
# This target run the go vet which do some static analysis
.PHONY: vet
vet: ; $(info $(M) running go vet…) @ ## Run go vet
$Q go vet $(PKGS) ; exit 0
.PHONY: fix
fix: ; $(info $(M) running go fix…) @
$Q go fix $(PKGS) ; exit 0
# This target run the code format tool
.PHONY: fmt
fmt: ; $(info $(M) running go fmt…) @ ## Run go fmt on all source files
$Q go fmt $(PKGS)
.PHONY: tests
tests: ; $(info $(M) running test suite…) @
$Q go test ./... -count=1 -coverprofile=coverage.txt
PHONY: deb
deb: mod build ; $(info $(M) building debian package…) @
$Q ./debian.sh
# This target clean all the generated files
.PHONY: clean
clean: ; $(info $(M) cleaning…) @ ## Cleanup everything
@rm -rf $(BINDIR)/*