-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
67 lines (53 loc) · 1.42 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
MAKEFLAGS += --no-print-directory
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOBIN ?= $(shell go env GOPATH)/bin
plugin_name := $(shell cat plugin.txt)
plugin_version := $(shell cat version.txt)
plugin_cmd := $(plugin_name)-telegraf-plugin
plugin_conf := $(plugin_name).conf
.DEFAULT_GOAL := build
.PHONY: deps
deps:
go mod download -x
.PHONY: testdeps
testdeps: deps
go install honnef.co/go/tools/cmd/[email protected]
.PHONY: tidy
tidy:
go mod verify
go mod tidy
.PHONY: build
build: deps
ifneq (windows, $(GOOS))
go build -o build/bin/$(plugin_cmd) ./cmd/$(plugin_cmd)
else
go build -o build/bin/$(plugin_cmd).exe ./cmd/$(plugin_cmd)
endif
cp $(plugin_conf) build/bin/
.PHONY: dist
dist: build
mkdir -p build/dist
tar czvf build/dist/$(plugin_name)-$(GOOS)-$(GOARCH)-$(plugin_version).tar.gz -C build/bin .
ifneq (, $(shell command -v zip 2>/dev/null))
zip -j build/dist/$(plugin_name)-$(GOOS)-$(GOARCH)-$(plugin_version).zip build/bin/*
else ifneq (, $(shell command -v 7z 2>/dev/null))
7z a -bd build/dist/$(plugin_name)-$(GOOS)-$(GOARCH)-$(plugin_version).zip ./build/bin/*
endif
.PHONY: vet
vet: testdeps
go vet ./...
.PHONY: staticcheck
staticcheck: testdeps
$(GOBIN)/staticcheck ./...
.PHONY: lint
lint: vet staticcheck
.PHONY: test
test:
go test -v -covermode=atomic -coverprofile=build/coverage.out ./...
.PHONY: check
check: test lint
.PHONY: clean
clean:
go clean ./...
rm -rf build