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