github.com/loafoe/helm@v1.0.1/Makefile (about)

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