-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
80 lines (65 loc) · 2.28 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
SOURCES := $(shell find . -type f -name "*.go")
BRANCH := $(shell git branch | sed -n -e 's/^\* \(.*\)/\1/p')
COMMIT := $(shell git rev-parse HEAD)
HOST := $(shell hostname)
GOMOD := $(shell find . -type f -name "go.mod")
GOSUM := $(shell find . -type f -name "go.sum")
SUBMODULES := $(foreach d,$(dir $(GOMOD)),$(d)...)
GOWORK := go.work
GOWORKSUM := go.work.sum
VENDOR := vendor
COVOUT := coverage.out
GOVERSION := $(shell awk '/^go / {print $$2}' go.mod)
GOBINARY := $(shell which go)
BIN_DIR := target
.PHONY: check-go-version
check-go-version:
@if [ -z "$(GOBINARY)" ]; then \
echo "Error: No Go binary found. It's a no-go!"; \
exit 1; \
fi; \
if [ "$$($(GOBINARY) version | awk '{print $$3}' | sed 's/go//')" != "$(GOVERSION)" ]; then \
echo "Error: Go version $(GOVERSION) is required, but version $$($(GOBINARY) version | awk '{print $$3}' | sed 's/go//') is installed."; \
exit 1; \
fi
all: check-go-version deps lint test build
deps: $(GOSUM) $(GOWORKSUM)
$(GOSUM): $(SOURCES) $(GOMOD)
$(foreach mod, $(dir GOMOD), cd $(mod) && go mod tidy -v;)
$(GOWORKSUM): $(GOWORK) $(GOMOD)
go work sync
LINTER_VERSION := 1.60.3
LINTER_BINARY := $(BIN_DIR)/golangci-lint-$(LINTER_VERSION)
.PHONY: lint
lint: $(LINTER_BINARY)
$(LINTER_BINARY) run $(LINT_ARGS) $(SUBMODULES)
$(LINTER_BINARY):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN_DIR) v$(LINTER_VERSION)
@mv $(BIN_DIR)/golangci-lint $@
.PHONY: test
test:
go test -count=1 -cover -covermode=atomic -coverprofile=$(COVOUT) $(SUBMODULES)
.PHONY: coverage
coverage: test
go tool cover -html=$(COVOUT)
.PHONY: clean
clean:
@rm -f $(COVOUT)
@rm -rf $(VENDOR)
.PHONY: build
build: update-workspace
@go build -ldflags="-X 'main.version=dev-$(BRANCH)' -X 'main.source=$(HOST)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(shell date -u "+%FT%TZ")'" -o "$(BIN_DIR)/grafana-app-sdk" cmd/grafana-app-sdk/*.go
.PHONY: install
install: build
ifndef GOPATH
@echo "GOPATH is not defined"
exit 1
endif
@cp "$(BIN_DIR)/grafana-app-sdk" "${GOPATH}/bin/grafana-app-sdk"
.PHONY: update-workspace
update-workspace:
@echo "updating workspace"
go mod download
.PHONY: regenerate-codegen-test-files
regenerate-codegen-test-files:
sh ./scripts/regenerate_golden_test_files.sh