1
+ # Copyright 2024 Redpanda Data, Inc.
2
+ #
3
+ # Use of this software is governed by the Business Source License
4
+ # included in the file licenses/BSL.md
5
+ #
6
+ # As of the Change Date specified in that file, in accordance with
7
+ # the Business Source License, use of this software will be governed
8
+ # by the Apache License, Version 2.0
9
+
10
+ GOCMD =go
11
+ GOLANGCILINTCMD =golangci-lint
12
+ GOFUMPTCMD =gofumpt
13
+ BAZELCMD =bazel
14
+
15
+ GOOS ?= $(shell go env GOOS)
16
+ GOARCH ?= $(shell go env GOARCH)
17
+ OUTDIR := $(GOOS ) -$(GOARCH )
18
+
19
+ REV := $(shell git rev-parse --short HEAD)
20
+ VER := $(or $(VERSION ) ,local-dev)
21
+ IMG_TAG: = $(or $(VERSION ) ,latest)
22
+ BUILD_TIME =$(shell date -Iseconds)
23
+ VER_PKG ='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version'
24
+ CONT_PKG ='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common'
25
+
26
+ LDFLAGS =-X $(VER_PKG ) .version=$(VER ) -X $(VER_PKG ) .rev=$(REV ) -X $(CONT_PKG ) .tag=$(IMG_TAG ) -X ${VER_PKG}.hostOs=${GOOS} -X ${VER_PKG}.hostArch=${GOARCH} -X ${VER_PKG}.buildTime=${BUILD_TIME}
27
+
28
+ all : help
29
+
30
+ ready : build test fmt lint bazel check_diff # # Runs all. Ensures commit is ready.
31
+
32
+ build : # # Build rpk.
33
+ $(shell mkdir -p $(OUTDIR ) )
34
+ $(GOCMD ) build -ldflags ' $(LDFLAGS)' -o $(OUTDIR ) ./...
35
+
36
+ test : # # Run rpk unit tests.
37
+ $(GOCMD ) test ./... -count=1
38
+
39
+ tidy : # # Run go mod tidy.
40
+ $(GOCMD ) mod tidy
41
+
42
+ lint : install_golangci_lint run_linter # # Run golangci-lint linter.
43
+
44
+ fmt : install_gofumpt run_gofumpt # # Run Gofumpt formatter.
45
+
46
+ bazel : install_bazelisk bazel_generate_build bazel_tidy # # Autogenerates BUILD files and resolve bazel dependencies.
47
+
48
+ install_gofumpt :
49
+ @echo " installing gofumpt..."
50
+ @$(GOCMD ) install mvdan.cc/gofumpt@latest
51
+
52
+ run_gofumpt :
53
+ @echo " running gofumpt"
54
+ $(shell find -type f -name '* .go' | xargs -n1 $(GOFUMPTCMD ) -w)
55
+
56
+ install_golangci_lint :
57
+ @echo " installing golangci-lint"
58
+ @$(GOCMD ) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
59
+
60
+ run_linter :
61
+ $(GOLANGCILINTCMD ) run
62
+
63
+ install_bazelisk :
64
+ @echo " installing bazelisk"
65
+ @$(GOCMD ) install github.com/bazelbuild/bazelisk@latest
66
+
67
+ bazel_generate_build : install_bazelisk
68
+ @$(BAZELCMD ) run //:gazelle
69
+
70
+ bazel_tidy : install_bazelisk
71
+ @$(BAZELCMD ) mod tidy
72
+
73
+ check_diff :
74
+ git diff --exit-code
75
+
76
+ GREEN := $(shell tput -Txterm setaf 2)
77
+ YELLOW := $(shell tput -Txterm setaf 3)
78
+ CYAN := $(shell tput -Txterm setaf 6)
79
+ RESET := $(shell tput -Txterm sgr0)
80
+
81
+ help : # # Show this help.
82
+ @echo ' '
83
+ @echo ' Usage:'
84
+ @echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
85
+ @echo ' '
86
+ @echo ' Targets:'
87
+ @awk ' BEGIN {FS = ":.*?## "} { \
88
+ if (/^[a-zA-Z_-]+:.*? # #.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
89
+ else if (/^# # .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
90
+ }' $(MAKEFILE_LIST)
0 commit comments