|
1 |
| - |
2 |
| -# Image URL to use all building/pushing image targets |
3 |
| -IMG ?= quay.io/joelanford/helm-operator |
4 |
| - |
5 |
| -SHELL=/bin/bash |
6 |
| -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
7 |
| -ifeq (,$(shell go env GOBIN)) |
8 |
| -GOBIN=$(shell go env GOPATH)/bin |
9 |
| -else |
10 |
| -GOBIN=$(shell go env GOBIN) |
11 |
| -endif |
12 |
| - |
13 | 1 | # GO_BUILD_ARGS should be set when running 'go build' or 'go install'.
|
14 | 2 | VERSION_PKG = "$(shell go list -m)/internal/version"
|
15 | 3 | SCAFFOLD_VERSION = $(shell git describe --abbrev=0)
|
16 | 4 | GIT_VERSION = $(shell git describe --dirty --tags --always)
|
17 | 5 | GIT_COMMIT = $(shell git rev-parse HEAD)
|
| 6 | +BUILD_DIR = $(PWD)/bin |
18 | 7 | GO_BUILD_ARGS = \
|
19 | 8 | -gcflags "all=-trimpath=$(shell dirname $(shell pwd))" \
|
20 | 9 | -asmflags "all=-trimpath=$(shell dirname $(shell pwd))" \
|
21 | 10 | -ldflags " \
|
| 11 | + -s \ |
| 12 | + -w \ |
22 | 13 | -X '$(VERSION_PKG).ScaffoldVersion=$(SCAFFOLD_VERSION)' \
|
23 | 14 | -X '$(VERSION_PKG).GitVersion=$(GIT_VERSION)' \
|
24 | 15 | -X '$(VERSION_PKG).GitCommit=$(GIT_COMMIT)' \
|
25 | 16 | " \
|
26 | 17 |
|
| 18 | +# Always use Go modules |
27 | 19 | export GO111MODULE = on
|
28 | 20 |
|
| 21 | +# Setup project-local paths and build settings |
| 22 | +SHELL=/bin/bash |
| 23 | +TOOLS_DIR=$(PWD)/tools |
| 24 | +TOOLS_BIN_DIR=$(TOOLS_DIR)/bin |
| 25 | +SCRIPTS_DIR=$(TOOLS_DIR)/scripts |
| 26 | +export PATH := $(BUILD_DIR):$(TOOLS_BIN_DIR):$(SCRIPTS_DIR):$(PATH) |
| 27 | + |
| 28 | +.PHONY: all |
| 29 | +all: test lint build |
| 30 | + |
29 | 31 | # Run tests
|
30 |
| -ENVTEST_ASSETS_DIR=$(shell pwd)/testbin |
31 |
| -test: fmt vet |
32 |
| - mkdir -p ${ENVTEST_ASSETS_DIR} |
33 |
| - test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh |
34 |
| - source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test -race -covermode atomic -coverprofile cover.out ./... |
| 32 | +.PHONY: test |
| 33 | +export KUBEBUILDER_ASSETS := $(TOOLS_BIN_DIR) |
| 34 | +CR_VERSION=$(shell go list -m sigs.k8s.io/controller-runtime | cut -d" " -f2 | sed 's/^v//') |
| 35 | +test: |
| 36 | + fetch envtest $(CR_VERSION) && go test -race -covermode atomic -coverprofile cover.out ./... |
35 | 37 |
|
36 | 38 | # Build manager binary
|
37 |
| -build: fmt vet |
38 |
| - CGO_ENABLED=0 go build $(GO_BUILD_ARGS) -o bin/helm-operator main.go |
39 |
| - |
40 |
| -# Run go fmt against code |
41 |
| -fmt: |
| 39 | +.PHONY: build |
| 40 | +build: |
| 41 | + CGO_ENABLED=0 mkdir -p $(BUILD_DIR) && go build $(GO_BUILD_ARGS) -o $(BUILD_DIR) ./ |
| 42 | + |
| 43 | +# Run go fmt and go mod tidy, and check for clean git tree |
| 44 | +.PHONY: fix |
| 45 | +fix: |
| 46 | + go mod tidy |
42 | 47 | go fmt ./...
|
| 48 | + git diff --exit-code |
43 | 49 |
|
44 |
| -# Run go vet against code |
45 |
| -vet: |
46 |
| - go vet ./... |
47 |
| - |
48 |
| -lint: golangci-lint |
49 |
| - $(GOLANGCI_LINT) run |
50 |
| -lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes |
51 |
| - $(GOLANGCI_LINT) run --fix |
| 50 | +# Run various checks against code |
| 51 | +.PHONY: lint |
| 52 | +lint: |
| 53 | + fetch golangci-lint 1.35.2 && golangci-lint run |
52 | 54 |
|
53 |
| -# find or download controller-gen |
54 |
| -# download controller-gen if necessary |
55 |
| -golangci-lint: |
56 |
| -ifeq (, $(shell which golangci-lint)) |
57 |
| - @{ \ |
58 |
| - set -e ;\ |
59 |
| - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.27.0 ;\ |
60 |
| - } |
61 |
| -GOLANGCI_LINT=$(shell go env GOPATH)/bin/golangci-lint |
62 |
| -else |
63 |
| -GOLANGCI_LINT=$(shell which golangci-lint) |
64 |
| -endif |
| 55 | +.PHONY: clean |
| 56 | +clean: |
| 57 | + rm -rf $(TOOLS_BIN_DIR) $(BUILD_DIR) |
0 commit comments