-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
125 lines (90 loc) · 3.84 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
116
117
118
119
120
121
122
123
124
125
SHELL := /bin/bash
NAME := inspect
BINARY_NAME := inspect
GO := GO111MODULE=on GO15VENDOREXPERIMENT=1 go
GO_NOMOD := GO111MODULE=off go
PACKAGE_NAME := github.com/garethjevans/inspect
ROOT_PACKAGE := github.com/garethjevans/inspect
ORG := garethjevans
# set dev version unless VERSION is explicitly set via environment
VERSION ?= $(shell echo "$$(git describe --abbrev=0 --tags 2>/dev/null)-dev+$(REV)" | sed 's/^v//')
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/ | grep -v e2e)
PEGOMOCK_PACKAGE := github.com/petergtz/pegomock
GO_DEPENDENCIES := $(shell find . -type f -name '*.go')
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
SHA1 := $(shell git rev-parse HEAD 2> /dev/null || echo 'unknown')
BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown')
BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
BUILDFLAGS := -trimpath -ldflags \
" -X $(ROOT_PACKAGE)/pkg/version.Version=$(VERSION)\
-X $(ROOT_PACKAGE)/pkg/version.Revision=$(REV)\
-X $(ROOT_PACKAGE)/pkg/version.BuiltBy=make \
-X $(ROOT_PACKAGE)/pkg/version.Sha1=$(SHA1)\
-X $(ROOT_PACKAGE)/pkg/version.Branch='$(BRANCH)'\
-X $(ROOT_PACKAGE)/pkg/version.BuildDate='$(BUILD_DATE)'\
-X $(ROOT_PACKAGE)/pkg/version.GoVersion='$(GO_VERSION)'"
CGO_ENABLED = 0
BUILDTAGS :=
GOPATH1=$(firstword $(subst :, ,$(GOPATH)))
export PATH := $(PATH):$(GOPATH1)/bin
CLIENTSET_NAME_VERSIONED := v0.15.11
.PHONY: build
build: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILDTAGS) $(BUILDFLAGS) -o build/$(BINARY_NAME) cmd/$(NAME)/$(NAME).go
linux: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/linux/$(NAME) cmd/$(NAME)/$(NAME).go
chmod +x build/linux/$(NAME)
arm: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=arm $(GO) build $(BUILDFLAGS) -o build/arm/$(NAME) cmd/$(NAME)/$(NAME).go
chmod +x build/arm/$(NAME)
win: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/win/$(NAME)-windows-amd64.exe cmd/$(NAME)/$(NAME).go
darwin: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/darwin/$(NAME) cmd/$(NAME)/$(NAME).go
chmod +x build/darwin/$(NAME)
deploy-local: build
mkdir -p ~/bin
cp build/$(BINARY_NAME) ~/bin/$(BINARY_NAME)
all: version check
check: fmt lint build test
version:
echo "Go version: $(GO_VERSION)"
test:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) $(GO) test -coverprofile=coverage.out $(PACKAGE_DIRS)
testv:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) $(GO) test -test.v $(PACKAGE_DIRS)
testrich:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) richgo test -test.v $(PACKAGE_DIRS)
test1:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) $(GO) test -count=1 -short ./... -test.v -run $(TEST)
cover:
$(GO) tool cover -func coverage.out | grep total
coverage:
$(GO) tool cover -html=coverage.out
install: $(GO_DEPENDENCIES)
GOBIN=${GOPATH1}/bin $(GO) install $(BUILDFLAGS) cmd/$(NAME)/$(NAME).go
get-fmt-deps: ## Install goimports
$(GO_NOMOD) get golang.org/x/tools/cmd/goimports
importfmt: get-fmt-deps
@echo "Formatting the imports..."
goimports -w $(GO_DEPENDENCIES)
fmt: importfmt
@FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)`
@([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true
clean:
rm -rf build release
modtidy:
$(GO) mod tidy
mod: modtidy build
.PHONY: release clean arm
generate-fakes:
$(GO) generate ./...
generate-all: generate-fakes
.PHONY: goreleaser
goreleaser:
step-go-releaser --organisation=$(ORG) --revision=$(REV) --branch=$(BRANCH) --build-date=$(BUILD_DATE) --go-version=$(GO_VERSION) --root-package=$(ROOT_PACKAGE) --version=$(VERSION)
docs: build
./build/inspect docs
lint:
golangci-lint run