forked from PacketFabric/terraform-provider-packetfabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
127 lines (101 loc) · 2.65 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
TEST?=$$(go list ./... | grep -v 'vendor')
HOSTNAME=$(shell hostname)
NAMESPACE=packetfabric
NAME=packetfabric
BINARY=terraform-provider-${NAME}
VERSION=0.0.1
OS_ARCH=linux_amd64
SOURCES := $(shell find . -name "*.go" -or -name "go.mod" -or -name "go.sum" \
-or -name "Makefile")
default: install
#
# Tools
#
# external tool
define tool # 1: binary-name, 2: go-import-path
TOOLS += $(TOOLDIR)/$(1)
$(TOOLDIR)/$(1): Makefile
GOBIN="$(CURDIR)/$(TOOLDIR)" go install "$(2)"
endef
$(eval $(call tool,gofumports,mvdan.cc/gofumpt/gofumports@latest))
$(eval $(call tool,golangci-lint,github.com/golangci/golangci-lint/cmd/[email protected]))
$(eval $(call tool,gomod,github.com/Helcaraxan/gomod@latest))
$(eval $(call tool,tfplugindocs,github.com/hashicorp/terraform-plugin-docs/cmd/[email protected]))
$(eval $(call tool,tfproviderlint,github.com/bflad/tfproviderlint/cmd/tfproviderlint@latest))
build:
go build -o ${BINARY}
release:
goreleaser release --rm-dist --snapshot --skip-publish --skip-sign
install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
.PHONY: test
test:
go test -v ./...
.PHONY: testacc
testacc:
TF_ACC=1 go test -v ./... -timeout 120m
#
# Coverage
#
.PHONY: cov
cov: coverage.out
.PHONY: cov-html
cov-html: coverage.out
go tool cover -html=coverage.out
.PHONY: cov-func
cov-func: coverage.out
go tool cover -func=coverage.out
coverage.out: $(SOURCES)
VCR=replay go test $(V) -timeout=120m \
-covermode=count -coverprofile=coverage.out \
$(TESTARGS) $(TEST)
#
# Dependencies
#
.PHONY: deps
deps:
$(info Downloading dependencies)
go mod download
.PHONY: deps-update
deps-update:
$(info Downloading dependencies)
go get -u -t ./...
.PHONY: deps-analyze
deps-analyze: $(TOOLDIR)/gomod
gomod analyze
.PHONY: tidy
tidy:
go mod tidy $(V)
.PHONY: verify
verify:
go mod verify
.SILENT: check-tidy
.PHONY: check-tidy
check-tidy:
cp go.mod go.mod.tidy-check
cp go.sum go.sum.tidy-check
go mod tidy
( \
diff go.mod go.mod.tidy-check && \
diff go.sum go.sum.tidy-check && \
rm -f go.mod go.sum && \
mv go.mod.tidy-check go.mod && \
mv go.sum.tidy-check go.sum \
) || ( \
rm -f go.mod go.sum && \
mv go.mod.tidy-check go.mod && \
mv go.sum.tidy-check go.sum; \
exit 1 \
)
#
# Documentation
#
# Force set provider configuration environment variables, as required vars get
# listed as "Optional" if the corresponding var is not empty.
.PHONY: docs
docs: $(TOOLDIR)/tfplugindocs
tfplugindocs generate
.PHONY: check-docs
check-docs: $(TOOLDIR)/tfplugindocs
tfplugindocs validate