forked from cisco-open/fsoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
115 lines (92 loc) · 3.91 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
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
############################################################
# Copyright 2022 Cisco Systems, Inc.
# See LICENSE.md for license information
############################################################
# git and build info
export BUILD_NUMBER ?= 0.0.0-0
export BUILD_HOST := $(shell hostname)
export GIT_HASH := $(shell git rev-parse --short --verify HEAD)
export GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
export GIT_OUTPUT := $(shell git status --porcelain)
export GIT_DIRTY := $(if ${strip ${GIT_OUTPUT}},true,false)
export GIT_TIMESTAMP := $(shell git show -s --format=%ct)
export BUILD_TIMESTAMP := $(shell date +%s)
export BUILD_IS_DEV ?= true
export VERSION_PKG_PATH := github.com/cisco-open/fsoc/cmd/version
export VERSION_INFO := \
-X ${VERSION_PKG_PATH}.defVersion=${BUILD_NUMBER} \
-X ${VERSION_PKG_PATH}.defGitHash=${GIT_HASH} \
-X ${VERSION_PKG_PATH}.defGitBranch=${GIT_BRANCH} \
-X ${VERSION_PKG_PATH}.defBuildHost=${BUILD_HOST} \
-X ${VERSION_PKG_PATH}.defGitDirty=${GIT_DIRTY} \
-X ${VERSION_PKG_PATH}.defGitTimestamp=${GIT_TIMESTAMP} \
-X ${VERSION_PKG_PATH}.defBuildTimestamp=${BUILD_TIMESTAMP}
DEV_BUILD_FLAGS := -ldflags='${VERSION_INFO} -X ${VERSION_PKG_PATH}.defIsDev=true'
PROD_BUILD_FLAGS := -ldflags='${VERSION_INFO} -X ${VERSION_PKG_PATH}.defIsDev=false'
GO := go
SCRIPT_DIR ?= $(shell pwd)
GOTEST_OPT := -p 1 -timeout 60s # -race desired but requires CGO
# choose files for formatting and other maintenance
GOFILES=$(shell find . -name '*.go' ! -name '*mock.go')
export CGO_ENABLED ?= 0
CURRENT_PATH := $(PATH)
TEST_REPORTS_DIR = ./build/reports
export GOBIN = $(SCRIPT_DIR)/bin
export PATH := $(GOBIN):bin:$(PATH)
GORELEASER ?= $(GOBIN)/goreleaser
GOLINT ?= $(GOBIN)/golangci-lint
IMPI ?= $(GOBIN)/impi
GOCOVMERGE ?= $(GOBIN)/gocovmerge
GOACC ?= $(GOBIN)/go-acc
GOCOBERTURA ?= $(GOBIN)/gocover-cobertura
dev-build: ## Build the project
@echo "Building ./fsoc"
${GO} build -a ${DEV_BUILD_FLAGS}
dev-test: ## Test the project locally
${GO} test $(GOTEST_OPT) ./...
help:
@grep -Eh '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
format:
@echo "formatting code..."
@$(GOBIN)/goimports -w -local github.com/cisco-open/fsoc ${GOFILES}
vet: ## Run go vet
@echo "vetting code..."
${GO} vet ./...
mod-update: ## Download all dependencies
@echo "installing dependencies..."
${GO} mod download
tidy: ## Tidy
@echo "tidying..."
${GO} mod tidy
lint: install-tools ## Linting go source code
@echo "linting code..."
${GOLINT} run ./...
go-impi: install-tools
@$(IMPI) --local github.com/cisco-open/fsoc --scheme stdThirdPartyLocal ./...
print-version-info:
@echo "BUILD_NUMBER=${BUILD_NUMBER}"
@echo "BUILD_HOST=${BUILD_HOST}"
@echo "GIT_HASH=${GIT_HASH}"
@echo "GIT_BRANCH=${GIT_BRANCH}"
@echo "GIT_DIRTY=${GIT_DIRTY}"
@echo "GIT_TIMESTAMP=${GIT_TIMESTAMP}"
@echo "BUILD_TIMESTAMP=${BUILD_TIMESTAMP}"
@echo "VERSION_PKG_PATH=${VERSION_PKG_PATH}"
.PHONY: install-tools
install-tools:
${GO} install github.com/golangci/golangci-lint/cmd/[email protected]
${GO} install github.com/goreleaser/[email protected]
${GO} install golang.org/x/tools/cmd/[email protected]
${GO} install github.com/pavius/impi/cmd/[email protected]
${GO} install github.com/wadey/[email protected]
${GO} install github.com/ory/[email protected]
${GO} install github.com/t-yuki/[email protected]
pre-commit: install-tools format go-impi lint vet tidy mod-update dev-build dev-test ## check all pre-req before committing
@echo "pre commit checks completed"
build: install-tools mod-update
@echo "Building binaries for all supported platforms in builds/"
@${GORELEASER} release --snapshot --clean --skip-publish
test-with-cover: install-tools
$(GOACC) ./...
mkdir -p $(TEST_REPORTS_DIR) && $(GOCOBERTURA) < coverage.txt > ./build/reports/coverage.xml
test: install-tools lint vet test-with-cover