-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
68 lines (56 loc) · 1.98 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
63
64
65
66
67
68
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=cps
ARCH := $(shell arch)
ifeq ($(ARCH),aarch64)
GOARCH=arm64
else
GOARCH=amd64
endif
BINARY_LINUX=$(BINARY_NAME)_linux
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
BUILDPATH=$(shell echo `pwd`/.build)/bin
GOLANG_CI_LINT_VERSION=1.39.0
# Copied from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@echo
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; { \
printf("$(_GREEN)make %-35s$(_RESET) $(_YELLOW)%s$(_RESET)\n", $$1, $$2) \
}'
all: test build
build: ## Build CPS binary
GOARCH=${GOARCH} $(GOBUILD) -o $(BINARY_NAME) -v -ldflags "-s -w -X github.com/rapid7/cps/version.GitCommit=$(GIT_COMMIT)"
test: ## Run unit tests
$(GOTEST) -v ./...
test-bench: ## Run unit tests (benchmark)
$(GOTEST) -v -bench=. ./...
test-benchmem: ## Run unit tests (benchmem)
$(GOTEST) -v -benchmem -bench=. ./...
test-cover: ## Run unit tests (with coverage)
$(GOTEST) -mod=vendor -coverprofile=c.out ./...
lint-setup:
@# Make sure linter is up to date
$(eval CURRENT_VERSION := $(strip $(shell golangci-lint version 2>&1 | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')))
@if [ "$(CURRENT_VERSION)" != "$(GOLANG_CI_LINT_VERSION)" ]; then \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(BUILDPATH) v$(GOLANG_CI_LINT_VERSION) ; \
fi
lint: lint-setup ## Run the linters
@echo "Running lint for branch ${BRANCH}..."
golangci-lint run --new-from-rev=master
clean: ## Clean
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_LINUX)
rm -rf $(BUILDPATH)
run: ## Run CPS
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)
# Cross compilation
build-linux: ## Build CPS Binary (linux target)
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} $(GOBUILD) -o $(BINARY_LINUX) -v -ldflags "-s -w -X github.com/rapid7/cps/version.GitCommit=$(GIT_COMMIT)"