github.com/SUSE/skuba@v1.4.17/Makefile (about) 1 GO ?= GO111MODULE=on go 2 3 GOMODFLAG ?= 4 5 #retrieve go version details for version check 6 GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') 7 GO_VERSION_MAJ := $(shell echo $(GO_VERSION) | cut -f1 -d'.') 8 GO_VERSION_MIN := $(shell echo $(GO_VERSION) | cut -f2 -d'.') 9 10 GOFMT ?= gofmt 11 TERRAFORM ?= $(shell which terraform 2>/dev/null || which true 2>/dev/null) 12 GO_MD2MAN ?= go-md2man 13 LN = ln 14 RM = rm 15 16 BINPATH := $(abspath ./bin) 17 GOBINPATH := $(shell $(GO) env GOPATH)/bin 18 COMMIT := $(shell git rev-parse HEAD) 19 BUILD_DATE := $(shell date +%Y%m%d) 20 # TAG can be provided as an envvar (provided in the .spec file) 21 TAG ?= $(shell git describe --tags --exact-match HEAD 2> /dev/null) 22 # CLOSEST_TAG can be provided as an envvar (provided in the .spec file) 23 CLOSEST_TAG ?= $(shell git describe --tags) 24 # VERSION is inferred from CLOSEST_TAG 25 # It accepts tags of type `vX.Y.Z`, `vX.Y.Z-(alpha|beta|rc|...)` and produces X.Y.Z 26 VERSION := $(shell echo $(CLOSEST_TAG) | sed -E 's/v(([0-9]\.?)+).*/\1/') 27 TAGS := development 28 PROJECT_PATH := github.com/SUSE/skuba 29 SKUBA_LDFLAGS = -ldflags "-X=$(PROJECT_PATH)/pkg/skuba.Version=$(VERSION) \ 30 -X=$(PROJECT_PATH)/pkg/skuba.BuildDate=$(BUILD_DATE) \ 31 -X=$(PROJECT_PATH)/pkg/skuba.Tag=$(TAG) \ 32 -X=$(PROJECT_PATH)/pkg/skuba.ClosestTag=$(CLOSEST_TAG)" 33 34 SKUBA_DIRS = cmd pkg internal 35 36 # go source files, ignore vendor directory 37 SKUBA_SRCS = $(shell find $(SKUBA_DIRS) -type f -name '*.go') 38 39 .PHONY: all 40 all: install 41 42 .PHONY: build 43 build: go-version-check 44 $(GO) build $(GOMODFLAG) $(SKUBA_LDFLAGS) -tags $(TAGS) ./cmd/... 45 46 MANPAGES_MD := $(wildcard docs/man/*.md) 47 MANPAGES := $(MANPAGES_MD:%.md=%) 48 49 docs/man/%.1: docs/man/%.1.md 50 $(GO_MD2MAN) -in $< -out $@ 51 52 .PHONY: docs 53 docs: $(MANPAGES) 54 55 .PHONY: install 56 install: go-version-check 57 $(GO) install $(GOMODFLAG) $(SKUBA_LDFLAGS) -tags $(TAGS) ./cmd/... 58 $(RM) -f $(GOBINPATH)/kubectl-caasp 59 $(LN) -s $(GOBINPATH)/skuba $(GOBINPATH)/kubectl-caasp 60 61 .PHONY: clean 62 clean: 63 $(GO) clean -i ./... 64 $(RM) -f ./skuba 65 $(RM) -rf $(BINPATH) 66 67 .PHONY: distclean 68 distclean: clean 69 $(GO) clean -i -cache -testcache -modcache ./... 70 71 .PHONY: staging 72 staging: 73 make TAGS=staging install 74 75 .PHONY: release 76 release: 77 make TAGS=release install 78 79 .PHONY: go-version-check 80 go-version-check: 81 @[ $(GO_VERSION_MAJ) -ge 2 ] || \ 82 [ $(GO_VERSION_MAJ) -eq 1 -a $(GO_VERSION_MIN) -ge 12 ] || (echo "FATAL: Go version should be >= 1.12.x" ; exit 1 ; ) 83 84 .PHONY: lint 85 lint: deps 86 # explicitly enable GO111MODULE otherwise go mod will fail 87 GO111MODULE=on go mod tidy && GO111MODULE=on go mod verify 88 # run go vet 89 $(GO) vet ./... 90 # run go gmt 91 test -z `$(GOFMT) -l $(SKUBA_SRCS)` || { $(GOFMT) -d $(SKUBA_SRCS) && false; } 92 # check terraform fmt 93 $(TERRAFORM) fmt -check=true -write=false -diff=true ci/infra 94 # run golangci-lint 95 $(BINPATH)/golangci-lint run --verbose --timeout=3m 96 # run bash linter 97 find ci -type f -name "*.sh" | xargs $(BINPATH)/shellcheck 98 99 .PHONY: deps 100 deps: 101 test -f $(BINPATH)/golangci-lint || curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BINPATH) v1.21.0 102 test -f $(BINPATH)/shellcheck || curl -sfL "https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.x86_64.tar.xz" | tar -xJv --strip-components=1 -C $(BINPATH) 103 104 .PHONY: pre-commit-install 105 pre-commit-install: 106 test -f $(BINPATH)/bin/pre-commit || curl -sfL https://pre-commit.com/install-local.py | HOME=$(BINPATH) python - 107 $(BINPATH)/bin/pre-commit install 108 109 .PHONY: pre-commit-uninstall 110 pre-commit-uninstall: 111 test -f $(BINPATH)/bin/pre-commit || curl -sfL https://pre-commit.com/install-local.py | HOME=$(BINPATH) python - 112 $(BINPATH)/bin/pre-commit uninstall 113 114 .PHONY: suse-package 115 suse-package: 116 ci/packaging/suse/rpmfiles_maker.sh "$(VERSION)" "$(TAG)" "$(CLOSEST_TAG)" 117 118 .PHONY: suse-changelog 119 suse-changelog: 120 ci/packaging/suse/changelog_maker.sh "$(CHANGES)" 121 122 # tests 123 .PHONY: test 124 test: test-unit test-bench 125 126 .PHONY: test-unit 127 test-unit: 128 $(GO) test $(GOMODFLAG) -coverprofile=coverage.out $(PROJECT_PATH)/{cmd,pkg,internal}/... 129 130 .PHONY: test-unit-coverage 131 test-unit-coverage: test-unit 132 $(GO) tool cover -html=coverage.out 133 134 .PHONY: test-bench 135 test-bench: 136 $(GO) test $(GOMODFLAG) -bench=. $(PROJECT_PATH)/{cmd,pkg,internal}/...