-
Notifications
You must be signed in to change notification settings - Fork 70
/
Makefile
207 lines (138 loc) · 5.5 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
.PHONY: build build-dev debug test test-unit test-acc test-examples lint lint-go lint-test lint-docs fmt fmt-test fmt-imports clean clean-tools clean-examples sweep generate gen-go docs ci-selproj
#################################################
# Global
#################################################
GO := CGO_ENABLED=0 go
TOOLS_DIR ?= tools
TOOLS_BIN_DIR ?= $(TOOLS_DIR)/bin
$(TOOLS_BIN_DIR):
mkdir -p $(TOOLS_BIN_DIR)
GOLANGCILINT := $(TOOLS_BIN_DIR)/golangci-lint
$(GOLANGCILINT): $(TOOLS_BIN_DIR) $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GO) build -o bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
TFPLUGINDOCS := $(TOOLS_BIN_DIR)/tfplugindocs
$(TFPLUGINDOCS): $(TOOLS_BIN_DIR) $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GO) build -o bin/tfplugindocs github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
TERRAFMT := $(TOOLS_BIN_DIR)/terrafmt
$(TERRAFMT): $(TOOLS_BIN_DIR) $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GO) build -o bin/terrafmt github.com/katbyte/terrafmt
SELPROJ := $(TOOLS_BIN_DIR)/selproj
$(SELPROJ): $(TOOLS_BIN_DIR) $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GO) build -tags tools -o bin/selproj github.com/aiven/go-utils/selproj
# See https://github.com/hashicorp/terraform/blob/main/tools/protobuf-compile/protobuf-compile.go#L215
ARCH ?= $(shell $(GO) env GOOS GOARCH | tr '\n' '_' | sed '$$s/_$$//')
BUILD_DEV_DIR ?= ~/.terraform.d/plugins/registry.terraform.io/aiven-dev/aiven/0.0.0+dev/$(ARCH)
BUILD_DEV_BIN ?= $(BUILD_DEV_DIR)/terraform-provider-aiven_v0.0.0+dev
$(BUILD_DEV_DIR):
mkdir -p $(BUILD_DEV_DIR)
#################################################
# Build
#################################################
build:
$(GO) build
# Example usage in Terraform configuration:
#
# terraform {
# required_providers {
# aiven = {
# source = "aiven-dev/aiven"
# version = "0.0.0+dev"
# }
# }
#}
build-dev: $(BUILD_DEV_DIR)
$(GO) build -gcflags='all=-N -l' -o $(BUILD_DEV_BIN)
#################################################
# Debug
#################################################
debug: build-dev
$(BUILD_DEV_BIN) -debug
#################################################
# Test
#################################################
test: test-unit test-acc
test-unit:
$(GO) test -v --cover ./...
PKG_PATH ?= internal
ifneq ($(origin PKG), undefined)
PKG_PATH = internal/sdkprovider/service/$(PKG)
endif
TEST_COUNT ?= 1
ACC_TEST_TIMEOUT ?= 180m
ACC_TEST_PARALLELISM ?= 10
test-acc:
TF_ACC=1 PROVIDER_AIVEN_ENABLE_BETA=1 $(GO) test ./$(PKG_PATH)/... \
-v -count $(TEST_COUNT) -parallel $(ACC_TEST_PARALLELISM) $(RUNARGS) $(TESTARGS) -timeout $(ACC_TEST_TIMEOUT)
test-examples: build-dev clean-examples
AIVEN_PROVIDER_PATH=$(BUILD_DEV_DIR) $(GO) test --tags=examples ./examples_tests/... \
-v -count $(TEST_COUNT) -parallel $(ACC_TEST_PARALLELISM) $(RUNARGS) $(TESTARGS) -timeout $(ACC_TEST_TIMEOUT)
#################################################
# Lint
#################################################
lint: lint-go lint-test lint-docs
lint-go: $(GOLANGCILINT)
$(GOLANGCILINT) run --build-tags all --timeout=30m ./...
lint-test: $(TERRAFMT)
$(TERRAFMT) diff ./internal -cfq
lint-docs: $(TFPLUGINDOCS)
PROVIDER_AIVEN_ENABLE_BETA=1 $(TFPLUGINDOCS) generate --rendered-website-dir tmp
mv tmp/data-sources/influxdb*.md docs/data-sources/
mv tmp/resources/influxdb*.md docs/resources/
rm -rf tmp
PROVIDER_AIVEN_ENABLE_BETA=1 $(TFPLUGINDOCS) validate --provider-name aiven
rm -f docs/data-sources/influxdb*.md
rm -f docs/resources/influxdb*.md
#################################################
# Format
#################################################
fmt: fmt-test fmt-imports
fmt-test: $(TERRAFMT)
$(TERRAFMT) fmt ./internal -fv
# macOS requires to install GNU sed first. Use `brew install gnu-sed` to install it.
# It has to be added to PATH as `sed` command, to replace default BSD sed.
# See `brew info gnu-sed` for more details on how to add it to PATH.
fmt-imports:
find . -type f -name '*.go' -exec sed -zi 's/"[\r\n\t]\+"/"\n"/g' {} +
goimports -local "github.com/aiven/terraform-provider-aiven" -w .
#################################################
# Clean
#################################################
clean: clean-tools clean-examples sweep
clean-tools: $(TOOLS_BIN_DIR)
rm -rf $(TOOLS_BIN_DIR)
clean-examples:
find ./examples -type f -name '*.tfstate*' -delete
SWEEP ?= global
sweep:
@echo 'WARNING: This will destroy infrastructure. Use only in development accounts.'
TF_SWEEP=1 $(GO) test ./internal/sweep -v -sweep=$(SWEEP) $(SWEEP_ARGS) -timeout 15m
sweep-check:
$(GO) test ./internal/sweep -v -run TestCheckSweepers
#################################################
# Generate
#################################################
generate: gen-go docs
gen-go:
go generate ./...;
$(MAKE) fmt-imports
docs: $(TFPLUGINDOCS)
rm -f docs/.DS_Store
PROVIDER_AIVEN_ENABLE_BETA=1 $(TFPLUGINDOCS) generate
rm -f docs/data-sources/influxdb*.md
rm -f docs/resources/influxdb*.md
OLD_SCHEMA ?= .oldSchema.json
CHANGELOG := PROVIDER_AIVEN_ENABLE_BETA=1 go run ./changelog/...
dump-schemas:
$(CHANGELOG) -save -schema=$(OLD_SCHEMA)
diff-schemas:
$(CHANGELOG) -diff -schema=$(OLD_SCHEMA) -changelog=CHANGELOG.md
rm $(OLD_SCHEMA)
load-schemas:
go get github.com/aiven/go-client-codegen@latest github.com/aiven/go-api-schemas@latest
go mod tidy
update-schemas: dump-schemas load-schemas generate diff-schemas
#################################################
# CI
#################################################
ci-selproj: $(SELPROJ)
$(SELPROJ)