-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
94 lines (69 loc) · 2.54 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
export BINARY=ch
GO_VERSION?=$(shell cat go.mod | grep '^go' | awk '{print $$2}')
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
VERSION?=$(shell git describe --tags --abbrev=0)-snapshot
PKG_BASE=github.com/hortonworks/cloud-haunter
BUILD_TIME=$(shell date +%FT%T)
LDFLAGS=-w -s -X $(PKG_BASE)/context.Version=${VERSION} -X $(PKG_BASE)/context.BuildTime=${BUILD_TIME}
ifdef IGNORE_LABEL
LDFLAGS+= -X '$(PKG_BASE)/context.IgnoreLabel=$(IGNORE_LABEL)'
endif
ifdef OWNER_LABEL
LDFLAGS+= -X '$(PKG_BASE)/context.OwnerLabel=$(OWNER_LABEL)'
endif
ifdef RESOURCE_GROUPING_LABEL
LDFLAGS+= -X '$(PKG_BASE)/context.ResourceGroupingLabel=$(RESOURCE_GROUPING_LABEL)'
endif
ifdef RESOURCE_DESCRIPTION
LDFLAGS+= -X '$(PKG_BASE)/context.ResourceDescription=$(RESOURCE_DESCRIPTION)'
endif
ifdef AZURE_CREATION_TIME_LABEL
LDFLAGS+= -X '$(PKG_BASE)/context.AzureCreationTimeLabel=$(AZURE_CREATION_TIME_LABEL)'
endif
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
all: deps build
deps:
ifeq (, $(shell which gh))
ifeq ($(shell uname),Linux)
apt-get update
apt-get -y install software-properties-common
apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
apt-add-repository https://cli.github.com/packages
apt update
apt -y install gh
endif
ifeq ($(shell uname),Darwin)
brew install gh
endif
gh auth login
endif
_check: formatcheck vet
formatcheck:
([ -z "$(shell gofmt -d $(GOFILES_NOVENDOR))" ]) || (echo "Source is unformatted"; exit 1)
format:
gofmt -s -w $(GOFILES_NOVENDOR)
vet:
GO111MODULE=on go vet -mod=vendor ./...
test:
GO111MODULE=on go test -mod=vendor -timeout 30s -coverprofile coverage -race ./...
_build: build-darwin build-linux
build: _check test _build
cleanup:
rm -rf release && mkdir release
build-darwin:
GO111MODULE=on GOOS=darwin CGO_ENABLED=0 go build -mod=vendor -ldflags "$(LDFLAGS)" -o build/Darwin/${BINARY} main.go
build-linux:
GO111MODULE=on GOOS=linux CGO_ENABLED=0 go build -mod=vendor -ldflags "$(LDFLAGS)" -o build/Linux/${BINARY} main.go
build-docker:
@#USER_NS='-u $(shell id -u $(whoami)):$(shell id -g $(whoami))'
docker run --rm ${USER_NS} -v "${PWD}":/go/src/$(PKG_BASE) -w /go/src/$(PKG_BASE) golang:$(GO_VERSION) make build
mod-tidy:
@#USER_NS='-u $(shell id -u $(whoami)):$(shell id -g $(whoami))'
@docker run --rm ${USER_NS} -v "${PWD}":/go/src/$(PKG_BASE) -w /go/src/$(PKG_BASE) -e GO111MODULE=on golang:$(GO_VERSION) make _mod-tidy
_mod-tidy:
go mod tidy -compat=$(GO_VERSION) -v
go mod vendor
release: cleanup build
./release.sh
download:
./download.sh