-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
70 lines (56 loc) · 1.96 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
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SHELL := /bin/bash
NAME := sdk-go
BUILD_TARGET = build
MAIN_SRC_FILE=main.go
GO := GO111MODULE=on go
GO_NOMOD :=GO111MODULE=off go
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
ORG := cdevents
REPO := sdk-go
ORG_REPO := $(ORG)/$(REPO)
RELEASE_ORG_REPO := $(ORG_REPO)
ROOT_PACKAGE := github.com/$(ORG_REPO)
GO_VERSION := 1.19
GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/,*.go)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown')
BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
CGO_ENABLED = 0
REPORTS_DIR=$(BUILD_TARGET)/reports
GOTEST := $(GO) test
# set dev version unless VERSION is explicitly set via environment
VERSION ?= $(shell echo "$$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)' 2>/dev/null)-dev+$(REV)" | sed 's/^v//')
ifdef DISABLE_TEST_CACHING
GOTEST += -count=1
endif
TEST_PACKAGE ?= ./...
COVER_OUT:=$(REPORTS_DIR)/cover.out
COVERFLAGS=-coverprofile=$(COVER_OUT) --covermode=count --coverpkg=./...
test: ## Run tests with the "unit" build tag
mkdir -p $(REPORTS_DIR)
CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) $(COVERFLAGS) --tags=testonly -failfast -short ./...
.PHONY: fmt
fmt: importfmt ## Format the code
$(eval FORMATTED = $(shell $(GO) fmt ./...))
@if [ "$(FORMATTED)" == "" ]; \
then \
echo "All Go files properly formatted"; \
else \
echo "Fixed formatting for: $(FORMATTED)"; \
fi
.PHONY: importfmt
importfmt: get-fmt-deps
@echo "Formatting the imports..."
goimports -w $(GO_DEPENDENCIES)
get-fmt-deps: ## Install test dependencies
$(GO) install golang.org/x/tools/cmd/goimports
.PHONY: lint
lint: ## Lint the code
./hack/gofmt.sh
./hack/linter.sh
.PHONY: generate # Regenerate code
generate:
./hack/generate.sh
.PHONY: all
all: fmt test lint generate