github.com/confluentinc/cli@v1.100.0/Makefile (about) 1 SHELL := /bin/bash 2 ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor) 3 GIT_REMOTE_NAME ?= origin 4 MASTER_BRANCH ?= master 5 RELEASE_BRANCH ?= master 6 7 DOCS_BRANCH ?= 5.5.1-post 8 9 include ./mk-files/semver.mk 10 include ./mk-files/release.mk 11 include ./mk-files/release-notes.mk 12 include ./mk-files/unrelease.mk 13 14 REF := $(shell [ -d .git ] && git rev-parse --short HEAD || echo "none") 15 DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") 16 HOSTNAME := $(shell id -u -n)@$(shell hostname) 17 RESOLVED_PATH=github.com/confluentinc/cli/cmd/confluent 18 19 S3_BUCKET_PATH=s3://confluent.cloud 20 S3_RELEASE_TEST_FOLDER=cli-release-test 21 ifeq (true, $(RELEASE_TEST)) 22 $(warning IN RELEASE_TEST=true MODE) 23 S3_BUCKET_PATH=s3://confluent.cloud/$(S3_RELEASE_TEST_FOLDER) 24 $(warning Release test S3_BUCKET_PATH=$(S3_BUCKET_PATH)) 25 endif 26 27 28 .PHONY: clean 29 clean: 30 rm -rf $(shell pwd)/dist 31 32 .PHONY: generate 33 generate: 34 @go generate ./... 35 36 .PHONY: deps 37 deps: 38 export GONOSUMDB=github.com/confluentinc,github.com/golangci/go-misc && \ 39 export GO111MODULE=on && \ 40 export GOPRIVATE=github.com/confluentinc && \ 41 go get github.com/goreleaser/goreleaser@v0.142.0 && \ 42 go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.21.0 && \ 43 go get github.com/mitchellh/golicense@v0.1.1 44 45 ifeq ($(shell uname),Darwin) 46 GORELEASER_SUFFIX ?= -mac.yml 47 SHASUM ?= gsha256sum 48 else ifneq (,$(findstring NT,$(shell uname))) 49 GORELEASER_SUFFIX ?= -windows.yml 50 # TODO: I highly doubt this works. Completely untested. The output format is likely very different than expected. 51 SHASUM ?= CertUtil SHA256 -hashfile 52 else 53 GORELEASER_SUFFIX ?= -linux.yml 54 SHASUM ?= sha256sum 55 endif 56 57 show-args: 58 @echo "VERSION: $(VERSION)" 59 60 # 61 # START DEVELOPMENT HELPERS 62 # Usage: make run-ccloud -- version 63 # make run-ccloud -- --version 64 # 65 66 # If the first argument is "run-ccloud"... 67 ifeq (run-ccloud,$(firstword $(MAKECMDGOALS))) 68 # use the rest as arguments for "run-ccloud" 69 RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) 70 # ...and turn them into do-nothing targets 71 $(eval $(RUN_ARGS):;@:) 72 endif 73 74 # If the first argument is "run-confluent"... 75 ifeq (run-confluent,$(firstword $(MAKECMDGOALS))) 76 # use the rest as arguments for "run-confluent" 77 RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) 78 # ...and turn them into do-nothing targets 79 $(eval $(RUN_ARGS):;@:) 80 endif 81 82 .PHONY: run-ccloud 83 run-ccloud: 84 @go run -ldflags '-X main.cliName=ccloud' cmd/confluent/main.go $(RUN_ARGS) 85 86 .PHONY: run-confluent 87 run-confluent: 88 @go run -ldflags '-X main.cliName=confluent' cmd/confluent/main.go $(RUN_ARGS) 89 90 # 91 # END DEVELOPMENT HELPERS 92 # 93 94 .PHONY: build 95 build: 96 make build-ccloud 97 make build-confluent 98 99 .PHONY: build-ccloud 100 build-ccloud: 101 @GO111MODULE=on GOPRIVATE=github.com/confluentinc GONOSUMDB=github.com/confluentinc,github.com/golangci/go-misc VERSION=$(VERSION) HOSTNAME="$(HOSTNAME)" goreleaser release --snapshot --rm-dist -f .goreleaser-ccloud$(GORELEASER_SUFFIX) 102 103 .PHONY: build-confluent 104 build-confluent: 105 @GO111MODULE=on GOPRIVATE=github.com/confluentinc GONOSUMDB=github.com/confluentinc,github.com/golangci/go-misc VERSION=$(VERSION) HOSTNAME="$(HOSTNAME)" goreleaser release --snapshot --rm-dist -f .goreleaser-confluent$(GORELEASER_SUFFIX) 106 107 .PHONY: build-integ 108 build-integ: 109 make build-integ-nonrace 110 make build-integ-race 111 112 .PHONY: build-integ-nonrace 113 build-integ-nonrace: 114 make build-integ-ccloud-nonrace 115 make build-integ-confluent-nonrace 116 117 .PHONY: build-integ-ccloud-nonrace 118 build-integ-ccloud-nonrace: 119 binary="ccloud_test" ; \ 120 [ "$${OS}" = "Windows_NT" ] && binexe=$${binary}.exe || binexe=$${binary} ; \ 121 GO111MODULE=on go test ./cmd/confluent -ldflags="-s -w -X $(RESOLVED_PATH).cliName=ccloud \ 122 -X $(RESOLVED_PATH).commit=$(REF) -X $(RESOLVED_PATH).host=$(HOSTNAME) -X $(RESOLVED_PATH).date=$(DATE) \ 123 -X $(RESOLVED_PATH).version=$(VERSION) -X $(RESOLVED_PATH).isTest=true" -tags testrunmain -coverpkg=./... -c -o $${binexe} 124 125 .PHONY: build-integ-confluent-nonrace 126 build-integ-confluent-nonrace: 127 binary="confluent_test" ; \ 128 [ "$${OS}" = "Windows_NT" ] && binexe=$${binary}.exe || binexe=$${binary} ; \ 129 GO111MODULE=on go test ./cmd/confluent -ldflags="-s -w -X $(RESOLVED_PATH).cliName=confluent \ 130 -X $(RESOLVED_PATH).commit=$(REF) -X $(RESOLVED_PATH).host=$(HOSTNAME) -X $(RESOLVED_PATH).date=$(DATE) \ 131 -X $(RESOLVED_PATH).version=$(VERSION) -X $(RESOLVED_PATH).isTest=true" -tags testrunmain -coverpkg=./... -c -o $${binexe} 132 133 .PHONY: build-integ-race 134 build-integ-race: 135 make build-integ-ccloud-race 136 make build-integ-confluent-race 137 138 .PHONY: build-integ-ccloud-race 139 build-integ-ccloud-race: 140 binary="ccloud_test_race" ; \ 141 [ "$${OS}" = "Windows_NT" ] && binexe=$${binary}.exe || binexe=$${binary} ; \ 142 GO111MODULE=on go test ./cmd/confluent -ldflags="-s -w -X $(RESOLVED_PATH).cliName=ccloud \ 143 -X $(RESOLVED_PATH).commit=$(REF) -X $(RESOLVED_PATH).host=$(HOSTNAME) -X $(RESOLVED_PATH).date=$(DATE) \ 144 -X $(RESOLVED_PATH).version=$(VERSION) -X $(RESOLVED_PATH).isTest=true" -tags testrunmain -coverpkg=./... -c -o $${binexe} -race 145 146 .PHONY: build-integ-confluent-race 147 build-integ-confluent-race: 148 binary="confluent_test_race" ; \ 149 [ "$${OS}" = "Windows_NT" ] && binexe=$${binary}.exe || binexe=$${binary} ; \ 150 GO111MODULE=on go test ./cmd/confluent -ldflags="-s -w -X $(RESOLVED_PATH).cliName=confluent \ 151 -X $(RESOLVED_PATH).commit=$(REF) -X $(RESOLVED_PATH).host=$(HOSTNAME) -X $(RESOLVED_PATH).date=$(DATE) \ 152 -X $(RESOLVED_PATH).version=$(VERSION) -X $(RESOLVED_PATH).isTest=true" -tags testrunmain -coverpkg=./... -c -o $${binexe} -race 153 154 # If you setup your laptop following https://github.com/confluentinc/cc-documentation/blob/master/Operations/Laptop%20Setup.md 155 # then assuming caas.sh lives here should be fine 156 define caasenv-authenticate 157 source $$GOPATH/src/github.com/confluentinc/cc-dotfiles/caas.sh && caasenv prod 158 endef 159 160 .PHONY: fmt 161 fmt: 162 @goimports -e -l -local github.com/confluentinc/cli/ -w $(ALL_SRC) 163 164 .PHONY: release-ci 165 release-ci: 166 ifneq ($(SEMAPHORE_GIT_PR_BRANCH),) 167 true 168 else ifeq ($(SEMAPHORE_GIT_BRANCH),master) 169 make release 170 else 171 true 172 endif 173 174 cmd/lint/en_US.aff: 175 @curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.aff?format=TEXT" | base64 -D > $@ 176 177 cmd/lint/en_US.dic: 178 @curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.dic?format=TEXT" | base64 -D > $@ 179 180 .PHONY: lint-cli 181 lint-cli: cmd/lint/en_US.aff cmd/lint/en_US.dic 182 @GO111MODULE=on go run cmd/lint/main.go -aff-file $(word 1,$^) -dic-file $(word 2,$^) $(ARGS) 183 184 .PHONY: lint-go 185 lint-go: 186 @GO111MODULE=on golangci-lint run --timeout=10m 187 188 .PHONY: lint 189 lint: lint-go lint-cli lint-installers 190 191 .PHONY: lint-installers 192 ## Lints the CLI installation scripts 193 lint-installers: 194 @diff install-c* | grep -v -E "^---|^[0-9c0-9]|PROJECT_NAME|BINARY" && echo "diff between install scripts" && exit 1 || exit 0 195 196 .PHONY: lint-licenses 197 ## Scan and validate third-party dependeny licenses 198 lint-licenses: build 199 $(eval token := $(shell (grep github.com ~/.netrc -A 2 | grep password || grep github.com ~/.netrc -A 2 | grep login) | head -1 | awk -F' ' '{ print $$2 }')) 200 @for binary in ccloud confluent; do \ 201 echo Licenses for $${binary} binary ; \ 202 [ -t 0 ] && args="" || args="-plain" ; \ 203 GITHUB_TOKEN=$(token) golicense $${args} .golicense.hcl ./dist/$${binary}/$(shell go env GOOS)_$(shell go env GOARCH)/$${binary} ; \ 204 echo ; \ 205 done 206 207 .PHONY: coverage-unit 208 coverage-unit: 209 ifdef CI 210 @# Run unit tests with coverage. 211 @GO111MODULE=on GOPRIVATE=github.com/confluentinc go test -v -race -coverpkg=$$(go list ./... | grep -v test | grep -v mock | tr '\n' ',' | sed 's/,$$//g') -coverprofile=unit_coverage.txt $$(go list ./... | grep -v vendor | grep -v test) $(UNIT_TEST_ARGS) 212 @grep -h -v "mode: atomic" unit_coverage.txt >> coverage.txt 213 else 214 @# Run unit tests. 215 @GO111MODULE=on GOPRIVATE=github.com/confluentinc go test -race -coverpkg=./... $$(go list ./... | grep -v vendor | grep -v test) $(UNIT_TEST_ARGS) 216 endif 217 218 .PHONY: coverage-integ 219 coverage-integ: 220 ifdef CI 221 @# Run integration tests with coverage. 222 @GO111MODULE=on INTEG_COVER=on go test -v $$(go list ./... | grep cli/test) $(INT_TEST_ARGS) -timeout 15m 223 @grep -h -v "mode: atomic" integ_coverage.txt >> coverage.txt 224 else 225 @# Run integration tests. 226 @GO111MODULE=on GOPRIVATE=github.com/confluentinc go test -v -race $$(go list ./... | grep cli/test) $(INT_TEST_ARGS) -timeout 15m 227 endif 228 229 .PHONY: test-installers 230 test-installers: 231 @echo Running packaging/installer tests 232 @bash test-installers.sh 233 234 .PHONY: test-prep 235 test-prep: lint 236 ifdef CI 237 @echo "mode: atomic" > coverage.txt 238 endif 239 240 .PHONY: test 241 test: test-prep coverage-unit coverage-integ test-installers 242 243 .PHONY: unit-test 244 unit-test: test-prep coverage-unit 245 246 .PHONY: int-test 247 int-test: test-prep coverage-integ 248 249 .PHONY: doctoc 250 doctoc: 251 npx doctoc README.md 252