|
| 1 | +BINDIR := $(CURDIR)/bin |
| 2 | +DIST_DIRS := find * -type d -exec |
| 3 | +TARGETS := darwin/amd64 linux/amd64#linux/386 linux/arm linux/arm64 linux/ppc64le windows/amd64 |
| 4 | +BINNAME ?= elasticcopy |
| 5 | + |
| 6 | +GOPATH = $(shell go env GOPATH) |
| 7 | +DEP = $(GOPATH)/bin/dep |
| 8 | +GOX = $(GOPATH)/bin/gox |
| 9 | +GOIMPORTS = $(GOPATH)/bin/goimports |
| 10 | +NAMESPACE = github.com/ebuildy/elastic-copy |
| 11 | + |
| 12 | +ACCEPTANCE_DIR:=$(GOPATH)/src/helm.sh/acceptance-testing |
| 13 | +# To specify the subset of acceptance tests to run. '.' means all tests |
| 14 | +ACCEPTANCE_RUN_TESTS=. |
| 15 | + |
| 16 | +# go option |
| 17 | +PKG := ./... |
| 18 | +TAGS := |
| 19 | +TESTS := . |
| 20 | +TESTFLAGS := |
| 21 | +LDFLAGS := -w -s |
| 22 | +GOFLAGS := |
| 23 | +SRC := $(shell find . -type f -name '*.go' -print) |
| 24 | + |
| 25 | +# Required for globs to work correctly |
| 26 | +SHELL = /bin/bash |
| 27 | + |
| 28 | +GIT_COMMIT = $(shell git rev-parse HEAD) |
| 29 | +GIT_SHA = $(shell git rev-parse --short HEAD) |
| 30 | +GIT_TAG = $(shell git describe --tags --abbrev=0 2>/dev/null) |
| 31 | +GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean") |
| 32 | + |
| 33 | +ifdef VERSION |
| 34 | + BINARY_VERSION = $(VERSION) |
| 35 | +endif |
| 36 | +BINARY_VERSION ?= ${GIT_TAG} |
| 37 | + |
| 38 | +# Only set Version if building a tag or VERSION is set |
| 39 | +ifneq ($(BINARY_VERSION),) |
| 40 | + LDFLAGS += -X /internal/version.version=${BINARY_VERSION} |
| 41 | +endif |
| 42 | + |
| 43 | +# Clear the "unreleased" string in BuildMetadata |
| 44 | +ifneq ($(GIT_TAG),) |
| 45 | + LDFLAGS += -X ${NAMESPACE}/internal/version.metadata= |
| 46 | +endif |
| 47 | +LDFLAGS += -X ${NAMESPACE}/internal/version.gitCommit=${GIT_COMMIT} |
| 48 | +LDFLAGS += -X ${NAMESPACE}/internal/version.gitTreeState=${GIT_DIRTY} |
| 49 | + |
| 50 | +.PHONY: all |
| 51 | +all: build |
| 52 | + |
| 53 | +# ------------------------------------------------------------------------------ |
| 54 | +# build |
| 55 | + |
| 56 | +.PHONY: build |
| 57 | +build: $(BINDIR)/$(BINNAME) |
| 58 | + |
| 59 | +$(BINDIR)/$(BINNAME): $(SRC) |
| 60 | + GO111MODULE=on go build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) . |
| 61 | + |
| 62 | +# ------------------------------------------------------------------------------ |
| 63 | +# test |
| 64 | + |
| 65 | +.PHONY: test |
| 66 | +test: build |
| 67 | +test: TESTFLAGS += -race -v |
| 68 | +test: test-style |
| 69 | +test: test-unit |
| 70 | + |
| 71 | +.PHONY: test-unit |
| 72 | +test-unit: |
| 73 | + @echo |
| 74 | + @echo "==> Running unit tests <==" |
| 75 | + GO111MODULE=on go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS) |
| 76 | + |
| 77 | +.PHONY: test-coverage |
| 78 | +test-coverage: |
| 79 | + @echo |
| 80 | + @echo "==> Running unit tests with coverage <==" |
| 81 | + @ ./.ci/scripts/coverage.sh |
| 82 | + |
| 83 | +.PHONY: test-acceptance |
| 84 | +test-acceptance: TARGETS = linux/amd64 |
| 85 | +test-acceptance: build build-cross |
| 86 | + @if [ -d "${ACCEPTANCE_DIR}" ]; then \ |
| 87 | + cd ${ACCEPTANCE_DIR} && \ |
| 88 | + ROBOT_RUN_TESTS=$(ACCEPTANCE_RUN_TESTS) ROBOT_HELM_PATH=$(BINDIR) make acceptance; \ |
| 89 | + else \ |
| 90 | + echo "You must clone the acceptance_testing repo under $(ACCEPTANCE_DIR)"; \ |
| 91 | + echo "You can find the acceptance_testing repo at https://github.com/helm/acceptance-testing"; \ |
| 92 | + fi |
| 93 | + |
| 94 | +.PHONY: test-acceptance-completion |
| 95 | +test-acceptance-completion: ACCEPTANCE_RUN_TESTS = shells.robot |
| 96 | +test-acceptance-completion: test-acceptance |
| 97 | + |
| 98 | +.PHONY: coverage |
| 99 | +coverage: |
| 100 | + @scripts/coverage.sh |
| 101 | + |
| 102 | +.PHONY: format |
| 103 | +format: $(GOIMPORTS) |
| 104 | + GO111MODULE=on go list -f '{{.Dir}}' ./... | xargs $(GOIMPORTS) -w -local ${NAMESPACE} |
| 105 | + |
| 106 | +# ------------------------------------------------------------------------------ |
| 107 | +# dependencies |
| 108 | + |
| 109 | +# If go get is run from inside the project directory it will add the dependencies |
| 110 | +# to the go.mod file. To avoid that we change to a directory without a go.mod file |
| 111 | +# when downloading the following dependencies |
| 112 | + |
| 113 | +$(GOX): |
| 114 | + (cd /; GO111MODULE=on go get -u github.com/mitchellh/gox) |
| 115 | + |
| 116 | +$(GOIMPORTS): |
| 117 | + (cd /; GO111MODULE=on go get -u golang.org/x/tools/cmd/goimports) |
| 118 | + |
| 119 | +# ------------------------------------------------------------------------------ |
| 120 | +# release |
| 121 | + |
| 122 | +.PHONY: build-cross |
| 123 | +build-cross: LDFLAGS += -extldflags "-static" |
| 124 | +build-cross: $(GOX) |
| 125 | + GO111MODULE=on CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' . |
| 126 | + |
| 127 | +.PHONY: dist |
| 128 | +dist: |
| 129 | + ( \ |
| 130 | + cd _dist && \ |
| 131 | + $(DIST_DIRS) cp ../LICENSE {} \; && \ |
| 132 | + $(DIST_DIRS) cp ../README.md {} \; && \ |
| 133 | + $(DIST_DIRS) tar -zcf ${BINNAME}-${BINARY_VERSION}-{}.tar.gz {} \; && \ |
| 134 | + $(DIST_DIRS) zip -r ${BINNAME}-${BINARY_VERSION}-{}.zip {} \; \ |
| 135 | + ) |
| 136 | + |
| 137 | +.PHONY: checksum |
| 138 | +checksum: |
| 139 | + for f in _dist/*.{gz,zip} ; do \ |
| 140 | + shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256" ; \ |
| 141 | + done |
| 142 | + |
| 143 | +# ------------------------------------------------------------------------------ |
| 144 | + |
| 145 | +.PHONY: clean |
| 146 | +clean: |
| 147 | + @rm -rf $(BINDIR) ./_dist |
| 148 | + |
| 149 | +.PHONY: info |
| 150 | +info: |
| 151 | + @echo "Version: ${BINARY_VERSION}" |
| 152 | + @echo "Git Tag: ${GIT_TAG}" |
| 153 | + @echo "Git Commit: ${GIT_COMMIT}" |
| 154 | + @echo "Git Tree State: ${GIT_DIRTY}" |
0 commit comments