...
1BINDIR := $(CURDIR)/bin
2INSTALL_PATH ?= /usr/local/bin
3DIST_DIRS := find * -type d -exec
4TARGETS := darwin/amd64 darwin/arm64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x linux/riscv64 windows/amd64
5TARGET_OBJS ?= darwin-amd64.tar.gz darwin-amd64.tar.gz.sha256 darwin-amd64.tar.gz.sha256sum darwin-arm64.tar.gz darwin-arm64.tar.gz.sha256 darwin-arm64.tar.gz.sha256sum linux-amd64.tar.gz linux-amd64.tar.gz.sha256 linux-amd64.tar.gz.sha256sum linux-386.tar.gz linux-386.tar.gz.sha256 linux-386.tar.gz.sha256sum linux-arm.tar.gz linux-arm.tar.gz.sha256 linux-arm.tar.gz.sha256sum linux-arm64.tar.gz linux-arm64.tar.gz.sha256 linux-arm64.tar.gz.sha256sum linux-ppc64le.tar.gz linux-ppc64le.tar.gz.sha256 linux-ppc64le.tar.gz.sha256sum linux-s390x.tar.gz linux-s390x.tar.gz.sha256 linux-s390x.tar.gz.sha256sum linux-riscv64.tar.gz linux-riscv64.tar.gz.sha256 linux-riscv64.tar.gz.sha256sum windows-amd64.zip windows-amd64.zip.sha256 windows-amd64.zip.sha256sum
6BINNAME ?= helm
7
8GOBIN = $(shell go env GOBIN)
9ifeq ($(GOBIN),)
10GOBIN = $(shell go env GOPATH)/bin
11endif
12GOX = $(GOBIN)/gox
13GOIMPORTS = $(GOBIN)/goimports
14ARCH = $(shell go env GOARCH)
15
16ACCEPTANCE_DIR:=../acceptance-testing
17# To specify the subset of acceptance tests to run. '.' means all tests
18ACCEPTANCE_RUN_TESTS=.
19
20# go option
21PKG := ./...
22TAGS :=
23TESTS := .
24TESTFLAGS :=
25LDFLAGS := -w -s
26GOFLAGS :=
27CGO_ENABLED ?= 0
28
29# Rebuild the binary if any of these files change
30SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum
31
32# Required for globs to work correctly
33SHELL = /usr/bin/env bash
34
35GIT_COMMIT = $(shell git rev-parse HEAD)
36GIT_SHA = $(shell git rev-parse --short HEAD)
37GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
38GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
39
40ifdef VERSION
41 BINARY_VERSION = $(VERSION)
42endif
43BINARY_VERSION ?= ${GIT_TAG}
44
45# Only set Version if building a tag or VERSION is set
46ifneq ($(BINARY_VERSION),)
47 LDFLAGS += -X helm.sh/helm/v3/internal/version.version=${BINARY_VERSION}
48endif
49
50VERSION_METADATA = unreleased
51# Clear the "unreleased" string in BuildMetadata
52ifneq ($(GIT_TAG),)
53 VERSION_METADATA =
54endif
55
56LDFLAGS += -X helm.sh/helm/v3/internal/version.metadata=${VERSION_METADATA}
57LDFLAGS += -X helm.sh/helm/v3/internal/version.gitCommit=${GIT_COMMIT}
58LDFLAGS += -X helm.sh/helm/v3/internal/version.gitTreeState=${GIT_DIRTY}
59LDFLAGS += $(EXT_LDFLAGS)
60
61# Define constants based on the client-go version
62K8S_MODULES_VER=$(subst ., ,$(subst v,,$(shell go list -f '{{.Version}}' -m k8s.io/client-go)))
63K8S_MODULES_MAJOR_VER=$(shell echo $$(($(firstword $(K8S_MODULES_VER)) + 1)))
64K8S_MODULES_MINOR_VER=$(word 2,$(K8S_MODULES_VER))
65
66LDFLAGS += -X helm.sh/helm/v3/pkg/lint/rules.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
67LDFLAGS += -X helm.sh/helm/v3/pkg/lint/rules.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
68LDFLAGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
69LDFLAGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
70
71.PHONY: all
72all: build
73
74# ------------------------------------------------------------------------------
75# build
76
77.PHONY: build
78build: $(BINDIR)/$(BINNAME)
79
80$(BINDIR)/$(BINNAME): $(SRC)
81 GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/helm
82
83# ------------------------------------------------------------------------------
84# install
85
86.PHONY: install
87install: build
88 @install "$(BINDIR)/$(BINNAME)" "$(INSTALL_PATH)/$(BINNAME)"
89
90# ------------------------------------------------------------------------------
91# test
92
93.PHONY: test
94test: build
95ifeq ($(ARCH),s390x)
96test: TESTFLAGS += -v
97else
98test: TESTFLAGS += -race -v
99endif
100test: test-style
101test: test-unit
102
103.PHONY: test-unit
104test-unit:
105 @echo
106 @echo "==> Running unit tests <=="
107 GO111MODULE=on go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS)
108
109.PHONY: test-coverage
110test-coverage:
111 @echo
112 @echo "==> Running unit tests with coverage <=="
113 @ ./scripts/coverage.sh
114
115.PHONY: test-style
116test-style:
117 golangci-lint run ./...
118 @scripts/validate-license.sh
119
120.PHONY: test-source-headers
121test-source-headers:
122 @scripts/validate-license.sh
123
124.PHONY: test-acceptance
125test-acceptance: TARGETS = linux/amd64
126test-acceptance: build build-cross
127 @if [ -d "${ACCEPTANCE_DIR}" ]; then \
128 cd ${ACCEPTANCE_DIR} && \
129 ROBOT_RUN_TESTS=$(ACCEPTANCE_RUN_TESTS) ROBOT_HELM_PATH='$(BINDIR)' make acceptance; \
130 else \
131 echo "You must clone the acceptance_testing repo under $(ACCEPTANCE_DIR)"; \
132 echo "You can find the acceptance_testing repo at https://github.com/helm/acceptance-testing"; \
133 fi
134
135.PHONY: test-acceptance-completion
136test-acceptance-completion: ACCEPTANCE_RUN_TESTS = shells.robot
137test-acceptance-completion: test-acceptance
138
139.PHONY: coverage
140coverage:
141 @scripts/coverage.sh
142
143.PHONY: format
144format: $(GOIMPORTS)
145 GO111MODULE=on go list -f '{{.Dir}}' ./... | xargs $(GOIMPORTS) -w -local helm.sh/helm
146
147# Generate golden files used in unit tests
148.PHONY: gen-test-golden
149gen-test-golden:
150gen-test-golden: PKG = ./cmd/helm ./pkg/action
151gen-test-golden: TESTFLAGS = -update
152gen-test-golden: test-unit
153
154# ------------------------------------------------------------------------------
155# dependencies
156
157# If go install is run from inside the project directory it will add the
158# dependencies to the go.mod file. To avoid that we change to a directory
159# without a go.mod file when downloading the following dependencies
160
161$(GOX):
162 (cd /; GO111MODULE=on go install github.com/mitchellh/gox@v1.0.2-0.20220701044238-9f712387e2d2)
163
164$(GOIMPORTS):
165 (cd /; GO111MODULE=on go install golang.org/x/tools/cmd/goimports@latest)
166
167# ------------------------------------------------------------------------------
168# release
169
170.PHONY: build-cross
171build-cross: LDFLAGS += -extldflags "-static"
172build-cross: $(GOX)
173 GOFLAGS="-trimpath" GO111MODULE=on CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/helm
174
175.PHONY: dist
176dist:
177 ( \
178 cd _dist && \
179 $(DIST_DIRS) cp ../LICENSE {} \; && \
180 $(DIST_DIRS) cp ../README.md {} \; && \
181 $(DIST_DIRS) tar -zcf helm-${VERSION}-{}.tar.gz {} \; && \
182 $(DIST_DIRS) zip -r helm-${VERSION}-{}.zip {} \; \
183 )
184
185.PHONY: fetch-dist
186fetch-dist:
187 mkdir -p _dist
188 cd _dist && \
189 for obj in ${TARGET_OBJS} ; do \
190 curl -sSL -o helm-${VERSION}-$${obj} https://get.helm.sh/helm-${VERSION}-$${obj} ; \
191 done
192
193.PHONY: sign
194sign:
195 for f in $$(ls _dist/*.{gz,zip,sha256,sha256sum} 2>/dev/null) ; do \
196 gpg --armor --detach-sign $${f} ; \
197 done
198
199# The contents of the .sha256sum file are compatible with tools like
200# shasum. For example, using the following command will verify
201# the file helm-3.1.0-rc.1-darwin-amd64.tar.gz:
202# shasum -a 256 -c helm-3.1.0-rc.1-darwin-amd64.tar.gz.sha256sum
203# The .sha256 files hold only the hash and are not compatible with
204# verification tools like shasum or sha256sum. This method and file can be
205# removed in Helm v4.
206.PHONY: checksum
207checksum:
208 for f in $$(ls _dist/*.{gz,zip} 2>/dev/null) ; do \
209 shasum -a 256 "$${f}" | sed 's/_dist\///' > "$${f}.sha256sum" ; \
210 shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256" ; \
211 done
212
213# ------------------------------------------------------------------------------
214
215.PHONY: clean
216clean:
217 @rm -rf '$(BINDIR)' ./_dist
218
219.PHONY: release-notes
220release-notes:
221 @if [ ! -d "./_dist" ]; then \
222 echo "please run 'make fetch-dist' first" && \
223 exit 1; \
224 fi
225 @if [ -z "${PREVIOUS_RELEASE}" ]; then \
226 echo "please set PREVIOUS_RELEASE environment variable" \
227 && exit 1; \
228 fi
229
230 @./scripts/release-notes.sh ${PREVIOUS_RELEASE} ${VERSION}
231
232
233
234.PHONY: info
235info:
236 @echo "Version: ${VERSION}"
237 @echo "Git Tag: ${GIT_TAG}"
238 @echo "Git Commit: ${GIT_COMMIT}"
239 @echo "Git Tree State: ${GIT_DIRTY}"
View as plain text