forked from fabric8-analytics/cli-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (68 loc) · 3.1 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
GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME=crda
GITCOMMIT:=$(shell git rev-parse --short HEAD)
REPO=github.com/fabric8-analytics/cli-tools
VERSION?=0.2.2
EXPORT_RESULT?=false
CGO_ENABLED:=0
LDFLAGS +=-X ${REPO}/pkg/version.timestamp=$(shell date +%s)
LDFLAGS +=-X ${REPO}/pkg/version.version=${VERSION}
LDFLAGS +=-X ${REPO}/pkg/version.commitHash=${GITCOMMIT}
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
.PHONY: all test build vendor
all: help
lint: lint-go lint-yaml
lint-go:
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS)
lint-yaml:
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
endif
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)
clean:
rm -fr $(which crda)
rm -fr ./out
rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml
test:
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
endif
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)
coverage:
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
$(GOCMD) tool cover -func profile.cov
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/AlekSi/gocov-xml
GO111MODULE=off go get -u github.com/axw/gocov/gocov
gocov convert profile.cov | gocov-xml > coverage.xml
endif
vendor:
$(GOCMD) mod vendor
build:
mkdir -p /usr/local/bin
CGO_ENABLED=$(CGO_ENABLED) $(GOCMD) build -v \
-ldflags="-s -w $(LDFLAGS)" \
-o $(BINARY_NAME)
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@echo " ${YELLOW}build ${RESET} ${GREEN}Build your project and put the output binary in /usr/local/bin/$(BINARY_NAME)${RESET}"
@echo " ${YELLOW}clean ${RESET} ${GREEN}Remove build related file${RESET}"
@echo " ${YELLOW}coverage ${RESET} ${GREEN}Run the tests of the project and export the coverage${RESET}"
@echo " ${YELLOW}help ${RESET} ${GREEN}Show this help message${RESET}"
@echo " ${YELLOW}lint ${RESET} ${GREEN}Run all available linters${RESET}"
@echo " ${YELLOW}lint-go ${RESET} ${GREEN}Use golintci-lint on your project${RESET}"
@echo " ${YELLOW}lint-yaml ${RESET} ${GREEN}Use yamllint on the yaml file of your projects${RESET}"
@echo " ${YELLOW}test ${RESET} ${GREEN}Run the tests of the project${RESET}"
@echo " ${YELLOW}vendor ${RESET} ${GREEN}Copy of all packages needed to support builds and tests in the vendor directory${RESET}"