-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.mk
101 lines (78 loc) · 3.22 KB
/
project.mk
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
# SPDX-FileCopyrightText: The terraform-provider-ipcalc Authors
# SPDX-License-Identifier: 0BSD
NAMESPACE = metio
NAME = ipcalc
PROVIDER = terraform-provider-${NAME}
VERSION = 9999.99.99
OS_ARCH ?= linux_amd64
XDG_DATA_HOME ?= ~/.local/share
out/${PROVIDER}: $(shell find internal -type f -name '*.go' -and -not -name '*test.go')
mkdir --parents $(@D)
go build -o out/${PROVIDER}
out/docs-sentinel: $(shell find internal -type f) $(shell find examples -type f -name '*.tf' -or -name '*.sh')
mkdir --parents $(@D)
go generate ./...
touch $@
# see https://www.terraform.io/cli/config/config-file#implied-local-mirror-directories
out/install-sentinel: out/${PROVIDER}
mkdir --parents $(@D)
mkdir --parents ${XDG_DATA_HOME}/terraform/plugins/localhost/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
cp out/${PROVIDER} ${XDG_DATA_HOME}/terraform/plugins/localhost/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}/${PROVIDER}
touch $@
out/terratest-lock-sentinel: out/install-sentinel
mkdir --parents $(@D)
find ./terratest -name "*.lock.hcl" -type f -delete
touch $@
out/terratests-run-sentinel: out/terratest-lock-sentinel $(shell find terratest -type f -name '*.go') $(shell find terratest -type f -name '*.tf')
mkdir --parents $(@D)
gotestsum --format=testname -- -timeout=120s -parallel=4 ./terratest/tests
touch $@
out/tests-sentinel: $(shell find internal -type f -name '*.go')
mkdir --parents $(@D)
gotestsum --format=testname -- -v -cover -timeout=120s -parallel=4 ./internal/provider
touch $@
out/coverage.out: $(shell find internal -type f -name '*.go')
mkdir --parents $(@D)
gotestsum --format=testname -- -v -cover -coverprofile=out/coverage.out -timeout=120s -parallel=4 ./internal/provider
out/coverage.html: out/coverage.out
go tool cover -html=out/coverage.out -o out/coverage.html
out/go-format-sentinel: $(shell find . -type f -name '*.go')
mkdir --parents $(@D)
gofmt -s -w -e .
touch $@
out/go-lint-sentinel: $(shell find . -type f -name '*.go')
mkdir --parents $(@D)
golangci-lint run
touch $@
out/tf-format-sentinel: $(shell find ./examples -type f -name '*.tf') $(shell find ./terratest -type f -name '*.tf')
mkdir --parents $(@D)
terraform fmt -recursive ./terratest
terraform fmt -recursive ./examples
touch $@
.PHONY: install
install: out/install-sentinel ## install the provider locally
.PHONY: docs
docs: out/docs-sentinel ## generate the documentation
.PHONY: terratests
terratests: out/terratests-run-sentinel ## run all terratest tests
.PHONY: terratest
terratest: out/terratest-lock-sentinel ## run specific terratest tests
go test -v -timeout=120s -parallel=4 -run $(filter-out $@,$(MAKECMDGOALS)) ./terratest/tests
.PHONY: tests
tests: out/tests-sentinel ## run the unit tests
.PHONY: test
test: ## run specific unit tests
go test -v -timeout=120s -run $(filter-out $@,$(MAKECMDGOALS)) ./internal/provider
.PHONY: coverage
coverage: out/coverage.html ## generate coverage report
.PHONY: format
format: out/go-format-sentinel out/tf-format-sentinel ## format Go code and Terraform config
.PHONY: lint
lint: out/go-lint-sentinel ## lint all Go code
.PHONY: update
update: ## update all dependencies
go get -t -u ./...
go mod tidy
.PHONY: clean
clean: ## removes all output files
rm -rf ./out