forked from confluentinc/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
170 lines (145 loc) · 5.62 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
SHELL := /bin/bash
ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor)
GIT_REMOTE_NAME ?= origin
MAIN_BRANCH ?= main
RELEASE_BRANCH ?= main
.PHONY: build # compile natively based on the system
build:
ifneq "" "$(findstring NT,$(shell uname))" # build for Windows
CC=gcc CXX=g++ make cli-builder
else ifneq (,$(findstring Linux,$(shell uname)))
ifneq (,$(findstring musl,$(shell ldd --version))) # build for musl Linux
CC=gcc CXX=g++ TAGS=musl make cli-builder
else # build for glibc Linux
CC=gcc CXX=g++ make cli-builder
endif
else # build for Darwin
make cli-builder
endif
.PHONY: cross-build # cross-compile from Darwin/amd64 machine to Win64, Linux64 and Darwin/arm64
cross-build:
ifeq ($(GOARCH),arm64)
ifeq ($(GOOS),linux)
CGO_ENABLED=1 CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++ CGO_LDFLAGS="-static" TAGS=musl make cli-builder
else # build for darwin/arm64
CGO_ENABLED=1 make cli-builder
endif
else # build for amd64 arch
ifeq ($(GOOS),windows)
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_LDFLAGS="-static" make cli-builder
else ifeq ($(GOOS),linux)
CGO_ENABLED=1 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ CGO_LDFLAGS="-static" TAGS=musl make cli-builder
else # build for Darwin/amd64
CGO_ENABLED=1 make cli-builder
endif
endif
.PHONY: cli-builder
cli-builder:
@TAGS=$(TAGS) CGO_ENABLED=$(CGO_ENABLED) CC=$(CC) CXX=$(CXX) CGO_LDFLAGS=$(CGO_LDFLAGS) VERSION=$(VERSION) goreleaser build -f .goreleaser-build.yml --rm-dist --single-target --snapshot
include ./mk-files/dockerhub.mk
include ./mk-files/semver.mk
include ./mk-files/docs.mk
include ./mk-files/release.mk
include ./mk-files/release-test.mk
include ./mk-files/release-notes.mk
include ./mk-files/unrelease.mk
include ./mk-files/usage.mk
include ./mk-files/utils.mk
REF := $(shell [ -d .git ] && git rev-parse --short HEAD || echo "none")
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
RESOLVED_PATH=github.com/confluentinc/cli/cmd/confluent
S3_BUCKET_PATH=s3://confluent.cloud
S3_STAG_FOLDER_NAME=cli-release-stag
S3_STAG_PATH=s3://confluent.cloud/$(S3_STAG_FOLDER_NAME)
.PHONY: clean
clean:
@for dir in bin dist docs legal release-notes; do \
[ -d $$dir ] && rm -r $$dir || true ; \
done
.PHONY: deps
deps:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 && \
go install github.com/google/go-licenses@v1.5.0 && \
go install github.com/goreleaser/goreleaser@v1.14.1 && \
go install gotest.tools/gotestsum@v1.8.2
show-args:
@echo "VERSION: $(VERSION)"
.PHONY: build-integ-nonrace
build-integ-nonrace:
go test ./cmd/confluent -ldflags="-s -w \
-X $(RESOLVED_PATH).commit=$(REF) \
-X $(RESOLVED_PATH).date=$(DATE) \
-X $(RESOLVED_PATH).version=$(VERSION) \
-X $(RESOLVED_PATH).isTest=true" \
-tags testrunmain -coverpkg=./... -c -o bin/confluent_test
.PHONY: build-integ-race
build-integ-race:
go test ./cmd/confluent -ldflags="-s -w \
-X $(RESOLVED_PATH).commit=$(REF) \
-X $(RESOLVED_PATH).date=$(DATE) \
-X $(RESOLVED_PATH).version=$(VERSION) \
-X $(RESOLVED_PATH).isTest=true" \
-tags testrunmain -coverpkg=./... -c -o bin/confluent_test_race -race
.PHONY: build-integ-nonrace-windows
build-integ-nonrace-windows:
go test ./cmd/confluent -ldflags="-s -w \
-X $(RESOLVED_PATH).commit=12345678 \
-X $(RESOLVED_PATH).date=2000-01-01T00:00:00Z \
-X $(RESOLVED_PATH).version=$(VERSION) \
-X $(RESOLVED_PATH).isTest=true" \
-tags testrunmain -coverpkg=./... -c -o bin/confluent_test.exe
.PHONY: build-integ-race-windows
build-integ-race-windows:
go test ./cmd/confluent -ldflags="-s -w \
-X $(RESOLVED_PATH).commit=12345678 \
-X $(RESOLVED_PATH).date=2000-01-01T00:00:00Z \
-X $(RESOLVED_PATH).version=$(VERSION) \
-X $(RESOLVED_PATH).isTest=true" \
-tags testrunmain -coverpkg=./... -c -o bin/confluent_test_race.exe -race
# If you setup your laptop following https://github.com/confluentinc/cc-documentation/blob/master/Operations/Laptop%20Setup.md
# then assuming caas.sh lives here should be fine
define aws-authenticate
source ~/git/go/src/github.com/confluentinc/cc-dotfiles/caas.sh && if ! aws sts get-caller-identity; then eval $$(gimme-aws-creds --output-format export --roles "arn:aws:iam::050879227952:role/administrator"); fi
endef
.PHONY: fmt
fmt:
@goimports -e -l -local github.com/confluentinc/cli/ -w $(ALL_SRC)
.PHONY: lint
lint:
make lint-go
make lint-cli
.PHONY: lint-go
lint-go:
@golangci-lint run --timeout=10m
@echo "✅ golangci-lint"
.PHONY: lint-cli
lint-cli: cmd/lint/en_US.aff cmd/lint/en_US.dic
@go run cmd/lint/main.go -aff-file $(word 1,$^) -dic-file $(word 2,$^) $(ARGS)
@echo "✅ cmd/lint/main.go"
cmd/lint/en_US.aff:
curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.aff?format=TEXT" | base64 -D > $@
cmd/lint/en_US.dic:
curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.dic?format=TEXT" | base64 -D > $@
.PHONY: lint-licenses
lint-licenses:
go-licenses check ./...
.PHONY: unit-test
unit-test:
ifdef CI
gotestsum --junitfile unit-test-report.xml -- -v -race $$(go list ./... | grep -v test)
else
go test -v -race $$(go list ./... | grep -v test) $(UNIT_TEST_ARGS)
endif
.PHONY: int-test
int-test:
ifdef CI
gotestsum --junitfile integration-test-report.xml -- -v -race $$(go list ./... | grep test)
cat integration-test-report.xml
else
go test -v -race $$(go list ./... | grep test) $(INT_TEST_ARGS)
endif
.PHONY: test
test: unit-test int-test
.PHONY: generate-packaging-patch
generate-packaging-patch:
diff -u Makefile debian/Makefile | sed "1 s_Makefile_cli/Makefile_" > debian/patches/standard_build_layout.patch